I think new kernel installs started updating grub properly after used grub2-set-default one time. Since then, I’ve installed the 6.6.6 kernel and a custom 6.6.7 kernel and both times the default grub entry has been updated accordingly.
Note, if you want to check what your default boot entry is before rebooting, you can use sudo grubby --default-kernel
. Or,
$ sudo grep saved_entry /boot/grub2/grubenv
saved_entry=0
$ sudo grubby --info=0
index=0
kernel="/boot/vmlinuz-6.6.7-200.draconyx.fc39.x86_64"
args="ro rd.lvm.lv=fedora/root rd.luks.uuid=luks-c28dcd68-0d5b-4fdf-99eb-c5f1ebe6985b rhgb quiet"
root="/dev/mapper/fedora-root"
initrd="/boot/initramfs-6.6.7-200.draconyx.fc39.x86_64.img"
title="Fedora Linux (6.6.7-200.draconyx.fc39.x86_64) 39 (KDE Plasma)"
id="75bded104d8f4edeadf1215610bef176-6.6.7-200.draconyx.fc39.x86_64"
EDIT: I previously said it didn’t seem like /etc/sysconfig/kernel is used anymore, but have since found that it still is. This is how it all gets tied together. Maybe this will lead someone to figure out why it isn’t working right!
When you install a new kernel, the post transaction script runs /bin/kernel-install add 6.6.6-200.fc39.x86_64 /lib/modules/6.6.6-200.fc39.x86_64/vmlinuz
. (You can see this in the output of rpm -q --scripts kernel-core-6.6.6-200.fc39.x86_64
)
The man page for kernel-install says it executes scripts from /usr/lib/kernel/install.d. One script in this directory, 20-grub.install
, is responsible for updating the default grub entry in certain cases.
It runs the grub2-get-kernel-settings
command and evalutes it’s output. grub2-get-kernel-settings
reads /etc/sysconfig/kernel if it exists, and if it contains UPDATEDEFAULT=yes, then it sets GRUB_UPDATE_DEFAULT_KERNEL=true
.
Later in 20-grub.install, it checks if GRUB_UPDATE_DEFAULT_KERNEL=true
(this may have been output by grub2-get-kernel-settings). If it is, it will run grub2-editenv - set "saved_entry=${NEWDEFAULT}"
. This updates the saved_entry setting in /boot/grub2/grubenv.
Note: 20-grub.install and grub2-get-kernel-settings are shell scripts so you can have a look at what they do easily enough. Also, it looks safe to run grub2-get-kernel-settings - it will just output some text to your terminal so you can see what settings it would use.
What I don’t quite understand, is why my system is updating the default grub entry when I install a kernel. I do not have a /etc/sysconfig/kernel file but on the last two installs (and since one-time using grub2-set-default) grub is being updated.
EDIT2: I just clued in, I used grub2-set-default 0
, so now grubenv has saved_entry=0. When I install a new kernel, it is inserted at index 0 and becomes the default as a result. This doesn’t seem very reliable.