I recently got a new pre-loved laptop and as always I nuked Windows but in the process of booting up, I noticed that my BIOS was a bit out of date. Like a whole year out of date. Flashing your BIOS in Ubuntu is a trivial albeit manual process nowadays. You just have to follow these steps:
- Go to your PC manufacturer’s website
- Enter your device’s service tag or serial number
- Download the BIOS .exe file or .iso file depending on your device maker
- Plugin a USB drive:
- Delete all partitions from it
- Format it using an ancient file system called FAT
- Reboot your laptop and flash BIOS
A case of mistaken partition
Easy right? Wrong. In the process of deleting all partitions, I used a graphical utility and failed to pay attention to the disk I was editing. Both my USB and OS drive had EFI partitions. I ended up deleting the all-important EFI partition without even noticing. The operation failed when I tried to delete my main partition. Again I was so distracted I failed to notice that I wasn’t working on my external drive.
Everything came to a crashing halt when I decided to restart. The laptop wouldn’t boot up and kept saying it was checking memory. Firing up a one-time boot using F12 showed that there was no operating system. Fortunately the USB I had failed to edit was a live USB. After booting up I noticed the EFI partition was missing. In the old Legacy Boot days not booting up could easily be fixed by reinstalling Grub2 the glorious Linux bootloader. Most internet searchers were useless but a few hours later I found a solution. Guess not people are making the mistake I made.
How to reinstall the EFI partition after accidentally deleting it in Ubuntu 20.04
The following steps will allow you to reinstall Grub on a computer with EFI enabled in order to make it bootable again. First, make sure you have an Ubuntu Live USB with Ubuntu 20.04. I have a 30GB UHS 3 SD card that I always keep at the back of my wardrobe draw that has the latest LTS on it just in case. You would be wise to have one too. You never know when you need it. If you don’t have a spare computer you will have to download the Ubuntu ISO on your phone and borrow a computer to make a live USB.
Then follow these steps:
- Plug in your USB preferably in the USB 3 port if you have a disk that supports it
- Boot up your machine from USB on most machines you press F12 or F8 at the splash machine
- When Ubuntu boots up select Try Ubuntu as opposed to Install Ubuntu
- Open a Terminal
- Determine whether your computer is in EFI or Legacy mode first
- [ -d /sys/firmware/efi ] && echo “EFI boot on HDD” || echo “Legacy boot on HDD”
- If your computer is in Legacy boot just reinstall Grub the old fashioned way if it’s in EFI boot then we are in business
- Run the command sudo fdisk -l to see all the drives and partitions on the operating system
- In my case, my main drive (i.e. the one inside the laptop) was shown as /dev/sda while my USB was identified as /dev/sdb
- The main drive only had one partition /dev/sda2 instead of the usual two. The first partition /dev/sda1 was missing
- I opened the Disks utility which is preinstalled
- Created a new partition at the beginning of the disk
- Format the partition as a FAT partition
- Go back to the terminal and mounted the main partition to /mnt using command: sudo mount /dev/sda2 /mnt
- Now mount the EFI partition to EFI directory of your main drive: sudo mount /dev/sda1 /mnt/boot/efi
- Prepare chroot environment if you don’t know what that is it’s OK just do it: for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
- Now activate chroot and set /mnt as root: sudo chroot /mnt
- Finally reinstall grub: grub-install /dev/sda
- Make grub pick up the new changes: sudo update-grub
That’s almost all of it. If you followed these steps you should be able to reboot. However, in my case, the machine was taking about 45 seconds to reboot instead of the usual 5-9 seconds to get to the “log on” screen. Pressing escape showed me what was going on. Startup scripts were trying to mount the original none existent old EFI partition. Because it didn’t exist the script would get stuck and the system would wait for it to timeout.
To fix this I followed the following steps:
- Patiently waited for the computer to boot up and logged in
- Open the fstab file using the command: sudo nano /etc/fstab
- Navigated to the line about mounting EFI created during installation and commented it out by placing # at the beginning
- Run command to obtain the partition’s new UUID: sudo blkid /dev/sda1
- Created new entry: UUID=D303-EB8B /boot/efi vfat umask=0077 0 1
- Run: sudo update-grub
Make sure you replace the UUID with your actual UUID obtained using the blkid command otherwise it won’t work. Also, the last command about updating grub is not needed after updating fstab but it doesn’t hurt to run it. After this, my blazing boot times were restored.
I lived to flash another time
I merrily went on to flash my BIOS updated but this time around I was super attentive. Flashing BIOS can be dangerous especially if you make a mistake. It might turn your laptop into a paperweight. Deleting the wrong partition might just have been a blessing in disguise as it shocked my wandering mind into attention.
19 comments
this has to rate as the most boring thing i have read all week
Not boring, but life saving. Thanks for this clear explanation. After 30+ years working on computers I managed to be one of the people who made the mistake you made. Luckily I realized it while the system stil ran, so I could even shorten your procedure. And safely reboot my laptop. Happy days are here again!
Life saving – I forgot to back up my EFI partition.
Then Acer deleted my HDD while repairing a minor hardware issue….
All I can say is THANK YOU!
Worked perfectly for me…
I was about to cry because I deleted the EFI partition on my company laptop mistakenly. You can’t imagine how that saved my life 🙂
Thanks a lot. I exchanged a 250G SSD with a 500G but forgot that the boot partition was on that SSD. With this recipe, I saved the installation.
In my case I had to create the directories first to mount. Just for those going copy-paste …
cd /mnt;
for i in /dev /dev/pts /proc /sys /run;
do sudo mkdir -p $i;
sudo mount -B $i /mnt$i;
done
God bless you, who ever you are. Thanks a million. This step by step walkthrough helped a lot. I accidentally just deleted my EFI partition.
Your blog just saved me a lot of time. Thank you very much!
Great tutorial. Nice work.
However, after running the “update-grub” command while on live-usb (sdb1), I got the following:
Generating grub configuration file …
Found linux image: /boot/vmlinuz-5.10.0-11-amd64
Found initrd image: /boot/initrd.img-5.10.0-11-amd64
Found linux image: /boot/vmlinuz-5.10.0-9-amd64
Found initrd image: /boot/initrd.img-5.10.0-9-amd64
grub-probe: error: cannot find a GRUB drive for /dev/sdb1. Check your device map.
done
Still unable to boot into the OS.
You are probably confusing the disks.
fantastic instructions!! you saved my day!!!!
Thanks very much. You saved my day! Best tutorial ever
Thanks so much! This was a lifesaver.
Friend, thanks for saving Friday evening.
I accidentally deleted the efi partition on the WD system drive instead WD usb disk (
I’m having this problem except I’m coming at it from a restored image. I backed up just the OS partition and then restore it to a partition I made on a new disk that used up all of the space on disk. I have since lost my backup.
Do I need to move this data off, wipe drive, create a new 16mb partition and I another with remaining space for this data and attempt this? Can I still revive this machine with that route? Thank you.
Just thank you!
Awesome awesome, life saver. I knew how to chroot but easy to follow instructions helped at the panic moment. Great content.
Thanks a lot . It work like a charm