Last active
March 20, 2025 22:39
-
-
Save Tamal/73e65bfb0e883e438310c5fe81c5de14 to your computer and use it in GitHub Desktop.
Setting up chroot from a live image in Fedora. Regenerate grub2 for Fedora.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ # 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 | |
$ mount /dev/mapper/fedora_localhost--live-root /mnt # mount root partition | |
$ cat /mnt/etc/fedora-release | |
Fedora release 31 (Thirty One) | |
$ mount /dev/nvme0n1p2 /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; do mount --bind $dir /mnt/$dir ; done | |
$ # enter chroot | |
$ chroot /mnt | |
$ # Now you can do all the work e.g. fix grub | |
$ dnf reinstall grub2-efi shim -y | |
$ grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg # Regenerate grub2 | |
$ # Check /etc/fstab UUID, update if necessary [Hint: lsblk -f would show partition UUIDs] | |
$ # All things done; now exit from chroot | |
$ exit | |
$ # Check BIOS boot details [ Note: this command won't work if you are inside chroot. ] | |
$ 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 | |
$ # To delete entry from efibootmgr use: efibootmgr -b <#entry> -B | |
$ # Copy grubx64.efi from Live USB, if required | |
$ cp -p /boot/efi/EFI/grubx64.efi /mnt/boot/efi/EFI/fedora | |
$ exit | |
$ # Now you can reboot |
Thank you so much! You saved my weekend
You just saved me a lot of trouble.
Special shout out to this command:
$ # Copy grubx64.efi from Live USB, if required
$ cp -p /boot/efi/EFI/grubx64.efi /mnt/boot/efi/EFI/fedora
An windows 11 update deleted this file.
When I run this command "$ for dir in /dev /proc /sys /run; do mount --bind $dir /mnt/$dir ; done" it said "do" command unknwon.
I pasted it to chatgpt It created more detailed version with if statement. (As I was in live cd, I lost all command and chats with ai)
I created sh file and pasted ai generated command and gave permission (chmod +x ), then executed with sudo, then followed rest and finally after 3 days of troubleshooting it finaly worked, I do not know how to thank you, you saved hours of my work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adding other steps i had to do to get this working correctly:
adding root folder to fedora doc instructions:
On UEFI systems, bind the efivars directory and mount the EFI system partition (e.g. /dev/sda1).
chroot: failed to run command '/bin/bash': no such file or directory
then continue official docs
etc