James's Ramblings

GRUB2

Created: July 09, 2019

Configuration

  • /etc/default/grub contains configuration options.

  • rhgb and quiet parameters are enabled by default and cause all output to be hidden when booting. rhgb is specific to the RHEL ecosystem.

  • man 7 bootparam gives an overview of kernel boot parameters.

  • Changes are not applied automatically; the grub2-mkconfig command needs to be used to update a file in the boot, or EFI partitions.

  • For BIOS systems the file is: /boot/grub2/grub.cfg or /boot/grub/grub.cfg.

  • For UEFI systems the file is: /boot/efi/EFI/redhat/grub.cfg or /boot/efi/EFI/centos/grub.cfg

  • For example: grub2-mkconfig > /boot/grub2/grub.cfg or grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

  • /etc/grub.d contains complex scripts to tell GRUB what order to load things in.

GRUB2 menu

Command mode

  • Press c to enter command mode.

  • In command mode, you can:

    List disks and partitions with: ls To make GRUB LVM aware: insmod lvm Search for a GRUB config file: search.file /grub2/grub.cfg Cat a file: cat

Edit mode

  • Press e to change boot parameters.

  • The key line begins with the word linux; three recovery modes can be accessed by adding options to this line.

  • rd.break: breaks to an interactive shell while still in initrd. Doesn’t mount the system disk. The system disk appears as /sysroot. rd.break is specific to the RHEL ecoysystem.

  • emergency: like rd.break but mounts the system disk.

  • recovery: more services than emergency mode and the system disk mounted.

  • After adding an option, press ^x to continue.

Resetting the root password for RHEL ecosystem distros

In an rd.break environment:

mount -o rw,remount /sysroot
passwd root
touch /.autorelabel
exit
mount -o ro,remount ./sysroot
reboot
  • The system will reboot twice and take some time to boot due to SELinux relabelling the filesystem.

  • /.autorelabel is necessary to relabel files with SELinux contexts.