Grub showing old kernel when booting

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.

1 Like

You can list (installed) packages that there is more than one version, e.g. kernel:

dnf rq --installonly

And narrow that down to all but latest two:

dnf rq --installonly --latest=-2

As said, the DNF does remove old ones and keeps only some (3 by default), by you can manually feed the list of packages to dnf for removal:

dnf remove $(dnf rq --installonly --latest=-2)
1 Like

Is there a way to keep them but not have them show on the grub boot screen?

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?

1 Like

Completely understand your point, my reasoning really is I just like a cleaner look to everything. Less options feels cleaner to me.

There is a way to hide the menu. What is “cleaner” than nothing?

In fact, it is the default in el9: Chapter 17. Kernel | Red Hat Product Documentation
(and has caused frequent questions on how to not hide the menu …)


Seems like

sudo grub2-editenv - set menu_auto_hide=1

Could do the hiding in el8 too.

This would be the perfect solution, but I am on a dual boot system so I do need a way to choose which OS to boot to.

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.

1 Like

Fantastic, I’lll give that a try then. Thanks everyone for the help.

Tried this and sadly it didn’t change anything on my boot.

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.)