RHEL7: How to get started with GRUB2.

Share this link

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.

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-default command,
  • GRUB_DISABLE_SUBMENU allows (false) or not (true) the display of a submenu (see below),
  • GRUB_TERMINAL defines the terminal input & output device (here console and serial),
  • 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:

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

7 Comments on "RHEL7: How to get started with GRUB2."

Notify of
Sort by:   newest | oldest
redhat0329
Member
redhat0329

Hi CertDepot,

So in the exam if there is a question like modify the grub timeout to 10 we just edit the /etc/default/grub file and modify the GRUB_TIMEOUT=10, then run
# grub2-mkconfig -o /boot/grub2/grub.cfg ?

ak340
Member
ak340

Hi Certdepot, do you have a procedure in rhel 7 to create another boot device, like for example I want sdb1 to be an alternate boot device. I need to know as well how to configure it in grub so upon bootup it will boot from the preferred drive.

Gjorgi
Member
Gjorgi

Alternate boot device… let’s think logically here for a bit: GRUB2 needs to know where to find the kernel and its initram image in order to boot the kernel, right? So:
– know how to tell GRUB2 where to look for a kernel and its accompanying initramfs.
– learn the syntax of addressing boot-capable devices when configuring GRUB2.
– force GRUB2 into autodiscovering the new kernel and autoediting appropriate config files.

terry
Member
terry

Can you please provide all I have to do to update a linux kernel from a given url? (ex: http://server1.host1.example.com/rhcsa. )

wpDiscuz

RHCSA7: Task of the day

Allowed time: 5 minutes.
Create two users "tom" and "engine". "tom" has the UID/GID 3000 and "engine" the UID/GID 4000. "engine" doesn't have an interactive shell.

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a caching-only DNS server to forward DNS queries.

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...