Skip to content

Instantly share code, notes, and snippets.

@jasper-d
Forked from tobikris/repair-dualboot-bootloader.sh
Last active September 3, 2023 23:31
Show Gist options
  • Save jasper-d/fa2443ead0df63ccde88582496645e85 to your computer and use it in GitHub Desktop.
Save jasper-d/fa2443ead0df63ccde88582496645e85 to your computer and use it in GitHub Desktop.
Setting up chroot from a live image in Fedora. Regenerate grub2 for Fedora.
$ # Use Live CD to boot
$ sudo su # Switch to root
$ mkdir /mnt/sysimage
$ fdisk -l # Get names of root, boot & EFI partition names. you can also use blkid
$ # http://dadadom.de/2020/04/11/fix-fedora-uefi-boot-with-encrypted-partitions/
$ udiskctl unlock -b /dev/nvme0n1p4 # unlock root luks partition
$ mount /dev/mapper/luks-123 /mnt/sysimage -t btrfs -o subvol=root
$ mount /dev/nvme0n1p3 /mnt/sysimage/boot # mount boot partition
$ mount /dev/nvme0n1p1 /mnt/sysimage/boot/efi # mount EFI partition
# Note: If you are not able to mount EFI partition ('Input/Output error'),
# You may have to repair ESP file system or format ESP.
# fsck.vfat /dev/nvme0n1p1
# mkfs.vfat /dev/nvme0n1p1
# If formatted then we may have to update UUID at /etc/fstab
$ ls /mnt/boot/efi # should show all OS names under EFI
$ # mount the virtual filesystems that the system uses to communicate with processes and devices
$ for dir in /dev /proc /sys /run /var/run; do mount --bind $dir /mnt/sysimage/$dir ; done
$ # enter chroot
$ chroot /mnt/sysimage
$ # https://fedoraproject.org/wiki/GRUB_2#Instructions_for_UEFI-based_systems
$ rm /boot/efi/EFI/fedora/grub.cfg
$ rm /boot/grub2/grub.cfg
$ dnf reinstall shim-* grub2-efi-* grub2-common
$ grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
$ # All things done; now exit from chroot
$ exit
$ # Check BIOS boot details
$ efibootmgr -v
$ # In case you need to create new entry in BIOS
$ efibootmgr -c -d /dev/nvme0n1p1 -p 1 -L Fedora -l '\EFI\fedora\shimx64.efi' # or, grubx64.efi
$ # Copy grubx64.efi from Live USB, if required
$ cp -p /boot/efi/EFI/grubx64.efi /mnt/boot/efi/EFI/fedora
# Check /etc/fstab UUID, update if necessary
$ # Now you can reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment