💾 Archived View for perso.pw › blog › articles › gentoo-cheatsheet.gmi captured on 2023-06-16 at 16:35:11. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-05-24)
-=-=-=-=-=-=-
This is a simple cheatsheet to manage my Gentoo systems, a linux distribution source based, meaning everything installed on the computer must be compiled locally.
I use the following command to update my system, it will downloaded latest portage version and then rebuild @world (the whole set of packages manually installed).
#!/bin/sh emerge-webrsync 2>&1 | grep "The current local" if [ $? -eq 0 ] then exit fi emerge -auDv --with-bdeps=y --changed-use --newuse @world
As you may rebuild the same program many times (especially on a new install), I highly recommend using ccache to reuse previous builded objects and will reduce build duration by 80% when you change an USE.
It's quite easy, install ccache package, add 'FEATURES="ccache"' in your make.conf and do "install -d -o root -g portage -p 775" /var/cache/ccache and it should be working (you should see files in the ccache directory).
Emlop can tell you how much time will be needed or remains on a build based on previous builds information. I find it quite fun to see how long an upgrade will take.
From the package genlop
# emlop predict Pid 353165: ...-newuse --backtrack=150 @world 1:07:15 sys-devel/gcc-12.2.1_p20230121-r1 1:34:41 - 1:06:21
The gentoolkit package provides a few commands to find informations about packages.
Gentoo wiki page about Gentoolkit
You can use "equery" from the package gentoolkit like this "equery l -p '*package name*" globbing with * is mandatory if you are not looking for a perfect match.
Example of usage:
# equery l -p '*firefox*' * Searching for *firefox* ... [-P-] [ ] www-client/firefox-78.11.0:0/esr78 [-P-] [ ~] www-client/firefox-89.0:0/89 [-P-] [ ~] www-client/firefox-89.0.1:0/89 [-P-] [ ~] www-client/firefox-89.0.2:0/89 [-P-] [ ] www-client/firefox-bin-78.11.0:0/esr78 [-P-] [ ] www-client/firefox-bin-89.0:0/89 [-P-] [ ] www-client/firefox-bin-89.0.1:0/89 [IP-] [ ] www-client/firefox-bin-89.0.2:0/89
Use "equery b /path/to/file" like this
# equery b /usr/bin/2to3 * Searching for /usr/bin/2to3 ... dev-lang/python-exec-2.4.6-r4 (/usr/lib/python-exec/python-exec2) dev-lang/python-exec-2.4.6-r4 (/usr/bin/2to3 -> ../lib/python-exec/python-exec2)
qlist -I
There are special packages sets like @security or @profile that can be used instead of @world that will restrict the packages to only a group, on a server you may only want to update @security for... security but not for newer versions.
Gentoo wiki about Packages sets
When building programs using emerge, you can disable the network access for the building process, this is considered a good thing because if the building process requires extra files downloaded or a git repository cloned during building phase, this mean your build is not reliable over time. This is also important for security because a rogue build script could upload data. This behavior is default on OpenBSD system.
To enable this, just add "network-sandbox" in the FEATURE variable in your make.conf file.
Gentoo documentation about make.conf variables
I had a bulky kernel at first but I decided to trim it down to reduce build time, it took me a long fail and retry process in order to have everything right that still work, here is a short explanation about my process.
You can do this without genkernel but if you are like me, using LVM over LUKS and that you need an initrd file, genkernel will just ease the process and generate the initird that you need.
If you use Gentoo you may want to have control over most of your packages, but some packages can be really long to compile without much benefit, or you may simply be fine using a binary package. Some packages have the suffix -bin to their name, meaning they won't require compilation.
There are a few well known packages such as firefox-bin, libreoffice-bin, rust-bin and even gentoo-kernel-bin! You can get a generic kernel pre-compiled :)
Gentoo wiki: Using distribution kernel
It is possible to create a binary package of every program you compile on Gentoo, this can be used for distributing packages on similar systems or simply make a backup of your packages. In some cases, the redistribution may not work if you are on a system with a different CPU generation or different hardware, this is pretty normal because you often define the variables to optimize as much as possible the code for your CPU and the binaries produced won't work on another CPU.
The guide from Gentoo will explain all you need to know about the binary packages and how to redistribute them, but the simplest config you need to start generating packages from emerge compilation is setting FEATURES="buildpkg" in your make.conf
Gentoo wiki: Binary package guide
This is a chunk of my `make.conf` file that I find really useful. It accepts all licenses, make portage run with nice 15 to not disturb much a running system, make it compile with 12 threads, run up to 8 parallel package creation except if the load reach 10.
And it always create binary packages, so if you play with USE flags and revert, you will already have a binary package and this will avoid recompiling.
ACCEPT_LICENSE="-* @EULA @BINARY-REDISTRIBUTABLE" PORTAGE_NICENESS=15 EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg -j 8 -l 10 --keep-going y" FEATURES="ccache buildpkg network-sandbox" MAKEOPTS="-j12" VIDEO_CARDS=yourcard L10N=yourlang