Modern GRUBing: Difference between revisions

mNo edit summary
Line 1: Line 1:
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).
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).


==== Quick D for Cloning, err, "Recreating" a drive from a BackUp (IE, the closest thing to Acronis that Linux seems to have) ====
====Quick D for Cloning, err, "Recreating" a drive from a BackUp (IE, the closest thing to Acronis that Linux seems to have)====


* Create a duplicate or functionally similar Partition layout to the original
*Create a duplicate or functionally similar Partition layout to the original
** CFDISK and "Logical Volume Commands"
**CFDISK and "Logical Volume Commands"
** Use Blivet from a Rocky 8 Live Boot Device<br />
**Use Blivet from a Rocky 8 Live Boot Device<br />


==== Rough D ====
====Rough D====


* Start from a 'Clean Slate': <code>wipefs -a /dev/sdX</code> (make dang sure the proper 'sdX' is chosen!)
*Start from a 'Clean Slate': <code>wipefs -a /dev/sdX</code> (make dang sure the proper 'sdX' is chosen!)
* Set the Partition Type (MBR or GPT): <code>cfdisk /dev/sdX</code>, (select DOS or GPT, save it (write) )
*Set the Partition Type (MBR or GPT): <code>cfdisk /dev/sdX</code>, (select DOS or GPT, save it (write) )
* Create Partitions: cfdisk
*Create Partitions: cfdisk
** https://en.wikipedia.org/wiki/Partition_type
**https://en.wikipedia.org/wiki/Partition_type
** Linux EXT4: $83 (that's Commodore Speaky for 83h)
**Linux EXT4: $83 (that's Commodore Speaky for 83h)
** Linux LVM (and LVM2): $8E
**Linux LVM (and LVM2): $8E
* LVM Stuff using Commands or BLIVET
*LVM Stuff using Commands or BLIVET (sadly only Rocky Linux 8)
** <code>pvcreate /dev/sdX</code>
**<code>pvcreate /dev/sdX</code>
** <code>vgcreate VG.NVMe.ROOT /dev/sdX</code>
**<code>vgcreate VG.NVMe.ROOT /dev/sdX</code>
*** <code>vgrename WhatEverOldName WhatEverNewName</code>
***<code>vgrename WhatEverOldName WhatEverNewName</code>
** <code>lvcreate -L 64G -n LV.ROOT VG.NVMe.ROOT</code>
**<code>lvcreate -L 64G -n LV.ROOT VG.NVMe.ROOT</code>
* BLIVET
*Format Partitions
**mkfs.vfat -F32 /dev/sdXy
**<code>mkfs.ext4 -v -L ROOT.EXT4 /dev/sdX ( -v = Verbose, -L = Label )</code>
**<code>mkswap -L SWAP /dev/sdaX</code>
*MBR Stuff if desired
*UEFI Stuff
**Make sure UEFI Stuff is installed (if cloning from an MBR / BIOS based system): dnf install -y grub2-efi-x64 grub2-efi-x64-modules shim-x64 efibootmgr
**<code>mkdir /mnt/efi</code>
**<code>mount /dev/nvme0n1p1 /mnt/efi</code>
**<code>grub2-install --target=x86_64-efi --efi-directory=/mnt/efi --bootloader-id=rocky --recheck --force --no-nvram --removable</code> ( --force = Do it on a supposedly 'non-secure' system, --no-nvram = Do it even if a target drive is being prepared as a UEFI Booted system even if the current OS is an MBR / BIOS system, --removable installs the 'generic' BOOTX64.EFI module so the system can boot before )
**Command to show information on how a system was booted (and can boot): <code>bootctl status</code>
**Command for EFIBootMgr: <code>efibootmgr -v</code>
*...and the tribulations continue as the below command won't work from an MBR / BIOS system or theoretically from any system that isn't the one being booted, run from etc.;
**Entry for Hardware Firmware (AKA BIOS Settings): efibootmgr --create --disk /dev/sdb --part 1 --loader /EFI/rocky/grubx64.efi --label "Rocky Linux" --verbose
**Work Around:


====BLS (Boot Loader Specification)====
====BLS (Boot Loader Specification)====
Line 88: Line 102:
*On '''UEFI systems''', <code>grub2-install</code> registers <code>grubx64.efi</code> with the UEFI boot manager using <code>efibootmgr</code>.
*On '''UEFI systems''', <code>grub2-install</code> registers <code>grubx64.efi</code> with the UEFI boot manager using <code>efibootmgr</code>.


=== More from ChatGPT on "GRUBing" ===
===More from ChatGPT on "GRUBing"===


= '''Comprehensive Guide to Installing GRUB on Rocky Linux (UEFI & BIOS)''' =
='''Comprehensive Guide to Installing GRUB on Rocky Linux (UEFI & BIOS)'''=
This guide covers:
This guide covers:


* '''UEFI bootloader installation''' on a target drive.
*'''UEFI bootloader installation''' on a target drive.
* '''Legacy BIOS (MBR) bootloader installation'''.
*'''Legacy BIOS (MBR) bootloader installation'''.
* '''BLS (Boot Loader Specification) and its effect on <code>grub2-mkconfig</code>.'''
*'''BLS (Boot Loader Specification) and its effect on <code>grub2-mkconfig</code>.'''
* '''GRUB Boot Stages Explanation (Stage 1, Stage 1.5, Stage 2).'''
*'''GRUB Boot Stages Explanation (Stage 1, Stage 1.5, Stage 2).'''
* '''How to properly configure bootloader entries and verify installation.'''
*'''How to properly configure bootloader entries and verify installation.'''


----
----


== '''1. Understanding GRUB Boot Stages''' ==
=='''1. Understanding GRUB Boot Stages'''==
{| class="wikitable"
{| class="wikitable"
!'''GRUB Stage'''
!'''GRUB Stage'''
Line 125: Line 139:
----
----


== '''2. Installing GRUB for UEFI Booting''' ==
=='''2. Installing GRUB for UEFI Booting'''==


=== '''A. Identify the Target Drive''' ===
==='''A. Identify the Target Drive'''===
List available drives and partitions:
List available drives and partitions:


Line 134: Line 148:
Example: If the target drive is <code>/dev/sdb</code>, and the EFI partition is <code>/dev/sdb1</code>, mount it:
Example: If the target drive is <code>/dev/sdb</code>, and the EFI partition is <code>/dev/sdb1</code>, mount it:


=== '''B. Bind System Directories (for Chroot)''' ===
==='''B. Bind System Directories (for Chroot)'''===
If configuring an external system:
If configuring an external system:


=== '''C. Install Required UEFI GRUB Packages''' ===
==='''C. Install Required UEFI GRUB Packages'''===


=== '''D. Install GRUB to the Target Drive''' ===
==='''D. Install GRUB to the Target Drive'''===


* <code>--target=x86_64-efi</code> → Specifies '''UEFI mode'''.
*<code>--target=x86_64-efi</code> → Specifies '''UEFI mode'''.
* <code>--efi-directory=/boot/efi</code> → Ensures GRUB is installed in the EFI partition.
*<code>--efi-directory=/boot/efi</code> → Ensures GRUB is installed in the EFI partition.
* <code>--bootloader-id=rocky</code> → Labels the boot entry as '''"Rocky"'''.
*<code>--bootloader-id=rocky</code> → Labels the boot entry as '''"Rocky"'''.
* <code>--recheck</code> → Forces a re-scan of the drive layout.
*<code>--recheck</code> → Forces a re-scan of the drive layout.


=== '''E. Generate the GRUB Configuration''' ===
==='''E. Generate the GRUB Configuration'''===
⚠ '''However, Rocky Linux follows BLS, which makes this step less critical''' (explained in Section 4).
⚠ '''However, Rocky Linux follows BLS, which makes this step less critical''' (explained in Section 4).
----
----


== '''3. Installing GRUB for Legacy BIOS (MBR Boot)''' ==
=='''3. Installing GRUB for Legacy BIOS (MBR Boot)'''==


=== '''A. Mount the Target Drive's Root Partition''' ===
==='''A. Mount the Target Drive's Root Partition'''===
If the system has a separate <code>/boot</code> partition:
If the system has a separate <code>/boot</code> partition:


=== '''B. Chroot into the Target System''' ===
==='''B. Chroot into the Target System'''===


=== '''C. Install Required BIOS GRUB Packages''' ===
==='''C. Install Required BIOS GRUB Packages'''===


=== '''D. Install GRUB to the MBR of the Target Drive''' ===
==='''D. Install GRUB to the MBR of the Target Drive'''===


* <code>--target=i386-pc</code> → '''Required for Legacy BIOS (MBR) booting'''.
*<code>--target=i386-pc</code> → '''Required for Legacy BIOS (MBR) booting'''.
* <code>/dev/sdb</code> → '''Must be the whole disk (not a partition like <code>/dev/sdb1</code>)'''.
*<code>/dev/sdb</code> → '''Must be the whole disk (not a partition like <code>/dev/sdb1</code>)'''.
* <code>--recheck</code> → Forces a disk layout rescan.
*<code>--recheck</code> → Forces a disk layout rescan.


=== '''E. Generate the GRUB Configuration''' ===
==='''E. Generate the GRUB Configuration'''===
⚠ '''But due to BLS, <code>grub.cfg</code> is no longer the main configuration source.'''
⚠ '''But due to BLS, <code>grub.cfg</code> is no longer the main configuration source.'''
----
----


== '''4. Understanding BLS (Boot Loader Specification)''' ==
=='''4. Understanding BLS (Boot Loader Specification)'''==
Rocky Linux follows '''BLS (Boot Loader Specification)''', meaning '''boot entries are controlled by systemd-boot entries, not <code>grub2-mkconfig</code>'''.
Rocky Linux follows '''BLS (Boot Loader Specification)''', meaning '''boot entries are controlled by systemd-boot entries, not <code>grub2-mkconfig</code>'''.


=== '''How to Manually Manage BLS Entries''' ===
==='''How to Manually Manage BLS Entries'''===


# '''List Existing Boot Entries:'''
#'''List Existing Boot Entries:'''
# '''Manually Create a BLS Entry:'''
#'''Manually Create a BLS Entry:'''
# '''Example BLS Entry (<code>rocky.conf</code>)'''
#'''Example BLS Entry (<code>rocky.conf</code>)'''
# '''Enable BLS Support in GRUB (if needed)'''
#'''Enable BLS Support in GRUB (if needed)'''


=== '''Why BLS Makes <code>grub2-mkconfig</code> Less Relevant''' ===
==='''Why BLS Makes <code>grub2-mkconfig</code> Less Relevant'''===


* '''Traditional GRUB entries are no longer used''' in Rocky Linux.
*'''Traditional GRUB entries are no longer used''' in Rocky Linux.
* The '''bootloader reads BLS entries instead'''.
*The '''bootloader reads BLS entries instead'''.
* '''<code>grub.cfg</code> is still used for bootloader settings''', but '''kernel entries are controlled by BLS'''.
*'''<code>grub.cfg</code> is still used for bootloader settings''', but '''kernel entries are controlled by BLS'''.


----
----


== '''5. Verify Installation''' ==
=='''5. Verify Installation'''==


=== '''Check EFI Boot Entries (For UEFI Only)''' ===
==='''Check EFI Boot Entries (For UEFI Only)'''===


=== '''Check GRUB Installation''' ===
==='''Check GRUB Installation'''===


=== '''Check BLS Entries''' ===
==='''Check BLS Entries'''===


=== '''Reboot and Test''' ===
==='''Reboot and Test'''===
----
----


== '''6. Summary''' ==
=='''6. Summary'''==
{| class="wikitable"
{| class="wikitable"
!'''Boot Mode'''
!'''Boot Mode'''
Line 222: Line 236:
<br />
<br />


== '''1. The Presence (or Absence) of <code>/boot/grub2/grub.cfg</code>''' ==
=='''1. The Presence (or Absence) of <code>/boot/grub2/grub.cfg</code>'''==


* If '''<code>grub.cfg</code> exists''', GRUB will parse it.
*If '''<code>grub.cfg</code> exists''', GRUB will parse it.
* If '''<code>grub.cfg</code> does NOT exist''', GRUB will attempt to '''read the BLS entries directly''' instead.
*If '''<code>grub.cfg</code> does NOT exist''', GRUB will attempt to '''read the BLS entries directly''' instead.


This means:
This means:
Line 234: Line 248:
----
----


== '''2. GRUB’s Bootloader Installation (<code>grub2-install</code>)''' ==
=='''2. GRUB’s Bootloader Installation (<code>grub2-install</code>)'''==
The actual bootloader installed to the disk controls whether it defaults to '''BLS mode or <code>grub.cfg</code> mode'''.
The actual bootloader installed to the disk controls whether it defaults to '''BLS mode or <code>grub.cfg</code> mode'''.


Line 241: Line 255:
(''where <code>/dev/sdX</code> is your boot disk, like <code>/dev/sda</code> or <code>/dev/nvme0n1</code>''), it does the following:
(''where <code>/dev/sdX</code> is your boot disk, like <code>/dev/sda</code> or <code>/dev/nvme0n1</code>''), it does the following:


* Sets up '''GRUB’s core image''' (<code>/boot/grub2/i386-pc/core.img</code> for BIOS systems or <code>/boot/efi/EFI/rocky/grubx64.efi</code> for UEFI systems).
*Sets up '''GRUB’s core image''' (<code>/boot/grub2/i386-pc/core.img</code> for BIOS systems or <code>/boot/efi/EFI/rocky/grubx64.efi</code> for UEFI systems).
* Embeds the logic for '''how GRUB will find and load boot entries'''.
*Embeds the logic for '''how GRUB will find and load boot entries'''.
* If BLS is active, it instructs GRUB to '''skip parsing <code>grub.cfg</code> and go directly to BLS entries'''.
*If BLS is active, it instructs GRUB to '''skip parsing <code>grub.cfg</code> and go directly to BLS entries'''.


This means: ✔ If GRUB was installed '''with BLS enabled''', even if <code>grub.cfg</code> exists, it may not be used.
This means: ✔ If GRUB was installed '''with BLS enabled''', even if <code>grub.cfg</code> exists, it may not be used.
Line 250: Line 264:
----
----


== '''How to Explicitly Switch Between BLS and <code>grub.cfg</code>''' ==
=='''How to Explicitly Switch Between BLS and <code>grub.cfg</code>'''==


=== '''To Force BLS Mode (and Ignore <code>grub.cfg</code> Completely)''' ===
==='''To Force BLS Mode (and Ignore <code>grub.cfg</code> Completely)'''===


# '''Ensure BLS entries exist''':  If this folder is empty, something is broken.
#'''Ensure BLS entries exist''':  If this folder is empty, something is broken.
# '''Delete <code>grub.cfg</code>''' (this ensures GRUB won’t use it):
#'''Delete <code>grub.cfg</code>''' (this ensures GRUB won’t use it):
# '''Ensure GRUB is installed with BLS support''':  ''(For UEFI systems; adjust for BIOS if needed.)''
#'''Ensure GRUB is installed with BLS support''':  ''(For UEFI systems; adjust for BIOS if needed.)''
# '''Reboot''' and verify that <code>grub.cfg</code> is no longer in use.
#'''Reboot''' and verify that <code>grub.cfg</code> is no longer in use.


----
----


=== '''To Force Legacy <code>grub.cfg</code> Mode (and Ignore BLS)''' ===
==='''To Force Legacy <code>grub.cfg</code> Mode (and Ignore BLS)'''===


# '''Ensure <code>grub.cfg</code> is present''':
#'''Ensure <code>grub.cfg</code> is present''':
# '''Reinstall GRUB to disable BLS mode''':  ''(The <code>--no-bootloader-spec</code> flag explicitly prevents GRUB from using BLS.)''
#'''Reinstall GRUB to disable BLS mode''':  ''(The <code>--no-bootloader-spec</code> flag explicitly prevents GRUB from using BLS.)''
# '''Reboot''' and verify that <code>grub.cfg</code> is being used.
#'''Reboot''' and verify that <code>grub.cfg</code> is being used.


----
----


=== '''Final Answer''' ===
==='''Final Answer'''===
✔ '''The real switch between BLS and <code>grub.cfg</code> is NOT in <code>/etc/default/grub</code>—it's controlled by how GRUB is installed and configured.'''
✔ '''The real switch between BLS and <code>grub.cfg</code> is NOT in <code>/etc/default/grub</code>—it's controlled by how GRUB is installed and configured.'''