Chapter 8. Building a customized boot menu


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, located in the /etc/grub.d/ directory, to build the menu. The scripts include the following files:

  • 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 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 change the default boot entry.

Procedure

  1. Specify which operating system or kernel must 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, 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

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.