8.4 KiB
title, description, published, date, tags, editor, dateCreated
| title | description | published | date | tags | editor | dateCreated |
|---|---|---|---|---|---|---|
| Hall of Gentooisms | Anything related to wrangling Gentoo, solving errors in Gentoo, making Gentoo faster thus creating errors in Gentoo, goes here. Gentoo. | true | 2022-04-30T20:10:34.075Z | gentoo | markdown | 2021-08-21T18:00:45.725Z |
Basics
Everybody starts somewhere. Here are the absolute essentials when it comes to Gentoo-wrangling.
The make.conf
Gentoo's key settings are set under the /etc/portage/make.conf file - which is likely the first you modify. Some important sections are:
USE=- Global USE flags for the system (see below).CFLAGS- these are the options to pass to the compiler. Unless you like suffering, these should be-O2 -pipe -march=native.MAKEOPTSare things to pass to themakecommand - pass-j$(nproc)to give compiling you entire system's oopmh.
You can also override to less oomph, or start with some oomph and give specific package all oomph via Portage - see environment section below. {.is-info}
ACCEPT_KEYWORDS- Your branch (see below).CMAKE_MAKEFILE_GENERATOR- what program to use for make. Default isemake, but you should probably useninjafor faster builds.CPU_FLAGS_X86- just runcpuid2cpuflags | sed -e 's/CPU_FLAGS_X86://g'and put it there. Do not question it.
You'll likely need to install that command using
emerge cpuid2cpuflags. {.is-info} See my (hopefully current)make.confhere. {.is-info}
The Portage
It is big, it is gnarly, and I'm going to pretend not to see it is also Python. What should you know about Portage, the legendary Gentoo package manager?
Since it's inspired by BSD's ports, each package's full name is a category followed by an actual pacakge name (ex: sys-devel/llvm).
Under Portage's configuration directory /etc/portage, there's a bunch of things you can mess with:
- Each package's keywords (like switching it around between branches)
- Each package's USE flags (things to add or remove from it, see here, and search specific package's USE flags here)
- Compiler environments and pointing packages to them
Generally, the structure is /etc/portage/package.something/, under which you put the base name of your package:
/etc/portage/package.accept_keywords/gentoo-sources:
sys-kernel/gentoo-sources -amd64 ~amd64
# ^ Package name ^ Keywords
And inside the file, you specify the full package name followed by whatever it is you're setting:
When it comes to more general things like environments, you create a file under /etc/portage/env and name it whatever, like the GCC override for my Clang system:
/etc/portage/env/compiler-gcc-lto:
CC="gcc"
CXX="g++"
CFLAGS="-flto=16 -march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"
LDFLAGS="-O2 -Wl,--as-needed"
AR="gcc-ar"
NM="gcc-nm"
RANLIB="gcc-ranlib"
and tell package to to use it by writing down their full name followed by the config in /etc/portage/package.env:
/etc/portage/package.env:
sys-libs/glibc compiler-gcc-lto
# ^ Package name #^ Config under /etc/portage/env
You can see my current
/etc/portagein the git repository, and a bunch of other useful things in the Gentoo Wiki page about Portage. {.is-info}
The Branches
Gentoo has two branches of relevance to me - the arch and the ~arch, which are the stable and testing branches, respectively.
instead of
arch, you put in your processor architecture!amd64gang! {.is-info}
It is really, REALLY friggin' hard to change branches as I've smugly predicted I could. Choose your branch carefully! {.is-warning}
For perspective, arch is about on par to what you'll see in Ubuntu LTS, while ~arch is what you'd see on... Arch!
~archis really funny to me. Like, Q: Hey! what processor are you?! A: Um, AMD64, kinda? Nice. {.is-success}
Setting the branches
Like many Gentoo things, you set your branches in /etc/portage/make.conf. Setting the branch to Testing would be like so:
ACCEPT_KEYWORDS="~amd64"
Hilarious!
The Kernel
In Gentoo, something-sources is the kernel. We are too artsy-fartsy for just
linux(Arch!) {.is-info}
Picking a kernel
There are three kernel types that may be of any interest to me (with my opinion, which is useless and irrelevant):
- The latest and greatest
gentoo-sources(you have been bad and must be punished) - The Long Term Support release of
gentoo-sources(you are a reasonable person) - The plain-ol'
vanilla-sources(you are a purist, a snob and a scoundrel)
Under arch, you get the LTS, since you're a reasonable person.
Under ~arch, you get the latest and greatest, because you hate it when things are working.
This is not true;
~archit working great, but how can you flex otherwise? {.is-warning}
vanilla-sources acts the same, but with the upstream kernel instead. Gentoo does very little patching, making this a prime example of nitpicking.
To use an LTS kernel on a Testing system, (smort!) you can change the keywords for the something-sources you're using like so:
sys-kernel/gentoo-sources -~amd64 amd64
# ^ NO testing
And to use the latest kernel on a stable system (why?) you'd do like so:
sys-kernel/gentoo-sources -amd64 ~amd64
# ^ NO stable
You get the gist.
Setting the kernel
While easy to forget, not setting the kernel often leads to booting and
initramfsgenenration errors. Follow attentively! {.is-warning}
After emerge-ing whatever kernel you use, run eselect kernel list, which will show something like this:
takahe :: ~ ‹takahe-root*› # eselect kernel list
Available kernel symlink targets:
[1] linux-5.13.12
[2] linux-5.13.12-gentoo *
select the kernel you desire by running eselect kernel set followed by the number of said kernel.
Behind the scene, this symlinks the downloaded kernel archive to /usr/src/linux.
Configuring the kernel
Whatever it is you do, do it in /usr/src/linux.
Make sure it is symlinked by running ls -l /usr/src/linux - it should show where the real path is.
option 1: I have time and like wasting compile power
genkernel all and follow whatever it yells at you. See here.
option 2: Use whatever's running already
run zcat /proc/config.gz > .config - Gentoos (and every other distribution I've seen) expose their kernel configs this way, but this is not universal.
You can double check this method by running make menuconfig and checking your option (or just reading the .config, you chad).
option 3: Use my AWESOME kernel configs (if you have my system, lol)
You can also clone the kernel config from this Git repository - obviously adapted to my system.
Note: Compiling with Clang is a bit messier - see Clang page. {.is-info}
Compiling and installing
To start compiling, run
make -j$(nproc) && make modules_install && make install
which will output some very cool text flying on the terminal which you could fail to impress people with.
Once the compilation is finished, you should see three files under /boot:
- a
vmlinuzwhatever - this is the actual kernel - an
initramfswhatever - this is the inital RAM filesystem image - a
System.mapwhatever - I have no idea what this is.
Example proper output:
ls /boot:
initramfs-5.13.12-gentoo-x86_64.img
System.map-5.13.12-gentoo-x86_64
vmlinuz-5.13.12-gentoo-x86_64
Vanilla kernels will not have the gentoo-x86_64 bit.
Some systems can boot without an
initramfs- I have yet to achieve this level of awesomeness {.is-info}
For some reason, my system usually fails to copy these files over. After compiling, you can copy them manually to the boot directory:
cp arch/x86_64/boot/bzImage /boot/vmlinuz-5.13.12-gentoo-x86_64
#^ This is the kernel
cp System.map /boot/System.map-5.13.12-gentoo-x86_64
if the initramfs is missing, you can generate it with genkernel or with dracut - see here.