Hide "old" kernels from grub menu

Hello to everyone.
I’m trying to clean up my grub menu and would like some help.
I understand that having some “backup” kernels is recommended, however I was wondering if it is possible to move those, and the rescue one to a sub menu on the boot screen, and set that as the default behavior for future kernel updates, so as to have a “main” (the latest one) entry always visible.
Thanks in advance.

I am not quite sure what you are asking.
By default grub always boots the latest installed kernel and that one is first on the list.
Dnf only keeps 3 kernels by default and unless you are booting multiple OSes you should see the 3 latest kernels, a rescue kernel, and a bios config entry for a total of 5 lines in the menu. Even with dual boot and windows you should only have 6 lines. Is yours different?

I don’t know that it is possible to break the grub menu down into sub-menus because grub builds the menu during the boot process.

Since the behavior you’re currently seeing is not the expected behavior, you should look into the source of that menu:

(Typically you’ll need sudo to look at these text files)


That file may have some lines starting menuentry
Those entries will appear in your grub menu. I don’t know if Fedora still cleans up stale entries from there. I think it no longer puts new ones there. You might need to remove some yourself. Notice the { and later } making each entry multiple lines long. If you manually remove one, take it all the way up to and including its }

That file also should have a line blscfg
That line represents all the entries described below. That line typically comes before any menuentry because you want all the following entries to come before the ones I described above.

Look in the directory /boot/loader/entries/
Each file there is a menu entry. Those should be automatically managed as you install kernels, removing old kernels.

My main question is which of those two places is the source of the unwanted entries. Knowing which it is will help understand what might need to be fixed.

As you can see by this, the menuentry lines are no longer part of the /boot/grub2/grub.cfg file except for the UEFI firmware setup entry. They are auto generated by parsing the /boot/loader/entries/*.conf files.

# grep menu /boot/grub2/grub.cfg
if [ x"${feature_menuentry_id}" = xy ]; then
export menuentry_id_option
  set timeout_style=menu
# populates the boot menu. Please refer to the Boot Loader Specification documentation
# The kernelopts variable should be defined in the grubenv file. But to ensure that menu
# Hiding the menu is ok if last boot was ok or if this is a first boot attempt to boot the entry
  set menu_hide_ok=1
  set menu_hide_ok=0 
# Avoid boot_indeterminate causing the menu to be hidden more than once
### BEGIN /etc/grub.d/12_menu_auto_hide ###
  if [ "${menu_show_once}" ]; then
    unset menu_show_once
    save_env menu_show_once
    set timeout_style=menu
  elif [ "${menu_auto_hide}" -a "${menu_hide_ok}" = "1" ]; then
      # timeout_style=menu + timeout=0 avoids the countdown code keypress check
      set timeout_style=menu
      set timeout_style=menu
### END /etc/grub.d/12_menu_auto_hide ###
### BEGIN /etc/grub.d/14_menu_show_once ###
  if [ "${menu_show_once_timeout}" ]; then
    set timeout_style=menu
    set timeout="${menu_show_once_timeout}"
    unset menu_show_once_timeout
    save_env menu_show_once_timeout
### END /etc/grub.d/14_menu_show_once ###
	menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change

My situation is exaclty what you are describing. Not a serious issue, its just that coming from other distros, I was used to having just one, maybe two, entries for linux and having multiple pop up seems a bit cluttered.

You have not actually described what you see and are concerned about with the grub menu.
Fedora routinely keeps the newest and 2 older kernels for booting and all display on the menu for user selection.

Please, when you next boot, press any key (up or down arrow is best) to halt booting then snap a picture of the boot menu.

Post that picture plus a description of what changes you are looking for so we can fully understand A) what you see, and B) what is upsetting to you in that display.

This is my boot menu:

I would like it to look more like this:

Specifically, I dont want to have 2+ entries from a single distro/os.

That seems a reasonable request, but the only way I know to approach that would be by directly interacting with the grub developers, or having some sort of detailed grub customizer in action.

Thanks for the reply. As I said not really an issue, so all good.

with colors!? how do you do that?

You can tell grub how many to keep I thought. It defaults to 3, including the rescue kernel.

It actually defaults to 3 plus the rescue kernel.

1 Like

Is there any way to get the Windows menu’s ID whatever how many kernels?
I want to pass it to grub2-reboot in a batch shell commands, automatically.
Instead of calc it manually

grub2-reboot can use the title. That is more stable than other methods.