Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save slmingol/a8290c64af664746b14be948e9d7e45a to your computer and use it in GitHub Desktop.
Save slmingol/a8290c64af664746b14be948e9d7e45a 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
$ 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/nvme0n1p6 # unlock root luks partition
$ mount /dev/mapper/fedora_fedora-root /mnt # mount root partition
$ mount /dev/mapper/fedora_fedora-var /mnt/var
$ mount /dev/nvme0n1p5 /mnt/boot # mount boot partition
$ mount /dev/nvme0n1p1 /mnt/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/$dir ; done
$ # enter chroot
$ chroot /mnt
$ # 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
$ # 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\grubx64.efi' # or, shimx64.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