accidentally deleted EFI partition, system is still running!
Andrew Henderson
I am running Ubuntu 20.04, I accidentally deleted the EFI partition (Damn GParted!) The system is still running. Can I create a new partition in the now UNUSED area, set the EFI flag and boot flag, and then just run update-grub? Will update-grub repopulate the EFI partition? Can I DD the EFI partition from another Ubuntu install?
Quick replies,Greatly Appreciated!
63 Answers
Thanks to ubfan1, I was able to repair and reboot. I followed these steps:
- Recreate a partition using GParted in the "unallocated" section created by deleting the original EFI partition.
- Select FAT32, manage flags and set the "boot" flag.
- Use
blkidcommand to find theUUIDof new partition. - Edit
/etc/fstabso that/boot/efiwill be mounted using the newUUID. - Mount
/boot/efi. - Copy all the files from
/boot/efiof another Ubuntu machine to the new/boot/efi. - Edit
/boot/efi/EFI/ubuntu/grub.cfgto haveUUIDofrootpartition of machine being fixed. - Pray to the Penguin God and reboot.
Everything is fine now.
1@Dennis D, just to complete your answer, not everybody will have another machine with *nix.. so
- recreate a partition using Gparted in the "unallocated" section created by deleting the original EFI partition.
- select FAT32, manage flags and set "boot" flag.
- use blkid to find the UUID of new partition.
- edit /etc/fstab so that /boot/efi will be mounted using the new UUID.
- mount /boot/efi
- install grub with:
sudo grub-install /dev/sdXandsudo grub-install --efi-directory=/boot/efi - run
sudo update-grub
On step 6, just take care selecting the right device (/dev/sda, /dev/sdb, etc).
1I know that it is a bit late for resolving the problem, since you got the system working, but I provide two different solutions.
Removing a partition does not remove the data. Think of the disk as a contiguous space of sectors (long 512, 4096 bytes or so). The information about disk partitioning is stored (for MBR a.k.a. DOS partition table) in the first sector or (for GPT) somewhere at the start and the end of the disk. The rest of disk is left for the partitions. Removing a partition only deletes the record about it in the are where the information about it is stored but not the actual partition data. The partition data will get overwritten only if you create another partition in the same area (or part of it) and write to it. So, when you create the same partition again, everything will work again. Just make sure that it has the same UUID (or change the UUID in GRUB config and fstab), type, position etc.
Use the installation disk for repair. Debian installation CD, and if I remember correctly, also the Ubuntu installation disk has in its text-mode variant a tool exactly for these problems. It can reinstall GRUB or LILO or add it to moved installation. It can also reinstall core system packages etc.
4