I am on a dual boot system with Rocky 8.10 and windows, normally updating my rocky 8.10 using sudo dnf update. When the kernel is updated in this process it adds a new entry to my Grub boot screen, in addition to the old kernel. Now I usually do sudo grubby --remove-kernel='/boot/vmlinuz-####' to remove the old kernels.
Is there a way to automate this so the old kernels are removed on update?
By default Rocky will keep 3 kernels in total and that is all automatic.
You can keep less than 3, but I certainly would not advise you to keep less than 2.
You can add
installonly_limit=2
to your dnf.conf.
Consider this:
You have two kernels, A and B, installed. There is boot entry only for B. You use B and it is fine.
You update and get kernel C. Kernel A is removed. Boot entry for B is removed. Entry for C is created.
You reboot.
Alas, something in the install of C failed. The system cannot successfully boot with C.
If you could boot with B, then you could fix the error. How do you boot B? It has no entry.
Why don’t you want to see more than one entry on the boot menu?
You can do that once grub is hidden. If the system is using UEFI to boot, then press the ESC key when the grub screen shows, and you can then see the menu and choose what you want. If it’s using BIOS instead of UEFI, shift key should show the grub menu to choose an option.
If you don’t want to do that, then you have no choice but to see the grub options to choose from. And removing them is a mistake if the new kernel doesn’t boot, then you’re really stuck. You should have at least two kernels available to choose like @jlehtone and @GZU said.
I forgot that you have dual boot. That prevents the automatic hide.
There are two ways to hide then. Both can be set in the /etc/default/grub.
One is to set the menu style explicitly to hidden. The other is to disable os prober. As result grub2-mkconfig does not create entry for Windows and auto hide should “work”.
Naturally, booting Windows without GRUB menu entry is “as easy” as booting Linux kernel without GRUB menu entry. Even for that there are options.
One is to use UEFI “Boot menu”. It is invoked something like F11 or F12 (depends on motherboard). That menu has entries for Windows and Rocky that load corresponding boot loader. Yours defaults to the entry that loads the GRUB. I do the boot menu to choose the non-default bootloader, when necessary. That is why I don’t need Windows entry in the GRUB menu.
The other is to create a GRUB entry and store it as custom.cfg (in the same directory as the grub.cfg). I have done so by copying what os prober did create for Windows (and then modified a bit). The statements in custom entry don’t have to prevent auto-hide. (I had to do the opposite to prevent auto-hide on el9 systems.)