How to upgrade Gentoo kernel

Gentoo is a rolling release, meaning that you have new updates available at regular intervals, but there are no major updates. The idea behind this is never to have incompatible parts of the system because they belong to different major releases. You upgrade as you need to. In many other distributions, the new kernels come with the new release. In Gentoo, you have new kernels when it has been tested. You can, of course, take the latest kernel out there and run that. With the caveat that you may be quite lonely on the forums if you have problems.

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.

$ file /boot/*
/mnt/cdrom/boot/EFI:               directory
/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/ 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.

$ cp -R /lib/modules/5.8.0-generic /mnt/gentoo/lib/modules

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-gentoo

$ emerge –ask sys-kernel/installkernel-systemd-boot

One of the tools to compile your kernel, after installing sources is ‘genkernel’.

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

$ emerge –ask –update –deep –with-bdeps=y –newuse sys-kernel/gentoo-sources

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.

$ eselect kernel list $ eselect kernel set 3

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.

$ zcat /proc/config.gz /usr/src/linux/config

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.

$ genkernel –oldconfig –menuconfig

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.

$ echo "sys-kernel/debian-sources binary" >> /etc/portage/package.use

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

$ emerge –ask sys-kernel/gentoo-kernel-bin

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

#Marking gentoo-sources-4.9.16 as manually installed

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.

$ emerge intel-microcode iucodetool

Skip this if you have an AMD processor.


You must update-grub the way you do on other distributions, with a twist.

$ grub-install –efi-directory=/boot /dev/vda

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.

$ ego boot update

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:

$ emerge –ask –depclean gentoo-sources

To remove a certain kernel:

$ emerge –ask –noreplace gentoo-source:5.4.83

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.


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!

About the author

Mats Tage Axelsson

Mats Tage Axelsson

I am a freelance writer for Linux magazines. I enjoy finding out what is possible under Linux and how we can all chip in to improve it. I also cover renewable energy and the new way the grid operates. You can find more of my writing on my blog.