Reinstalling Grub EFI on Ubuntu
Recently, whilst migrating some Hyper-V VMs to ESXi, I ran in to issues booting the VMs after migration. On boot, the EFI partition wasn’t found and couldn’t be booted. Thankfully, it’s a rather simple procedure to reinstall Grub EFI.
- Power on the VM and allow it to get stuck on the boot screen searching for an EFI partition.
- Grab the rEFInd Boot Manager ISO and attach it to the VM.
- Hit Control + Alt+ Insert to reboot the VM without removing the ISO. The VM should now boot in to rEFInd which will search for and locate your existing Ubuntu install. It’s normally the default/first, so hit Enter to boot.
- Log in to your Ubuntu installation as normal.
- Reinstall the grub-efi package using sudo apt-get install –reinstall grub-efi .
- Install the grub bootloader on to your disk using sudo grub-install /dev/sda . Don’t forget to adjust /dev/sda to an alternative disk if /dev/sda isn’t your boot disk.
- Generate a new grub configuration using sudo update-grub .
- Shutdown the VM and disconnect the rEFInd ISO. Turn the VM back on and now ESXi will find a bootable EFI partition and Ubuntu will boot as normal.
This process was adapted from Debian’s Grub EFI Reinstall instructions. If you run in to issues, there are a few other things on there to try. I’ve also found that some EFI installations don’t like being moved between computers due to path changes, and have used the above process to get a working EFI boot again.