Kernel upgrade on Gentoo

  () #linux, #gentoo, #kernel, #sysadmin

I’m writing down the procedure I usually follow when updgrading the kernel on my Gentoo system. This was initially just a checklist, but I later added some explanations and additional sections about the Nvidia drivers and Intel microcode.

I assume familiarity with the system and a working installation. If you need more exhaustive documentation, see the wiki and handbook1.

Preliminary steps

We will update from linux-A.B.C to linux-X.Y.Z.

Let’s start by fetching the source of the new kernel.

emerge -uDUa --with-bdeps=y =sys-kernel/gentoo-sources-X.Y.Z

You may also need to update @world set before updating the kernel.

emerge -uDUa --with-bdeps=y @world

Using eselect, select the kernel version that you want to upgrade to. This will adjust the /usr/src/linux symlink.

eselect kernel list
eselect kernel set X

Go to the directory containing kernel sources.

cd /usr/src/linux

Configuration

Start by copying your .config from the old kernel sources.

# from the old folder
cp /usr/src/linux-A.B.C-gentoo/.config /usr/src/linux
# from the running kernel
zcat /proc/config.gz > /usr/src/linux/.config

Then, you will have to update the configuration file. The oldconfig target will interactively prompt you to insert values for the new options.

make oldconfig

Alternatively, olddefconfig will automatically insert default values for the new options.

make olddefconfig

To easily change more configuration options you can use menuconfig, which will start an interactive ncurses interface.

make menuconfig
Warning
Manually editing the .config file is highly discouraged since configuration options have dependencies.

Building

Once you are done changing your configuration, you can build your kernel with make. The NVIDIA drivers and Intel microcode require you to do extra steps before building.

You can speed up the build process by using multiple make jobs. It is helpful to determine the number of cpu threads with nproc.

make -j$(nproc)

Installation

Firstly, mount the boot partition if it is not already mounted.

mount /boot

Then, you can install the new kernel and modules.

make install
make modules_install

Update your bootloader configuration. If you are using GRUB, you can use grub-mkconfig.

grub-mkconfig -o /boot/grub/grub.cfg

Some kernel modules may be installed by packages and live outside of the kernel source tree (e.g. Nvidia drivers). They need to be rebuilt every time you change the kernel. Luckily portage provides this handy shorthand.

emerge @module-rebuild

Additionally, some drivers may require firmware updates.

emerge sys-kernel/linux-firmware

Now you can reboot your machine and everything should hopefully work as intended.

Clean up

It is a good habit to keep the old kernel files around (at least until you have verified the new ones).

If you have a few old kernels in your boot partition, you may want to remove some of them.

rm /boot/System.map-A.B.C-gentoo
rm /boot/config-A.B.C-gentoo
rm /boot/vmlinuz-A.B.C-gentoo

Then, remember to update GRUB (or your bootloader of choice).

grub-mkconfig -o /boot/grub/grub.cfg

Addendum

Nvidia drivers

I will not delve too much on the details here. You can check exactly which kernel options features to enable on the wiki2.

However, I recently found the solution to a problem that caused my TTYs to be blank. I had accidentally activated FB_SIMPLE, SYSFB_SIMPLEFB and DRM_SIMPLEDRM. These options cause problems with newer nvidia drivers and should be disabled3.

emerge x11-drivers/nvidia-drivers

If you already installed the drivers, @module-rebuild should automatically rebuild them.

Intel microcode

Install Intel’s iucode_tool for managing microcodes.

emerge sys-firmware/intel-microcode

Use the tool to get the processor signature and search a microcode bundle with a matching signature.

iucode_tool -S
iucode_tool -S -l /lib/firmware/intel-ucode/*

Enable in the kernel configuration the microcode loading features and add in the Firmware loading facility the microcode bundle found before as a named firmware blob, then build the kernel.

Now build and install the kernel.

Verify after rebooting that the microcode is loaded by the kernel.

dmesg | grep microcode

For more details, see the wiki4.

References


  1. https://wiki.gentoo.org/wiki/Handbook:AMD64 ↩︎

  2. https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers ↩︎

  3. https://forums.gentoo.org/viewtopic-t-1157629-start-25.html ↩︎

  4. https://wiki.gentoo.org/wiki/Intel_microcode ↩︎