48

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!

Dennis D
  • 839

4 Answers4

70

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

Everything is fine now.

sotirov
  • 4,379
Dennis D
  • 839
27

@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).

Hackz
  • 371
3

I know that it is a bit late for resolving the problem, since you got the system working, but I provide two different solutions.

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

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

andrew.46
  • 39,359
jiwopene
  • 209
0

A simple solution exists to rescue a removed partition with parted:

  • boot a linux setup usb key (like ubuntu live USB try-or-install)
  • run sudo parted in a terminal
  • print devices to list your devices
  • select the right device with the select command
  • print to show the hole where your deleted partition was
  • then use the rescue command giving the bounds printed above

The partition is restored and its UUID has not changed. You just have to reboot.

etham
  • 101
  • 3