Score:42

accidentally deleted EFI partition, system is still running!

it flag

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!

cc flag
Maybe if you're lucky, you just need to reset the partition start/end and the flags. update-grub does not copy in new bootloaders, you need grub-install for that. Do you have a Windows dual boot? The EFI bootloaders are just files on a FAT filesystem, you may copy them in, but the .../EFI/ubuntu/grub.cfg three line stub has a UUID you need to edit to be your root UUID.
Dennis D avatar
it flag
Thanks, but what files, copied from where.
Dennis D avatar
it flag
Never mind, I copied files from another machine and then update the UUID is you indicated. Thanks.
cc flag
If that worked for you, you may answer your own question, and accept it after a few days to mark it solved, helping others and gaining some reputation points for yourself.
Vikki avatar
eg flag
@ubfan1: Strictly-speaking, you only gain rep from answering your question if someone upvoted your answer - accepting your own answer doesn't give you the reputation boost that you accepting someone else's answer or someone else accepting your answer gives you.
Score:65
it flag

Thanks to ubfan1, I was able to repair and reboot. I followed these steps:

  1. Recreate a partition using GParted in the "unallocated" section created by deleting the original EFI partition.
  2. Select FAT32, manage flags and set the "boot" flag.
  3. Use blkid command to find the UUID of new partition.
  4. Edit /etc/fstab so that /boot/efi will be mounted using the new UUID.
  5. Mount /boot/efi.
  6. Copy all the files from /boot/efi of another Ubuntu machine to the new /boot/efi.
  7. Edit /boot/efi/EFI/ubuntu/grub.cfg to have UUID of root partition of machine being fixed.
  8. Pray to the Penguin God and reboot.

Everything is fine now.

Organic Marble avatar
us flag
Welcome to Ask Ubuntu. Nice job!
Score:19
cn flag

@Dennis D, just to complete your answer, not everybody will have another machine with *nix.. so

  1. recreate a partition using Gparted in the "unallocated" section created by deleting the original EFI partition.
  2. select FAT32, manage flags and set "boot" flag.
  3. use blkid to find the UUID of new partition.
  4. edit /etc/fstab so that /boot/efi will be mounted using the new UUID.
  5. mount /boot/efi
  6. install grub with: sudo grub-install /dev/sdX and sudo grub-install --efi-directory=/boot/efi
  7. run sudo update-grub

On step 6, just take care selecting the right device (/dev/sda, /dev/sdb, etc).

Dennis D avatar
it flag
Thanks, I didn't know if those programs would reinstall those files. It sounds like you know that they do. Also, with all of my redundant backup systems, I had not backed up the /boot/efi directory. I do now!
oᴉɹǝɥɔ avatar
ir flag
This is a more useful answer as it doesn't require other instances of Linux in order to copy efi directory contents from and doesn't involve tweaking grub.cfg by hand.
Score:3
in flag

I 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.

us flag
For the first solution you should indicate how to restore the partition without formatting it, e.g. with testdisk.
jiwopene avatar
in flag
@DidierL, `testdisk` is not needed, since you know where the original EFI partition was stored (since it usually is on the start or the end of the disk and other partitions follow, or it is between multiple partitions). Manually creating the partition (e.g. using GParted that is used by the asker) is enough. (`testdisk` will do just the same thing.)
us flag
Creating a new partition with GParted will allocate a new, empty FAT, so it won’t recover anything, right? In fact if it wasn’t the case it would be likely to create corrupted partitions when allocating over previously existing space. testdisk however can just resurrect the previously existing partition.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.