December 2

Linux: Gentoo Cheat Sheet 2

Gentoo Cheat Sheet
Jump to:navigationJump to:search
This is a reference card of useful commands and tips for administrating Gentoo systems. Newcomers and grey beards alike are encouraged to add their helpful tips below.


Contents
Package management
Sync methods
 Important
It is important to read and follow any and all news items that may be listed after performing a repository sync. See detailed instructions about upgrades.
Portage
Sync all repositories that are set to auto-sync including the Gentoo ebuild repository:

root #emaint --auto sync
Or, for short:

root #emaint -a sync
Sync the Gentoo ebuild repository using the mirrors by obtaining a snapshot that is (at most) a day old:

root #emerge-webrsync
emerge --sync now runs the emaint sync module with the --auto option. See Portage's sync operation.

eix
Sync custom package repository and the Gentoo ebuild repository using eix:

root #eix-sync
app-portage/eix can be installed by issuing:

root #emerge -a app-portage/eix
Gather more information on eix by reading its manual:

user $man eix
layman
 Warning
Eselect/Repository supersedes layman
If there are overlays created by layman, to sync those overlays (layman does not manage overlays defined in /etc/portage/repos.conf):

root #layman -S
app-portage/layman can be installed by issuing:

root #emerge -a app-portage/layman
Package listings
qlist
List installed packages with version number and name of overlay used:

root #qlist -IRv
qlist is provided by app-portage/portage-utils.

eix
To view the list of packages in the world set, along with their available versions, it is possible to use eix:

root #eix --world | less
To keep color in the output, use the --color switch:

root #eix --color -c --world | less -R
Package installation
In the following examples the www-client/firefox package will be used, but users should replace it with the package they want to install.

List what packages would be installed, without installing them:

user $emerge --pretend --verbose www-client/firefox
Or, for short:

user $emerge -pv www-client/firefox
List what packages would be installed, ask for confirmation before installing them:

root #emerge --ask --verbose www-client/firefox
Install a specific version
Install a specific version of a package (use "\=" (backslash and equal sign) for shells that attach special meaning to the "=" character). This example will install the package immediately, without asking for confirmation; use with caution or add the --ask option:

root #emerge =www-client/firefox-24.8.0
Install without adding to the world file
Install a package without adding it to the world file:

root #emerge --ask --oneshot www-client/firefox
Or, for short:

root #emerge -a1 www-client/firefox
Package removal
Recommended method
The recommended way to remove a package is by using emerge --deselect. This removes the specified package from the @world set (i.e. says the package is no longer wanted). To clean up the system afterwards, run depclean as given below.

root #emerge --deselect www-client/firefox
Now run emerge --depclean. The --pretend option will have emerge display what actions would be taken, this must be reviewed to make sure no required packages would be removed:

user $emerge --pretend --depclean
If emerge --depclean has not been run in a while, it may try to remove many packages - caution is advised. Once it has been assured that emerge depclean will only remove unneeded packages, run (--ask option is not needed after a check via --pretend, but is included here to help avoid "copy paste" mishaps):

root #emerge --ask --depclean
Separately, to remove a package that no other packages depend on:

root #emerge --ask --verbose --depclean www-client/firefox
As a safety measure, depclean will not remove any packages unless all required dependencies have been resolved. As a consequence of this, it often becomes necessary to run:

root #emerge --ask --verbose --update --newuse --deep @world
Use --changed-use in place of --newuse to avoid rebuilds when the only changes are USE flags added to or dropped from the repository. Use the --quiet flag for more succinct execution:

root #emerge --ask --quiet --update --changed-use --deep @world
Unclean removal (ignoring dependencies)
 Warning
Use the --unmerge, or the shorthand equivalent -C, options with extreme caution, and only if necessary, and once properly informed of what this does. This will break the system, or other software, if used on some packages. The correct way to remove packages in Gentoo is usually with the --depclean option, as described above.
Remove a package even if it is required by other packages, or is a vital system package:

root #emerge --unmerge www-client/firefox
This may sometimes be useful to temporarily remove a hard block.

The -C switch is short for --unmerge.

 Tip
Do not confuse the lower case -c switch, which is short for --depclean (and is safe), with the upper case -C switch witch risks damaging the system and should only be used when absolutely required.
Package upgrades
Upgrade all packages in the world set, their dependencies (--deep), and packages that have USE flag changes (avoiding unnecessary rebuilds when USE changes have no impact):

root #emerge --ask --verbose --update --deep --changed-use @world
The --newuse may be used in place of--changed-use to make sure that all package use flags reflect the current state of those in the Gentoo repository, though this will entail more rebuilds. The --with-bdeps=y can be used to update build time dependencies also.

Package troubleshooting
Check for and rebuild missing libraries (not normally needed):

root #revdep-rebuild -v
equery is part of app-portage/gentoolkit. You can obtain it by issuing this command:

root #emerge -a gentoolkit
Tell which installed package provides a command using equery:

user $equery b `which vim`
 Tip
qfile can provide a faster alternative to equery, if needed.
Tell which (not) installed package provides a command using e-file:

user $e-file vim
Install e-file with:

root #emerge -a app-portage/pfl
Tell which packages depend on a specific package (cat/pkg in the example) using equery:

user $equery d www-client/firefox
Get information about a package using eix:

root #eix www-client/firefox
 Warning
Do not unemerge sys-libs/glibc. It is needed by nearly every other package. If you inadvertedly remove it you may need a rescue stick/disk. You can fetch glibc after setting PORTAGE_BINHOST="http://packages.gentooexperimental.org/packages/amd64-stable/" in /etc/portage/make.conf.
Portage enhancements
Manage configuration changes after an emerge completes:

root #dispatch-conf
Or alternatively:

root #etc-update
After installations or updates
After updating perl-core packages:

root #perl-cleaner --all
or if previous didn't help:

root #perl-cleaner --reallyall -- -av
For haskell packages:

root #haskell-updater
USE flags
Obtain descriptions and usage of the USE flag X using euse:

user $euse -i X
Gather more information on euse by reading its manual page:

user $man euse
Show what packages have the mysql USE flag:

user $equery hasuse mysql
Show what packages are currently built with the mysql USE flag:

user $eix --installed-with-use mysql
Show what USE flags are available for a specific package:

user $equery uses <package-name>
Quickly add a required USE flag for a package install:

root #echo 'dev-util/cmake -qt5' >> /etc/portage/package.use
Important Portage files
/etc/portage - primary configuration directory for Portage.
/etc/portage/make.conf - Global settings (USE flags, compiler options).
/etc/portage/package.use - USE flags of individual packages. Can also be a folder containing multiple files.
/etc/portage/package.accept_keywords - Keyword individual packages; e.g. ~amd64, ~x86, or ∼arm.
/etc/portage/package.license - Accepted licenses
/var/lib/portage/world - List of explicitly installed package atoms.
/var/db/pkg - Contains information for every installed package a set of files about the installation.
Log management
genlop
genlop is a Portage log processor, also estimating build times when emerging packages.

Install genlop by issuing:

root #emerge -a app-portage/genlop
You can gather more information on app-portage/genlop by reading its manual page:

root #man genlop
View the last 10 emerges (installs):

root #genlop -l | tail -n 10
View how long emerging LibreOffice took:

root #genlop -t libreoffice
Estimate how long emerge -uND --with-bdeps=y @world will take:

root #emerge -pU @world | genlop --pretend
Watch the latest merging ebuild during system upgrades:

root #watch genlop -unc
Overlays
eselect repository
app-eselect/eselect-repository can be installed by issuing:

root #emerge -a app-eselect/eselect-repository
List all existing overlays:

user $eselect repository list
List all installed overlays:

user $eselect repository list -i
See also Eselect/Repository

Layman
 Warning
Eselect/Repository supersedes layman
app-portage/layman can be installed by issuing:

root #emerge -a app-portage/layman
List all existing overlays:

user $layman -L
List all installed overlays (layman does not manage overlays defined in /etc/portage/repos.conf):

user $layman -l
See also Layman

Services
Obtain root shell (if the current user is listed in the sudoers list):

user $sudo -i
OpenRC
Start the ssh daemon in the default runlevel at boot:

root #rc-update add sshd default
Start the sshd service now:

root #rc-service sshd start
Check if the sshd service is running:

root #rc-service sshd status
systemd
Start the ssh daemon at boot:

root #systemctl enable sshd
Start the sshd service now:

root #systemctl start sshd
Check if the sshd service is running:

root #systemctl status sshd
Gentoo Monthly Newsletter (GMN)
Search packages in Portage by regular expressions:

root #emerge -s "%^python$"
Overlays vary from very small to very large in size. As a result they slow down the majority of Portage operations. That happens because overlays do not contain metadata caches. The cache is used to speed up searches and the building of dependency trees. A neat trick is to generate local metadata cache after syncing overlays.

root #emerge --regen
This trick also works in conjunction with eix. eix-update can use metadata cache generated by emerge --regen to speed up things. To enable this, add the following variable to /etc/eixrc/00-eixrc:

FILE /etc/eixrc/00-eixrc
OVERLAY_CACHE_METHOD="assign"
qcheck
Use qcheck to verify installed packages:

root #qcheck vim-core
qcheck comes with app-portage/portage-utils and can be installed by running this command:

root #emerge -a app-portage/portage-utils
Learn more about qcheck by reading its manual page:

user $man qcheck
Category: Linux | Comments Off on Linux: Gentoo Cheat Sheet 2
December 1

Linux: fdisk – Partition contains a LVM2_member signature

In fdisk, when doing a hard delete and the create of an existing partition to resize a partition, if you receive the following alert:

Partition ## contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o:

Answer: No
If you say yes it will delete all LVM signature references and the OS will no longer see your LVM volumes

Category: Linux | Comments Off on Linux: fdisk – Partition contains a LVM2_member signature
November 30

Linux: Ubuntu installation – skip disk checking

During the installation process of Ubuntu and other Linux installers there is an automatic filesystem check that takes place. Typically this should not be skipped, but there are cases when it needs to be skipped, including installing to a server over a slow network.

  1. On boot press e to drop into the grub bootloader
  2. Change the following: Linux /casper/vmlinuz quiet —
    to
    Linux /casper/vmlinuz fsck.mode=skip —
  3. Click ctrl + x

Category: Linux | Comments Off on Linux: Ubuntu installation – skip disk checking
November 29

Linux: Setup a new user and their public key

Prerequisite: openssh-server Installed

_______________________________________

useradd username -m -d /home/username –shell /bin/bash

mkdir /home/username/.ssh

chmod 700 /home/username/.ssh

echo “public_keyofuser” > /home/username/.ssh/authorized_keys

chmod 600 /home/username/.ssh/authorized_keys

chown username:username /home/username/.ssh/ -R

Category: Linux | Comments Off on Linux: Setup a new user and their public key
November 29

Linux: Gentoo Cheat Sheet

By: B Macomber

cat /var/lib/portage/world
	to show packages explicitly installed.
equery list *
	to show all the installed packages, including dependencies.
less /usr/portage/profiles/use.desc
	to view descriptions of the common USE flags.
nano /etc/portage/make.conf
	to specify USE flags.
nano /etc/portage/package.use
	to specify USE flags for individual packages.
emerge --sync
	to get the latest Portage tree (metadata about packages), which is needed for all subsequent emerge commands.
eselect news read
	to read news about Portage updates.
emerge -s package
	to search for a package to see what exists.
emerge -S package
	like above, except it will search all the descriptive text in addition to the package name. Note that Regular Expressions are used for this search. equery uses package
	to see the effect of USE flags on the specified package (requires gentoolkit).
emerge -p package
	to pretend to install a package, in order to show a preview of the dependencies, etc. that will be installed in total.
emerge -a package
	like above, except it will ask to proceed after showing a preview of what will happen.
emerge -q package
	to install quietly, omitting all the technical compilation output.
emerge -uD --with-bdeps=y @world -p
	to update all packages explicitly installed, as well as their dependencies and their build dependencies, pretending at first.
emerge -uDN --with-bdeps=y @world -p
	like above, except changes to USE flags will also be considered in determining what needs to be re-built.
etc-update
	to resolve changes to config files made by Portage updates.
eread
	to view Portage logs.
less /var/log/portage/elog/summary.log
	ditto.
eselect
	to choose which SLOT of a package to use (among other things).
gcc-config
	to choose which version of C++ compiler to use.
env-update && source /etc/profile && emerge binutils glibc -1q
	to rebuild the "toolchain" after changing which version of C++ compiler to use.
emerge -Ca package
	to remove a package.
emerge -ca (--depclean --ask)
	to remove unneeded dependencies.
emerge @preserved-rebuild
	to rebuild packages using outdated libraries.
revdep-rebuild -p
	to rebuild packages whose (dynamically linked) dependencies are no longer needed and have been removed (requires gentoolkit), pretending at first.
eclean -d -p distfiles
	to delete leftover package installation/build files; destructive means to remove stuff except for packages explicitly installed, pretending at first.
rm /usr/portage/distfiles/*
	to delete leftover package installation/build files, regardless of whether you might want them again.
eselect kernel
	to choose a version of the kernel source.
cd /usr/src/linux && make menuconfig
	to configure kernel.
cd /usr/src/linux && make oldconfig
	to configure kernel, showing only options that have changed since the current .config file. Since this will only prompt you with a sequence of questions, you may want to run the above command at the same time in another terminal so that you can browse through the questions and gain some context of what's being asked.
make && make modules_install
	to build kernel & modules.
mount /boot && cp arch/x86_64/boot/bzImage /boot/kernel-x.x.x-hardened && nano /etc/lilo.conf && lilo && umount /boot
	to install kernel; change "x.x.x-hardened" to whatever version you're building.
rm -r /usr/src/linux-x.x.x-hardened && rm -r /lib/modules/x.x.x-hardened && rm /boot/kernel-x.x.x-hardened
	to remove an old, obsolete kernel that's no longer acknowledged by Portage.
rc-config list
	to show which services are started in which runlevels, including those inactive.
rc-update
	to show which services are started in which runlevels, in a slightly different format.
rc-update add service runlevel
	to add a service, such as apache2, to a runlevel, such as default, so that it gets started when the computer boots up.
rc-status
	to show which services are currently running.
/etc/init.d/service restart
	to restart a service. Besides restart, you can also start, stop, etc.
ntpq -p
	to query the status of your Network Time Protocol Daemon.
nohup command > /dev/null 2>&1 &
	to run a process in the background, squelching its output, continuing even after you log off.
echo 1 > /proc/sys/kernel/sysrq && echo b > /proc/sysrq-trigger
	to remotely reboot without accessing any disks, when all else fails.
head -c 200 /dev/urandom | LC_CTYPE=C tr -c -d '[:alnum:]' | head -c 10
	to generate a password of 10 alphanumeric characters.

By: B Macomber

Category: Linux | Comments Off on Linux: Gentoo Cheat Sheet