2015-12-12

How to reinstall GRUB2 EFI?

Reference 1 : How to reinstall GRUB2 EFI?
Reference 2 : Grub EFI Reinstall
Reference 3 : Linux UEFI 開機

Q : After successfully updating my bios, something went wrong and I ended up with a blinking cursor on the top left corner of a black screen. No errors, no nothing. The bios now only listed a SATA: <disc name> boot option in place of the usual UEFI ubuntu one. I'm using a GPT partitioning scheme.
I eventually found that the working solution was to properly reinstall grub-efi-amd64. So, how do I do this ?

PS: Actually, i succeeded to reinstall GRUB2 EFI on my own and will post my answer here as I was unable to find any complete how-to on this.

A : Boot your computer with a live-usb/CD in UEFI mode. I had two boot options <flash_drive> and UEFI: <flash_drive>, the second is needed to expose the efi variables in /sys/firmware/efi/ so that efibootmgr don't fail later on. Booting with the first option gives me the following error:
Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables.
Try 'modprobe efivars' as root.
modprobe efivars did'nt work for me.

chroot into the broken system (similar to the ubuntu grub2 help but with efi specificities):
sudo mount /dev/sda2 /mnt #sda2 is my root partition
sudo mount /dev/sda1 /mnt/boot/efi #sda1 is my efi partition
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo cp /etc/resolv.conf /mnt/etc/ #makes the network available after chrooting
modprobe efivars # make sure this is loaded
sudo chroot /mnt

Depending on your linux distribution, you now do different things.
For Ubuntu/Debian:
apt-get install --reinstall grub-efi-amd64
or alternatively:
apt-get install --reinstall grub-efi
update-grub
should the above give you a grub, but not a bootable one (…???…)

For Fedora (up to 16, may work for others):
yum reinstall grub-efi

In the following command, you have to replace sdX with the device which has the EFI partition you want to boot from. In --part Y you have to replace the Y with the number of the EFI partition (as in /dev/sdXY).
efibootmgr -c --disk /dev/sdX --part Y
efibootmgr -v # verify a new record called Linux is there
Now type Ctrl+D to exit chroot, unmount everything and reboot:
for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
sudo umount /mnt/boot/efi #please do this. corrupted efi partitions are not nice
sudo umount /mnt
sudo reboot

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.