Kernel Update

Recently, I have been using Centos 7 (1511) and I have been happy with it - until I discovered that the kernel updates were not actually having any effect. Rebooting would boot the old kernel. A hint to this is the error message I got when the update was executed:

grubby fatal error: unable to find a suitable template

Obviously, the error is related to the bootloader. Also, it is likely an error that is related to the way that particular installation was configured, i.e. disk partitioning, formatting, package selection... because it is unlikely that such a huge problem would be in a shipped version of the OS.

The special condition causing the problem seems to be the fact that /boot is not on a separate partition on my system. It is just a directory in the root filesystem, which is formatted as btrfs. Centos puts the root filesystem into a subvolume called root. From the running filesystem, what can be seen is actually everything that's in /root: e.g. /etc is /root/etc, /home is /root/home (if you do not have a separate subvolume for it) and so on. Apparently, this confuses the grubby tool when it tries to find a suitable template among the boot options in grub.cfg.

There is literally an ancient bug report for this and it is still not fixed. But there seems to be a workaround (it worked for me, at least): Just call

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

It will create entries for all kernels it finds in /boot. That is a bit more than is needed but then again, who cares as long as it works. However, the default boot entry is still wrong in most cases. Even if your default boot index was 0 (as shown by "grubby --default-index") before running grub2-mkconfig, it will have changed afterwards so that it still points to the old kernel. To fix this, first check the current default boot index

# grubby --default-index

then open grub.cfg (at /boot/grub2/grub.cfg or its symlink, /etc/grub2.cfg) and find the index of the latest kernel (just count from zero from the first entry...). Then set the default via

# grubby --set-default-index <yourindex>

That's it.

© 2010-2021 Stefan Birgmeier
sbirgmeier@21er.org