Existing kernel
You may not want your own kernel. For the first boot, a standard kernel may do. This way, you get the system running, and you can boot it at any time and set everything up correctly. Compiling a kernel can also take time, so using an existing kernel can be useful. To do this, copy the kernel and the modules to the correct locations. In the newer CD, the files are in the boot directory. Usually called ‘Gentoo’, you should find them easily. One caveat is that you must make sure they are the kernel and ‘.igz’ files. Use the file command for that.
/mnt/cdrom/boot/gentoo: Linux kernel x86 boot executable bzImage,
version 5.4.80-gentoo-r1-x86_64 (root@catalyst) #1 SMP Sun Jan 17 23:41:47 UTC
2021, RO-rootFS, swap_dev 0x3, Normal VGA
/mnt/cdrom/boot/gentoo-config: Linux make config build file, ASCII text
/mnt/cdrom/boot/gentoo.igz: XZ compressed data
/mnt/cdrom/boot/System-gentoo.map: ASCII text
As you can see, the files are clearly marked with this method so you know which one to use. Next, you need to copy modules. The modules are in your lib/modules directory, one per kernel you run.
For the directory, you can also use ‘uname -r’ to get the name.
Install tools
Gentoo comes with tools for many advanced tasks. When compiling a kernel, you usually use ‘make config’ which you can also use inside Gentoo. However, you also have a Gentoo tool; genkernel. It can compile your kernel automatically with given standard settings. You need to be aware that you can also install a kernel just by using the emerge packaging tool. You need to pick a kernel package that suits your platform. You can see a few choices below.
$ emerge –ask sys-kernel/installkernel-systemd-boot
One of the tools to compile your kernel, after installing sources is ‘genkernel’.
The genkernel tool runs all the scripts you need to upgrade the kernel after downloading new sources.
Using Source Code
This requires more compile power, but it is one of the reasons that you choose Gentoo. In fact, all documentation assumes you want to compile your kernel and has binary kernels as an alternative. The big change about this happened in September 2020 when the Gentoo developers released pre-built kernels. You have many packages to choose from, but the procedure is the same for all of them. Pick a kernel, from here! There are many more, but you can pick those after you are done. In here, you pick the newest kernel form Gentoo.
This implies that you are choosing to upgrade only the kernel. A full system upgrade will often upgrade the sources for a new kernel. After this, you will have several kernels, select the one you want to use.
The system has now changed the link to /usr/src/linux. All tools will use that symbolic link. You should then copy the old config file, so most of your new kernel has the same values. The old file is available in many places; one is in your running system.
Now, you can start the kernel configuration. You do this with any of the standard packages, ‘make config’, ‘make menuconfig’ and so on. However, Gentoo has an ace up its sleeve; genkernel! This tool takes all the steps and does the whole process for you. Mind you, to optimise; you need to add a few options.
You can run without any parameters, but then you have no choices about your kernel configuration. This procedure is enough for creating and installing a new kernel. Setting the parameters is a big challenge.
Using pre-built kernels
Are you sure you want to compile your own kernel? You have several choices to get a binary kernel. If you set the value below, the install of the debiansources will install the binary kernel saving you the hassle of compiling your own.
$ emerge debian-sources
You can also get the newest stable kernel directly from the developers from their site. To install and upgrade run emerge to install it.
More kernels are available, and the distribution kernels are also available.
Using unsupported Source Code
You may have your own changes to the kernel code. To handle this situation, you want to turn off the automatic handling of that code. To make sure that Portage knows what dependencies need to be handled, you need to tell it you put it there but should not be updated automatically.
The file you need to fill up to inform Portage is /etc/portage/profile/package.provided
sys-kernel/gentoo-sources-4.9.16
This way, you can use any code and do what you want without having the scripts change things around unexpectedly.
Intel Micro Code
When you have finished compiling, you should make sure you have the microcode for your processor. These packages are for the Intel processor.
Skip this if you have an AMD processor.
Grub
You must update-grub the way you do on other distributions, with a twist.
The efi stuff is needed when you do not mount your boot partition on default: ‘boot/efi’. Special for Gentoo is this little guy, which will set up all your boot related stuff.
Check that it found the kernel and intramfs, the command lists all the successes and failures. Make sure it all works.
Removing sources
Since you install the sources with the package manager, you can also use the package manager to remove them and clean the tree between compiles.
To clean your tree:
To remove a certain kernel:
If you want to remove the current stable branch!
Other choices
A fairly recent project in Gentoo is to add “distribution kernels”. There are three available, once you have chosen one, the system will upgrade the kernel during a regular upgrade.
Conclusion
Gentoo was built for the tinkerer from the beginning, which makes it a powerful tool for optimisation. Nowadays, you can let the distribution handle the kernel for you. You will miss out on the fine-tuning, but you can dig into that at any time by adding sources with the standard packages. All and all, Gentoo is becoming accessible to more people without sacrificing tweaking capability. Way to go; Gentoo!