This script automates the process of restoring the Fedora GRUB bootloader on a UEFI system after it has been removed or overwritten, typically by a Windows installation.
It is designed for a common Fedora setup: a LUKS-encrypted BTRFS root partition and a separate /boot partition. The script performs the following actions:
- Prompts for the LUKS encryption password to unlock the Fedora system partition.
- Correctly mounts the BTRFS
rootsubvolume, the/bootpartition, and the EFI System Partition (ESP). - Binds the necessary system directories from the live environment.
- Executes a
chrootcommand to run commands inside the installed Fedora system. - Inside the
chroot, it reinstalls the GRUB2 and shim packages, which places the boot files in the ESP and creates a new boot entry in the UEFI firmware. - Regenerates the
grub.cfgfile to ensure it detects all available operating systems. - Performs two critical verification checks after the restore process:
- Boot Partition Check: It compares the actual UUID of your
/bootpartition with the UUID written inside GRUB's configuration file. This ensures that when GRUB loads, it knows exactly where to find your Linux kernels and boot files. - EFI Partition Check: It compares the actual UUID of the new EFI System Partition (ESP) with the UUID listed in your Fedora system's
/etc/fstabfile. This is crucial because a Windows installation creates a new ESP with a new UUID. This check ensures your Fedora system can correctly mount the ESP after rebooting, which is necessary for future kernel and bootloader updates.
- Boot Partition Check: It compares the actual UUID of your
This guide follows the official Fedora documentation but is tailored for recent Fedora installations (Fedora 33+) that use a BTRFS filesystem by default and do not use LVM: Restoring the bootloader using the Live disk
- You must be booted from a Fedora Live USB.
- The commands should be run step-by-step manually with
sudo suprivileges. - It assumes a partition layout similar to the one below, where Windows has just been installed, overwriting the original EFI partition.
Assumed lsblk -f -p Output
After cryptsetup luksOpen /dev/nvme0n1p6 myvolume:
/dev/nvme0n1
├─/dev/nvme0n1p1 vfat FAT32 (EFI System Partition)
├─/dev/nvme0n1p2
├─/dev/nvme0n1p3 ntfs (Windows C: Drive)
├─/dev/nvme0n1p4 ntfs (Windows Recovery)
├─/dev/nvme0n1p5 ext4 1.0 (Fedora /boot)
└─/dev/nvme0n1p6 crypto_LUKS 2 (Fedora LUKS Container)
└─/dev/mapper/luks- btrfs fedora (Fedora BTRFS Volume)
- Open a terminal in your Fedora Live environment.
- Gain root privileges for the entire session by running
sudo su. - Open the
restore_grub.shscript in a text editor to view the commands. - Carefully copy and paste each command from the script into your terminal, one at a time, and press Enter.
- Pay close attention to the output of each command, especially the final verification steps, to ensure everything completes successfully before rebooting.