Changing CentOS kernel option doesn't change active kernel after reboot

We’re using Centos 7.9 but had updated to kernel 5.4.112-1 for various reasons. I needed to install the kernel headers for a 3rd party driver, but I didn’t bother to check that doing so would update the kernel to 5.15.0-1 (from elrepo). I have 6 options in my grub2.cfg:

5.15.0-1
5.4.112-1
3.10.0-1160.24
3.10.0.1127.13
3.10.0.1127
0-rescue

I have run the grub2-set-default 1 and grub2-mkconfig -o /boot/grub2/grub.cfg commands and rebooted, and after a reboot, grub2-editenv list returns saved_entry=1, which I believe is correct since the first option in the grub2.cfg is numbered 0. However when I run uname -r, it says the running kernel is still 5.15.0-1. I can’t work out what I’m doing wrong. I can’t see anything obviously wrong in boot.log, /var/log/messages or dmesg outputs. Any ideas? Thanks in advance…

Is the GRUB_DEFAULT=saved option set?

Make sure GRUB_DEFAULT=saved is set in the /etc/default/grub file. The grub-set-default or grub2-set-default command only works for GRUB configuration files created with GRUB_DEFAULT=saved in the /etc/default/grub file.

Did you rebooted the system?

After running the grub2-set-default 1 and grub2-mkconfig -o /boot/grub2/grub.cfg, did you reboot the system?

sudo reboot

What does the following command outputs on the screen?

awk -F "'" /^menuentry/{print\$2} /etc/grub2.cfg

Try the grub2-reboot command to change the default boot kernel temporarily

Use the grub2-reboot command which sets the default boot menu entry for the next boot, but not further boots after that. This command only works for GRUB configuration files created with GRUB_DEFAULT=saved in /etc/default/grub. Try as the root user:

grub2-reboot 1
reboot

Source: HowTos/Grub2 - CentOS Wiki

We list the available menu entries:

awk -F\' /^menuentry/{print\$2} /etc/grub2.cfg

The ID starts with 0 so, it ‘CentOS Linux (3.10.0-1160.45.1.el7.x86_64) 7 (Core)’

CentOS Linux (3.10.0-1160.45.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-cab9605edaa5484da7c2f02b8fd10762) 7 (Core)

I am telling system which kernel should be loaded first, pass its number to the grub2-set-default command:

grub2-set-default 1
## other option ##
grub2-set-default 'CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)'

For BIOS based CentOS 7:

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

For UEFI-based Centos 7:

grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

We verify it:

cat /boot/grub2/grubenv |grep saved

Reboot the system:

shutdown -r now

After the reboot:

uname -mrs

Thanks for your reply.

GRUB_DEFAULT=saved is set in the /etc/default/grub file.

I had rebooted the system several times after running the changes as specified.

The listed kernels from the awk output are as listed in the orignal post, except they all have CentOS Linux at the beginning and the 5.x kernels are from elrepo.

I will try the grub2-reboot 1 command later. Manually selecting the kernel during the boot works, however it’s not ideal.

No problem. I hope it worked out for ya.


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki