Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Working with GRUB 2

The GRUB 2 boot loader is one of the first things that needs to be working well to boot a Linux server. As an administrator, you will sometimes need to apply modifications to the GRUB 2 boot loader configuration. This section explains how to do so. The RHEL 8 boot procedure is discussed in more detail in Chapter 18, where troubleshooting topics are covered as well.

Understanding GRUB 2

The GRUB 2 boot loader makes sure that you can boot Linux. GRUB 2 is installed in the boot sector of your server’s hard drive and is configured to load a Linux kernel and the initramfs:

  • The kernel is the heart of the operating system, allowing users to interact with the hardware that is installed in the server.

  • The initramfs contains drivers that are needed to start your server. It contains a mini file system that is mounted during boot. In it are kernel modules that are needed during the rest of the boot process (for example, the LVM modules and SCSI modules for accessing disks that are not supported by default).

Normally, GRUB 2 works just fine and does not need much maintenance. In some cases, though, you might have to change its configuration. To apply changes to the GRUB 2 configuration, the starting point is the /etc/default/grub file, which has options that tell GRUB what to do and how to do it. Example 17-3 shows the contents of this file after an installation with default settings of RHEL 8.


Example 17-3 Contents of the /etc/default/grub File

[root@localhost ~]# cat /etc/default/grub
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/rhel-swap
  rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"

As you can see, the /etc/default/grub file does not contain much information. The most important part that it configures is the GRUB_CMDLINE_LINUX option. This line contains boot arguments for the kernel on your server.

Apart from the configuration in /etc/default/grub, there are a few configuration files in /etc/grub.d. In these files, you’ll find rather complicated shell code that tells GRUB what to load and how to load it. You typically do not have to modify these files. You also do not need to modify anything if you want the capability to select from different kernels while booting. GRUB 2 picks up new kernels automatically and adds them to the boot menu automatically, so nothing has to be added manually.

Understanding GRUB 2 Configuration Files

Based on the configuration files mentioned previously, the main configuration file is created. If your system is a BIOS system, the name of the file is /boot/grub2/grub.cf. On a UEFI system the file is written to /boot/efi/EFI/redhat. After making modifications to the GRUB 2 configuration, you’ll need to regenerate the relevant configuration file, which is why you should know the name of the file that applies to your system architecture. Do not edit it, as this file is automatically generated.

Modifying Default GRUB 2 Boot Options

To apply modifications to the GRUB 2 boot loader, the file /etc/default/grub is your entry point. The most important line in this file is GRUB_CMDLINE_LINUX, which defines how the Linux kernel should be started. In this line, you can apply permanent fixes to the GRUB 2 configuration. Some likely candidates for removal are the options rhgb and quiet. These options tell the kernel to hide all output while booting. That is nice to hide confusing messages for end users, but if you are a server administrator, you probably just want to remove these options.

Another interesting parameter is GRUB_TIMEOUT. This defines the amount of time your server waits for you to access the GRUB 2 boot menu before it continues booting automatically. If your server runs on physical hardware that takes a long time to get through the BIOS checks, it may be interesting to increase this time a bit.

While working with GRUB 2, you need to know a bit about kernel boot arguments. There are many of them, and most of them you’ll never use, but it is good to know where you can find them. Type man 7 bootparam for a man page that contains an excellent description of all boot parameters that you may use while starting the kernel.

To write the modified configuration to the appropriate files, you use the grub2-mkconfig command and redirect its output to the appropriate configuration file. On a BIOS system, the command would be grub2-mkconfig -o /boot/grub2/grub.cfg, and on a UEFI system the command would be grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg.

In Exercise 17-2, you learn how to apply modifications to the GRUB 2 configuration and write them to the /boot/grub2/grub.cfg configuration file.


Exercise 17-2 Applying Modifications to GRUB 2

  1. Open the file /etc/default/grub with an editor and remove the rhgb and quiet options from the GRUB_CMDLINE_LINUX line.

  2. From the same file, set the GRUB_TIMEOUT parameter to 10 seconds. Save changes to the file and close the editor.

  3. From the command line, type grub2-mkconfig > /boot/grub2/grub.cfg to write the changes to GRUB 2. (Note that instead of using the redirector > to write changes to the grub.cfg file, you could use the -o option. Both methods have the same result.)

  4. Reboot and verify that while booting you see boot messages scrolling by.

  • + Share This
  • 🔖 Save To Your Account