Update Your Gentoo Kernel Without Changing Your Bootloader Entries

Content:

The relative ease of building your own Linux kernel is one of the benefits of using Gentoo. A major downside of doing this is the extra step required to keep your bootloader/boot config up to date.

While distros like Ubuntu and Fedora automate the bootloader update when required, you’re on your own if you’re using Gentoo.

There is, however, a simple trick you can use to make your Gentoo system auto-update, too. It doesn’t work in quite the same way, but it does mean you’ll never need to change your boot config again.

This guide will explain what you need to do.

Using the vmlinuz File

When running make install to install your freshly built kernel in /boot, Gentoo will check for a file named vmlinuz.

If this file exists, Gentoo will create a copy of the new kernel, and save it to this file. This means you’ll have two copies of your new kernel in /boot – the named file as before, plus vmlinuz.

However, if vmlinuz does not exist, it will not be created. You’ll therefore be missing out on this functionality. To get it working, simply create a file called vmlinuz in /boot.

touch /boot/vmlinuz

When you next install a kernel, you’ll see vmlinuz has been updated.

$ ls -al
-rwxr-xr-x  1 root root  116626 Dec  4 18:19 config-6.0.11-gentoo
-rwxr-xr-x  1 root root  117950 Dec 13 00:23 config-6.1.0-gentoo
-rwxr-xr-x  1 root root 4827315 Dec  4 18:19 System.map-6.0.11-gentoo
-rwxr-xr-x  1 root root 3856758 Dec 13 00:23 System.map-6.1.0-gentoo
-rwxr-xr-x  1 root root 9204192 Dec 13 00:23 vmlinuz
-rwxr-xr-x  1 root root 9254240 Dec  4 18:19 vmlinuz-6.0.11-gentoo
-rwxr-xr-x  1 root root 9204192 Dec 13 00:23 vmlinuz-6.1.0-gentoo
-rwxr-xr-x  1 root root 9254240 Dec 13 00:22 vmlinuz.old

As you can see, vmlinuz-6.1.0-gentoo and vmlinuz both have the same size and update date/time.

You can also see a second entry, named vmlinuz.old. This file is a copy of the previous vmlinuz file, prior to being overwritten with the new kernel. This can be used as a fallback boot option.

To use an existing kernel, make a copy of the file, and name it vmlinuz (or vmlinuz.old for the fallback). For example, if your kernel is named vmlinuz-6.1.0-gentoo, and the EFI partition mounted to /boot, run

cp /boot/vmlinuz-6.1.0-gentoo /boot/vmlinuz

A drawback of this method is that two copies of the active, and fallback kernels are stored. This shouldn’t cause a problem, provided the partition containing /boot is a decent size (128MB+ should be plenty).

Configuring Your Boot Options

If you’re using EFISTUB, you should be able to add boot entries pointing to the vmlinuz and vmlinuz.old files in your system UEFI.

If you’re using a bootloader, such as GRUB, create a custom config which points to these two files. When installing a new kernel in future, you wont need to run grub-mkconfig as the old configuration will still be valid.

Unbootable Kernels

One thing to note here is that if a kernel build is unbootable, it will still be copied to vmlinuz.old when the new kernel is installed. A second defective kernel build would then render both vmlinuz and vmlinuz.old unbootable.

In this instance, you’d need to boot a named kernel which is able to boot.

This can be avoided by manually copying vmlinuz.old over vmlinuz in the event the kernel fails to boot, restoring a working kernel.