Fix grub2 boot UEFI after Ubuntu dual system reinstallation of Windows

If you have installed Ubuntu and Windows and then reinstalled Windows. Then the Grub boot entry will most likely be overwritten by Windows Boot Manager and you won’t be able to enter Ubuntu at that time. But don’t panic, follow the steps below to fix grub2 boot without installing additional software.

Creating a USB boot disk for Ubuntu

In order to repair the boot entries, we need to use the software tools provided with the Ubuntu system. Although we can’t get into the original Ubuntu system for now, we can use the image written on the Ubuntu USB stick to get a working basic Ubuntu environment.

Download the image file from the Ubuntu website.

You can use rufus to quickly create a USB boot disk, taking care to select GPT mode.

Boot U disk boot disk

Reboot your computer, boot the USB drive in the BIOS boot setup, then after entering the Ubuntu boot installer, select Try Ubuntu in the installation screen to enter Ubuntu Live.

Perform a Grub2 rebuild operation

Using fdisk, find the partition where the EFI partition, /boot mount point, is located (or /mount point if you have not set the /boot mount point).

Mount the partition where the /boot mount point is located under /mnt (my partition is on the nvme SSD).

% sudo mount /dev/nvme0n1p6 /mnt/

Mount the EFI partition, where you need to know which partition in your hard drive is the EFI system partition (in my case it is the fifth partition).

% sudo mount /dev/nvme0n1p5 /mnt/boot/efi

Connect other necessary directories

% sudo mount --bind /dev /mnt/dev
% sudo mount --bind /dev/pts /mnt/dev/pts
% sudo mount --bind /proc /mnt/proc
% sudo mount --bind /sys /mnt/sys

Convert root directory to /mnt

% sudo chroot /mnt

Fix Grub2 boot

For 32-bit systems and 64-bit systems, the commands you need to run here are different. The commands corresponding to them are given separately below.

32-bit system

% sudo grub-install --target=i386-efi /dev/nvme0n1

64-bit system

% sudo grub-install --target=x86_64-efi /dev/nvme0n1

After executing one of the above commands, execute Recheck again

% grub-install --recheck /dev/nvme0n1

Follow up cleanup steps (optional)

% exit
% sudo umount /mnt/sys
% sudo umount /mnt/proc
% sudo umount /mnt/dev/pts
% sudo umount /mnt/dev
% sudo umount /mnt

Then reboot and you will see that you have successfully entered the grub2 interface and that grub2 has recognized the Ubuntu system and Windows Boot Manager.

Rebuild the Windows Boot Manager boot entry in Grub2

Reboot your computer, access your Ubuntu system via Grub, and run the following command to regenerate the configuration file

% sudo update-grub