Modify the system bootloader

7. Deploy, Configure, and Maintain Systems

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


The bootloader is a small program that runs first when your computer starts. Its job is to load the operating system. On Red Hat systems, the default bootloader is GRUB2 (GRand Unified Bootloader version 2).

Understanding and modifying GRUB2 is critical because it controls how your system boots, which kernel it uses, and even troubleshooting options if the system doesn’t start properly.


1. Understanding the Boot Process

Here’s the basic flow:

  1. BIOS/UEFI – Your server’s firmware starts and looks for a bootable disk.
  2. MBR/GPT – The bootloader (GRUB2) is located here.
  3. GRUB2 menu – GRUB2 shows the boot menu, lets you pick which kernel or OS to boot.
  4. Kernel – The Linux kernel starts, initializes hardware, and starts system services.

IT Example: In a server environment, if you have multiple kernel versions (like 5.15 and 6.1), GRUB2 lets you choose which one to boot. This is useful if a new kernel breaks a service.


2. GRUB2 Configuration Files

GRUB2 has two main files:

  1. /etc/default/grub
    • This file contains the main settings for GRUB2.
    • Common options:
      • GRUB_TIMEOUT – How many seconds GRUB waits before booting the default OS.
      • GRUB_DEFAULT – Which kernel or menu entry boots by default.
      • GRUB_CMDLINE_LINUX – Add kernel parameters (e.g., rd.lvm.lv=vg0/lvroot for LVM systems).
  2. /boot/grub2/grub.cfg
    • This is the generated GRUB menu file.
    • You should not edit this file manually, because it is overwritten when you regenerate GRUB configuration.

3. Regenerating GRUB Configuration

After changing /etc/default/grub or other GRUB settings, you must regenerate the GRUB config file:

  • On BIOS systems: grub2-mkconfig -o /boot/grub2/grub.cfg
  • On UEFI systems: grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

IT Example: If you update the GRUB_TIMEOUT to 10 seconds, running the above command ensures GRUB will actually wait 10 seconds before booting.


4. Changing the Default Kernel

If multiple kernels are installed:

  1. List available kernels in GRUB: awk -F\’ ‘/menuentry / {print $2}’ /boot/grub2/grub.cfg
  2. Set the default kernel:
    • By index number: grub2-set-default 1
    • By name: grub2-set-default “CentOS Linux (5.15.0-100.el8.x86_64) 8 (Core)”
  3. Verify default: grub2-editenv list

IT Example: On a production server, you might keep the last stable kernel as default but still keep a newer test kernel available for troubleshooting.


5. Adding Kernel Parameters

Kernel parameters can modify boot behavior:

  • Temporary (for troubleshooting):
    • At the GRUB menu, press e, edit the kernel line, and press Ctrl+X to boot.
  • Permanent:
    • Edit /etc/default/grub: GRUB_CMDLINE_LINUX=”rd.lvm.lv=vg0/lvroot crashkernel=auto”
    • Regenerate GRUB config.

IT Example: You can add single to boot into single-user mode, useful for fixing a misconfigured service or forgotten root password.


6. Booting into Rescue or Emergency Mode

Sometimes, the system fails to boot normally. GRUB allows you to:

  • Boot into rescue mode or emergency mode by editing the kernel line in GRUB:
    • Add rescue or emergency to linux16 or linux line.
  • This boots the system with minimal services so you can repair it.

IT Example: If a critical service prevents normal boot, emergency mode lets you start only the root shell without networking or other services.


7. Managing GRUB on UEFI vs BIOS Systems

  • BIOS (legacy):
    • GRUB config: /boot/grub2/grub.cfg
    • GRUB installation: grub2-install /dev/sda
  • UEFI:
    • GRUB config: /boot/efi/EFI/redhat/grub.cfg
    • GRUB installation: grub2-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=redhat

IT Example: UEFI systems are common in virtualized environments; correct installation ensures the VM boots after migration.


8. RHCSA Exam Key Points

For the exam, you should be able to:

  1. Identify the GRUB2 configuration files (/etc/default/grub, /boot/grub2/grub.cfg)
  2. Modify GRUB settings (timeout, default kernel, kernel parameters)
  3. Regenerate GRUB config using grub2-mkconfig
  4. Set the default boot kernel using grub2-set-default
  5. Boot into emergency/rescue mode for troubleshooting
  6. Know the difference between BIOS and UEFI GRUB locations
  7. Temporarily modify boot parameters at GRUB menu

Tip for exam: Practice editing /etc/default/grub, regenerating GRUB, and rebooting into different kernels. The exam often asks you to change the default kernel or add kernel parameters.


βœ… Summary Table

TaskCommand/ActionNotes
Show available GRUB entriesawk -F\' '/menuentry / {print $2}' /boot/grub2/grub.cfgLists all kernels
Set default kernelgrub2-set-default <index or name>Permanent
Check default kernelgrub2-editenv listShows default boot entry
Edit kernel parameters temporarilyPress e in GRUB menuOnly for next boot
Edit GRUB config permanently/etc/default/grub + grub2-mkconfigRequired after changes
Regenerate GRUB config (BIOS)grub2-mkconfig -o /boot/grub2/grub.cfgMust do after changes
Regenerate GRUB config (UEFI)grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfgUEFI systems
Buy Me a Coffee