Skip to content

Instantly share code, notes, and snippets.

@tobikris
Forked from Tamal/set-chroot.sh
Last active April 6, 2026 23:23
Show Gist options
  • Select an option

  • Save tobikris/e87e57d0acd11910f1133597a97e73f0 to your computer and use it in GitHub Desktop.

Select an option

Save tobikris/e87e57d0acd11910f1133597a97e73f0 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
@doomnonius
Copy link
Copy Markdown

Thank you for this, was able to rescue my coworker's laptop! The luks bit was stopping me from using the original this is forked from.
In line 6 I used udisksctl
Additionally, on this system everything was /root/... ie mount /dev/{device} /mnt/root/boot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment