Search

Chapter 8. Building a customized boot menu

download PDF

You can build a boot menu containing specific entries or change the order of the entries. For such a task, you can use GRUB, grubby, and Boot Loader Specification (BLS) files.

The following sections provide information about using GRUB and grubby to do basic customization of the boot menu.

8.1. The GRUB configuration file

Learn about the boot loader configuration file that is /boot/grub2/grub.cfg on BIOS-based machines and /boot/efi/EFI/redhat/grub.cfg on UEFI-based machines.

GRUB scripts search the user’s computer and build a boot menu based on what operating systems the scripts find. To reflect the latest system boot options, the boot menu is rebuilt automatically when the kernel is updated or a new kernel is added.

GRUB uses a series of scripts to build the menu; these are located in the /etc/grub.d/ directory. The following files are included:

  • 00_header, which loads GRUB settings from the /etc/default/grub file.
  • 01_users, which reads the root password from the user.cfg file.
  • 10_linux, which locates kernels in the default partition of Red Hat Enterprise Linux.
  • 30_os-prober, which builds entries for operating systems found on other partitions.
  • 40_custom, a template, which can be used to create additional menu entries.

GRUB reads scripts from the /etc/grub.d/ directory in alphabetical order and therefore you can rename them to change the boot order of specific menu entries.

8.2. Hiding the list of bootable kernels

You can prevent GRUB from displaying the list of bootable kernels when the system starts up.

Procedure

  1. Set the GRUB_TIMEOUT_STYLE option in the /etc/default/grub file as follows:

    GRUB_TIMEOUT_STYLE=hidden
  2. Rebuild the grub.cfg file for the changes to take effect.

    • On BIOS-based machines, enter:

      # grub2-mkconfig -o /boot/grub2/grub.cfg
    • On UEFI-based machines, enter:

      # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  3. Press the Esc key to display the list of bootable kernels when booting.
Important

Do not set GRUB_TIMEOUT to 0 in the /etc/default/grub file to hide the list of bootable kernels. With such a setting, the system always boots immediately on the default menu entry, and if the default kernel fails to boot, it is not possible to boot any previous kernel.

8.3. Changing the default boot entry with the GRUB configuration file

You can specify the default kernel package type, and thus change the default boot entry.

Procedure

  1. Specify which operating system or kernel should be loaded by default by passing its index to the grub2-set-default command. For example:

    # grubby --set-default-index=1
    The default is /boot/loader/entries/d5151aa93c444ac89e78347a1504d6c6-4.18.0-348.el8.x86_64.conf with index 1 and kernel /boot/vmlinuz-4.18.0-348.el8.x86_64

    GRUB supports using a numeric value as the key for the saved_entry directive in /boot/grub2/grubenv to change the default order in which the operating systems are loaded.

    Note

    Index counting starts with zero; therefore, in the previous example, GRUB loads the second entry. With the next installed kernel, the index value will be overwritten.

    Note

    You can also use grubby to find indices for kernels. For more information, see Viewing the GRUB Menu Entry for a Kernel.

  2. Optional: Force the system to always use a particular menu entry:

    1. List the available menu entries:

      # grubby --info=ALL
    2. Use the menu entry name or the number of the position of a menu entry in the list as the key to the GRUB_DEFAULT directive in the /etc/default/grub file. For example:

      GRUB_DEFAULT=example-gnu-linux
  3. Rebuild the grub.cfg file for the changes to take effect.

    • On BIOS-based machines, enter:

      # grub2-mkconfig -o /boot/grub2/grub.cfg
    • On UEFI-based machines:

      # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.