Modern GRUBing

Revision as of 02:40, 3 February 2025 by Root (talk | contribs) (Created page with "Rocky Linux 9 does not use the /etc/default/grub and /boot/grub2/grub.cfg Files any longer. Instead the BLS (Boot Loader Specification) 'method' is used. If one reads the documentation from RedHat, it seems like thing got really messy (and confusing). ==== BLS (Boot Loader Specification) ==== /etc/fstab grub2-mkconfig -o /tmp/boot/grub2/grub.cfg --root-directory=/tmp/LV.ROOT ==== GRUB "Installation" for MBR / BIOS ==== Installs the Stage 1 Boot Code (program) in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Rocky Linux 9 does not use the /etc/default/grub and /boot/grub2/grub.cfg Files any longer. Instead the BLS (Boot Loader Specification) 'method' is used. If one reads the documentation from RedHat, it seems like thing got really messy (and confusing).


BLS (Boot Loader Specification)

/etc/fstab


grub2-mkconfig -o /tmp/boot/grub2/grub.cfg --root-directory=/tmp/LV.ROOT

GRUB "Installation" for MBR / BIOS

Installs the Stage 1 Boot Code (program) in the MBR and Stage 1.5 Boot Code (program) in the "MBR Gap": grub2-install --target=i386-pc /dev/sdd

...and don't forget to set the Boot Partition active using CFDISK or something else

OR

Use DD to clone the Boot Partition

Sources

https://www.baeldung.com/linux/grub-menu-management

https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/ > https://uapi-group.org/specifications/specs/boot_loader_specification/

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_monitoring_and_updating_the_kernel/configuring-kernel-command-line-parameters_managing-monitoring-and-updating-the-kernel

ChatGPT's Opinion

GRUB "Installation" (What Does grub2-install Do?)

The grub2-install command is used to install the GRUB bootloader onto a disk or partition. It places the necessary GRUB boot code onto the target disk and copies GRUB modules required for booting.

How grub2-install Works

When executed, grub2-install performs the following actions:

1. Determines the Installation Target

  • If given a disk (e.g., /dev/sda), it installs GRUB to the MBR or GPT boot partition.
  • If given a partition (e.g., /dev/sda1), it may fail or install to the partition's boot sector (not recommended).
  • If on a BIOS system, it installs the i386-pc GRUB bootloader.
  • If on a UEFI system, it installs x86_64-efi and places EFI files in the EFI system partition.

2. Copies GRUB Core to the Correct Location

  • On BIOS/MBR systems, GRUB places its boot code in the MBR and additional code in the post-MBR gap (sectors after the MBR).
  • On GPT systems using BIOS (BIOS-GPT), it places GRUB in the BIOS Boot Partition.
  • On UEFI systems, it installs the grubx64.efi file into the EFI System Partition (ESP).

3. Selects the Correct GRUB Modules

  • grub2-install determines which GRUB modules are needed based on the filesystem, partition layout, and system firmware.
  • It installs these modules into /boot/grub2/ (BIOS) or /boot/efi/EFI/ (UEFI).

4. Writes GRUB Boot Code

  • BIOS (MBR) Installation:
    • The Stage 1 boot code is written into the MBR.
    • The Stage 1.5 boot code is stored in the post-MBR gap (if available).
    • The Stage 2 boot code (GRUB core modules) is stored in /boot/grub2/.
  • UEFI Installation:
    • The grubx64.efi file is copied to the EFI System Partition.
    • GRUB is registered as a boot entry with the system's UEFI firmware.

5. Registers the Bootloader (If UEFI)

  • On UEFI systems, grub2-install registers grubx64.efi with the UEFI boot manager using efibootmgr.