Table of Contents
Kernels - CentOS 7/8/9
The Kernel is 'Linux', its the root operating system that is loaded when the computer boots up so its kinda important. However, there are times (more often than you may think) that a newly updated kernel doesn't boot. In this scenario you can simply reboot, and select an earlier kernel from the boot list (provided by Grubby), but, every time you reboot it will default to the faulty one. This is fairly easy to resolve using the tools provided. I'll start by introducing some of these tools and what they provide.
Currently loaded kernel
Default Kernel at boot time
To see the actual files on disk
ls -la /boot/vm*
The early boot process works like this
- Boot Partition loads Grubby
- Grubby mounts the /boot partition and reads its configuration file
- Grubby loads the selected kernel into memory and passes control to that, at this point Grubby is done.
- The Kernel loads, mounts filesystems and executes the boot-up scripts in /etc/rc /initrc or various other paths (depending on linux flavour)
Setting the DEFAULT Kernel
grubby --set-default /boot//boot/vmlinuz-4.18.0-394.el8.x86_64
Where /boot/vmlinuz-4.18.0-394.el8.x86_64 is the selected kernel file. Take care to make sure this file exists (although Grubby should complain if not).
The important naming convention (which makes no sense to me) is that the kernel is named
- kernel-4.18.0-394.el8.x86_64 ← In the package manager (yum/dnf)
- vmlinuz-4.18.0-394.el8.x86_64 ← The disk file
So once we've set the default kernel using grubby (and we can check that using grubby –default-kernel) we can remove the bad ones we don't want anymore.
dnf remove kernel-4.18.0-394.el8.x86_64
Will remove the 4.18.0-394.el8.x86_64 kernel.
The system will automatically remove old kernels as its installs new ones, this is ok but not safe. Redhat generally keeps 3 kernels, the current and two older ones. This means if you install a new kernel and it fails to boot so you manually select an earlier one, then when doing a dnf/yum update you get a later kernel which still fails to boot, and again you manually select the earlier one, then at this point you're at risk should you install yet another kernel in an update. For this reason alone, I recommend keeping 5 kernels if you're using Centos 8/9 stream.
To do this we need to edit the package manager's config file, which will be either /etc/dnf/dnf.conf or /etc/yum/yum.conf and we're looking for the line in the file that reads:
Update this line to change the 3 to 5. Do not set this to any larger than 5 or /boot could run out of space and that's a whole world of pain. 5 is a good number.