Recreate EFI partition with GRUB
What happens if this partition (but only the partition!) gets corrupted or is deleted "by accident"?
The system won’t be able to boot again.
But even if the system is not able to boot anymore, it is possible to access all other files of the operating system and user.
Thus it is possible to make a backup of the data before reinstalling the operating system.
Even better, it is possible to recreate the partition, and avoiding to to reinstall everything.
As the system is not bootable, and assuming that taking the internal drive out and connecting it to another PC is not an option, one needs to boot a GNU/Linux distribution from a DVD or USB stick. If possible, the system on the USB stick should match the one installed on the machine, in order to avoid incompatibilities.
In case the EFI partition has been deleted and the PC is still running, it is possible to restore the partition without rebooting from a removable media.
First, it’s essential to locate the EFI partition, or what is going to be the EFI partition.
EFI partitions are relatively small (I’ve seen most sizes between 100MB and 500MB) and formatted in FAT32 with the
With the program
parted it is possible to see if such partition is available with
Model: ATA Samsung SSD 860 (scsi) Disk /dev/sda: 500GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 2097kB 317MB 315MB fat32 boot, esp 2 317MB 463GB 463GB ext4 3 463GB 500GB 36.8GB linux-swap(v1) swap
On a system where the partition is missing, the first partition would not be there, but it is possible to query for free space with
parted /dev/sda print free:
Model: ATA Samsung SSD 860 (scsi) Disk /dev/sda: 500GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 2097kB 317MB 315MB Free Space 2 317MB 463GB 463GB ext4 3 463GB 500GB 36.8GB linux-swap(v1) swap
Once we have a valid partition for EFI, we can install grub on it, and add an entry that will permit to boot to the installed operating system. As far as I know, there are no graphical tools for this task, so one has to resort to the command line.
In case GRUB is being restored from a live CD or USB stick, we need to
mount some directories and use
sudo su; mkdir /tmp/hdd; # or another unused directory mount /dev/sdX2 /tmp/hdd; # /dev/sdX2 is the the partition where the operating system is located mount /dev/sdX1 /tmp/hdd/boot/efi; # /dev/sdX1 is the efi partition mount --bind /dev /tmp/hdd/dev; mount --type proc proc /tmp/hdd/proc; mount --type sysfs sys /tmp/hdd/sys; mount --type devpts pts /tmp/hdd/dev/pts; chroot /tmp/hdd; grub-install --efi-directory=/boot/efi --recheck; update-grub; exit; umount /tmp/hdd/dev/pts /tmp/hdd/sys /tmp/hdd/proc /tmp/hdd/dev /tmp/hdd/boot/efi /tmp/hdd;
If GRUB is being restored from the system installed on the PC, we just need to execute following commands as administrator
grub-install --efi-directory=/boot/efi --recheck; update-grub;
If all commands are executed successfully, it should be possible to reboot without issues. During the execution of
update-grub the program should list the operating systems it found. In the case of a machine with multiple operating systems, if GRUB has been restored from a live CD/USB stick, it might be that the other systems are missing from grub.
This can be fixed by running
update-grub as administrator after rebooting the computer.
Do you want to share your opinion? Or is there an error, some parts that are not clear enough?
You can contact me here.