4 minute read

Note: This is an RHCSA 7 exam objective.

Presentation of GRUB2

GRUB2 is the new Linux bootloader. GRUB2 stands for GRand Unified Bootloader version 2.

As GRUB was not maintained for some time and lacked some critical features like GPT management needed to handle disks bigger than 2.4TB, it was decided to start a new version from scratch with modularity in mind.

GRUB2 provides the following new features:

  • ability to boot on various file systems (xfs, ext4, ntfs, hfs+, raid, etc),
  • gzip files decompression on the fly,
  • management of all disk geometries,
  • support for GPT (GUID Partition Tables) and MBR (Master Boot Record),
  • portability with different architectures (BIOS, EFI, Coreboot, etc),
  • ability to load modules at execution time.

Linux Booting Process

GRUB2 Organization

The GRUB2 configuration is spread over several files:

  • /boot/grub2/grub.cfg: this file contains the final GRUB2 configuration (do not edit it directly!),
  • /etc/grub2.cfg: this is a symbolic link to the /boot/grub2/grub.cfg file,
  • /etc/default/grub: this file contains the list of the GRUB2 variables (the values of the environment variables can be edited),
  • /etc/sysconfig/grub: this is a symbolic link to the /etc/default/grub file,
  • /etc/grub.d: this directory contains all the individual files internally used by GRUB2.

This tutorial will only explore knowledge required for the RHCSA exam. Refer to the Additional Resources section for more details.

Basic Management

To get the details about the current active kernel, type:

# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-229.11.1.el7.x86_64) 7 (Core)

Note: This information is stored in the /boot/grub2/grubenv file.

To get the list of the kernels displayed at boot time, type:

# grep ^menuentry /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.10.0-229.20.1.el7.x86_64) 7 (Core)' ...
menuentry 'CentOS Linux (3.10.0-229.14.1.el7.x86_64) 7 (Core)' ...
menuentry 'CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127' ...caf

To permanently define the kernel to execute at boot time (here 0 for the first entry), type:

# grub2-set-default 0

To display the GRUB2 variables, type:

# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=115200"
GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root console=ttyS0,115200""
GRUB_DISABLE_RECOVERY="true"

Where

  • GRUB_TIMEOUT defines the boot waiting delay (here 5 seconds),
  • GRUB_DISTRIBUTOR contains the distribution name (here CentOS Linux),
  • GRUB_DEFAULT specifies the default menu entry; it can be a number, an entry name or the string saved which means the entry saved during the last reboot or the execution of the grub2-set-defaultcommand,
  • GRUB_DISABLE_SUBMENU allows (false) or not (true) the display of a submenu (see below),
  • GRUB_TERMINAL defines the terminal input & output device (here consoleandserial),
  • GRUB_SERIAL_COMMAND configures the serial port,
  • GRUB_CMDLINE_LINUX specifies the command-line arguments added to the menu entries for the Linux kernel,
  • GRUB_DISABLE_RECOVERY defines if all entries can be selected in recovery mode through a separate line (false) or only the default entry (true).

If you want to change the content of any variables in the previous file, you will need to type:

# grub2-mkconfig -o /boot/grub2/grub.cfg

Note: This is the main command to memorize for the exam. You can also replace /boot/grub2/grub.cfg with /etc/grub2.cfg

To better understand some of the environment variables, here are the standard display with GRUB_DISABLE_RECOVERY=”true” and GRUB_DISABLE_SUBMENU=true:

      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>

      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   

If GRUB_DISABLE_RECOVERY is set to “false”, here is the new display:

      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64              
      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64 (recovery m>
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64             
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64 (recovery m>
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>

      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   

Each kernel line gets an associated line in recovery mode.

If GRUB_DISABLE_RECOVERY is now set to “true” (like in the initial standard display) and GRUB_DISABLE_SUBMENU is set to**false, here is the new display:

      CentOS Linux 7 (Core)                                                     
      Advanced options for CentOS Linux 7 (Core)                               
                                                                             
      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   

If the first entry is selected (“CentOS Linux 7 (Core)”), the system boots. If the second option is chosen, the standard menu is shown with an additional line at the bottom to go back to the first menu with the Esc key:

      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64              
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64             
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>

      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   
      Press Escape to return to the previous menu.                        

Additional Resources

To better explore GRUB2, you can:

Leave a comment