Modern GRUBing: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Notes; | |||
*LVM on NVMe is the issue | |||
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/ | **<code>pvcreate /dev/sdXy</code> | ||
** <code>vgcreate VG.NVMe.ROOT /dev/ | **<code>vgcreate VG.NVMe.ROOT /dev/sdXy</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> | ||
* | *Format Partitions | ||
**mkfs.vfat -F32 /dev/sdXy | |||
**<code>mkfs.ext4 -v -L ROOT.EXT4 /dev/sdXy ( -v = Verbose, -L = Label )</code> | |||
**<code>mkswap -L SWAP /dev/sdaXy</code> | |||
*MBR Stuff if desired | |||
*UEFI Stuff ("make" the grubx64.efi File) --- Best done from a UEFI system! | |||
**grub2-mkstandalone is a similar command | |||
**Make sure UEFI Stuff is installed (if cloning from an MBR / BIOS based system); | |||
***dnf install grub2-efi-x64 grub2-tools grub2-tools-efi grub2-tools-extra grub2-efi-x64-modules efibootmgr shim-x64 | |||
**<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 --verbose --modules="part_gpt ext2 fat normal search search_fs_uuid search_fs_file configfile all_video gfxterm gzio" **--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 is optional and installs the 'generic' BOOTX64.EFI File. ) | |||
***--modules because apparently absolutely no modules are installed by default, even ext2! | |||
****...and if you've got loads of space, then load up grubx64.efi with everything: --modules="$(ls /boot/grub2/x86_64-efi/ | sed 's/\.mod//g' | tr '\n' ' ')" | |||
**Command to show information on how a system was booted (and can boot): <code>bootctl status</code> | |||
**Command for EFIBootMgr: <code>efibootmgr -v</code> | |||
*GRUB Menu stuff | |||
**Edit: /etc/default/grub | |||
**Make the grub.cfg file: grub2-mkconfig -o /boot/grub2/grub.cfg | |||
**Seemingly useless command (as a text editor would work, no matter the 'threats' in the file): grub2-editenv | |||
***Wait, spoke too soon. If this error is encountered: grub2-editenv: error: environment block too small. when using kernel-install it indicates the grubenv file isn't 1024 bytes. Seems like the grub2-editenv tool pads the file with ###### symbols to make it exactly 1024 Bytes (and we know how important it is to have a file equal to exactly 1024 Bytes!) | |||
**grub2-probe: General information, simple | |||
*Kernel Stuff (initramfs, vmlinuz, bootloader entries, etc.): kernel-install | |||
**to 'redo' VMLinuz Stuff: dracut | |||
*Edit / Register the entry in the Hardwares UEFI Storage space | |||
**efibootmgr --create --disk /dev/nvme0n1 --part 1 --loader '\EFI\rocky\grubx64.efi' --label "Custom GRUB" --bootorder 0001 | |||
*Edit the BLS (Boot Loader System) Entries, etc. | |||
**GRUBBY | |||
*Restore BOOT and ROOT File Systems | |||
**f | |||
**f | |||
*Modify Entries in; | |||
**/boot/loader/entries (wherever mounted) | |||
**/etc/fstab (wherever mounted) | |||
*...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 132: | ||
*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 169: | ||
---- | ---- | ||
== '''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 178: | ||
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 266: | ||
<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 278: | ||
---- | ---- | ||
== '''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 285: | ||
(''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 294: | ||
---- | ---- | ||
== '''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.''' | ||