💾 Archived View for perso.pw › blog › articles › gentoo-cheatsheet.gmi captured on 2022-01-08 at 13:51:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-17)

➡️ Next capture (2023-01-29)

-=-=-=-=-=-=-

Gentoo cheatsheet

NIL=> https://bsd.network/@solenepercent/106530128025057576 Comment on Mastodon

Introduction

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.

Gentoo project website

Upgrade system

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

Use ccache

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).

Gentoo wiki about ccache

Use genlop to view / calculate build time from past builds

Genlop 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.

Gentoo wiki about Genlop

View compilation time

From the package genlop

# genlop -c

 Currently merging 1 out of 1

 * app-editors/vim-8.2.0814-r100 

       current merge time: 4 seconds.
       ETA: 1 minute and 5 seconds.

Simulate compilation

Add -p to emerge command for "pretend" and pipe it to genlop -p like this

# emerge -av -p kakoune | genlop -p
These are the pretended packages: (this may take a while; wait...)

[ebuild   R   ~] app-editors/kakoune-2020.01.16_p20200601::gentoo  0 KiB


Estimated update time: 1 minute.

Using gentoolkit

The gentoolkit package provides a few commands to find informations about packages.

Gentoo wiki page about Gentoolkit

Find a package

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

Get the package name providing a file

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)

Upgrade parts of the system using packages sets

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

Disable network when emerging for extra security

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

Easy trimming kernel process

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.

Use binary packages

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

Create binary packages

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