Previously we discussed about GRUB rescue on lagacy BIOS mode.
But in case the operating systems or GRUB is loaded in UEFI mode, few different steps needs to be performed.
So, here's the guide to rescue broken GRUB on UEFI based systems, more precisely if you prefer to boot the operating system in UEFI mode.
Few things to remember -
- If you laptop/desktop supports UEFI, it doesn't mean that you're using UEFI to load the operating systems.
- If the hard drive/SSD has a GPT partition table, then there's a higher chance that you're using UEFI.
- There must be a FAT32 partition of around 100MB or more if the system is using UEFI.
- This FAT32 partition is called EFI System Partition, or ESP.
- In case Windows 10 was pre-installed on your laptop, then most probably it's using UEFI by default.
Here you can check if you're using UEFI at all or not, both on Windows and Linux. However it's not possible to check the same if you're on GRUB rescue mode.
Without further introduction, lets begin with the main recovery process.
Check if the EFI System partition is present or not
Why I'm stressing this point? May be your motherboard supports UEFI, but you're not using it. And I've seen it a lot.
So one way to be sure about that to check if the ESP partition is present or not.
First use the
ls command on the rescue prompt to list all the disk partitions.
Then again use the
ls (hd0,X) command to check the filesystem type. Replace the X with actual partition number, like 1, 2, 3.
The above screenshot shows that the 2nd partition is the ESP. It's a real 500 GB hard drive connected to Virtualbox to take better screenshots. However there's no Linux installed, just to show you the ESP.
Note: If there's more than one hard drive installed on your system, then it will also show the other drive as
Boot from the grub rescue prompt
At this point, you could have four possibilities.
- GRUB and it's all related files are present, jut the configuration is corrupted or missing.
- Hard drive's partition UUID is changed, rescue prompt is showing no such device or no such partition error.
- All the GRUB related file under the
/boot/grubdirectory are missing or corrupted.
- The GRUB UEFI executable file is missing or corrupted.
- Entire Linux partition is deleted. In that case it's impossible recover, full re-installation is required.
Note: Please don't be confused here, I'm just telling you the possibilities. If the third and fourth point happened, it's not possible to recover without a Live CD or USB.
The fifth point is out of discussion in this tutorial. Instead you could follow the dual boot tutorial to re-install Ubuntu.
No such partition grub rescue
If you don't know what is the Linux root partition yet, then you've to find it out.
Again we'll be using the ls command to check the contents of each partition.
grub rescue> ls (hd0,x)/ # use a trailing slash
Replace the X with actual partition number. The linux root (/) partition should contain
etc and other similar directories.
After being sure about the linux root partition, run these commands one by one on the rescue prompt.
set root=(hd0,x) set prefix=(hd0,x)/boot/grub insmod normal normal
Also don't forget to replace the x with the actual hard drive partition number. If there's a proper grub configuration file under the
/boot/grub directory, it will be loaded.
This should take you to the GRUB menu, select the Linux operating system and boot to it.
After successfully booting and logging in, you've to install GRUB and generate new configuration file.
Open up the terminal application, any of them should be fine.
Then mount the ESP partition and install GRUB with UEFI support, example below.
sudo mount /dev/sda2 /boot/efi sudo grub-install /dev/sda --target=x86_64-efi
Here assuming the
/dev/sda is the main boot drive. There should be no error while installing the GRUB bootloader.
Finally update the GRUB configuration with
sudo update-grub , and you should be able to boot normally after next reboot.
Reinstall GRUB with a Live CD
As I've said before, if the GRUB modules under /boot/grub directory or the GRUB UEFI executable files, namely BOOTx64.efi and grubx64.efi are corrupted or missing, it's not possible to repair from the rescue mode.
So, here we've to use a linux live CD or live USB, any 64 bit live linux distro should work.
Assuming you know how to create a live USB and you already have one ready.
So, power off the laptop/PC, plug in the USB drive containing your favorite live distro and boot to it.
After successfully booting into the live session, you've to identify the linux root partition and the EFI system partition.
fdisk command, example below.
sudo fdisk -l /dev/sda
So, here you can see that the
/dev/sda1 is the EFI system partition and the
/dev/sda2 is the linux root filesystem.
Now we've to mount those partitions accordingly and create a chroot environment. We'll be using a folder,
/mnt/chroot to mount the partitions.
sudo mkdir -p /mnt/chroot # create the chroot directory sudo mount /dev/sda2 /mnt/chroot/ sudo mount /dev/sda1 /mnt/chroot/boot/efi
Let's mount other necessary directories to the chroot environment.
sudo -i # login as root, on the live session mount -B /dev/ /mnt/chroot/dev/ mount -B /dev/pts/ /mnt/chroot/dev/pts/ mount -B /proc/ /mnt/chroot/proc/ mount -B /sys/ /mnt/chroot/sys/ chroot /mnt/chroot/
After chrooting inside the
/mnt/chroot directory, it's time to reinstall the GRUB in UEFI mode and update the configuration.
sudo grub-install /dev/sda --target=x86_64-efi # inside chroot update-grub
Both of these should run without any error. Finally restart the system to check if the GRUB reinstall is successful or not.
Hope you've got the basic idea of grub rescue on UEFI systems. Just make sure that Linux was installed on UEFI mode.
If yo have any question or suggestion, you're always welcome in the comment section.