How to recover Ubuntu's Grub boot by UEFI?

  
                

I accidentally deleted Ubuntu's Grub boot under UEFI, so I can't boot into Ubuntu automatically, I can only enter it by manual boot. However, we can use some methods to restore Ubuntu Grub boot, please see below for specific methods.

1. Manually boot into Ubuntu

First, download the Ubuntu installation image (with grub2 boot inside), or directly next to grub2, and then install it in the U disk.

Power on and select the u disk to enter the Grub boot. Then press c to enter the command line mode.

Then manually boot into the original Ubuntu, my boot partition is independent, in (hd0, gpt6), the root partition is in (hd0, gpt7).

If you forget your partition, you can ls,

setroot=(hd0,gpt6)

linux/vmli...roroot=/dev/sda7

initrd/initrd...

boot

The ellipsis part is directly pressed by the Tab key. Then you can enter ubuntu.

2.Rebuild the Grub boot in the ESP partition

Open the command line in Ubuntu and start su in root mode. Then grub-install -v Note that the v here is lowercase. Then the screen pops up and then rebuilds.

If you have any rebuilds, you can mount the ESP partition and see if there is a Ubuntu directory inside. There should be 4 files.

In order to avoid this tragedy in the future, it is recommended to back up the ESP partition before the toss, in case of any eventuality.

First use fdisk -u -l to see which is the ESP partition.

Here I see my ESP partition is in /dev/sda4, write down Sectors, here is 522240.

Then:

dd if=/dev/sda4 bs=512 count=522240 of=./efi.backup

The role of dd is to copy the specified input file Go to the specified output file.

if=Source file path, this is the partition we want to back up.

of=The target file path, here I am writing an efi.backup file in the current directory.

bs=512 means that the size of the block is 512 bytes.

count is how many blocks you want to copy, here we fill in the Sectors obtained above.

If you recover later, directly dd if=./efi.backup bs=512 of=/dev/sda4 will be restored.

The above is the complete content of the Ubuntu Grub boot recovery under UEFI. In the Ubuntu command line, you can re-create the Grub boot of the Ubuntu system.

Copyright © Windows knowledge All Rights Reserved