If you have installed Ubuntu and Windows dual system, then reinstall Windows system. Then the Grub boot item will most likely be overwritten by Windows Boot Manager, and you will not be able to enter Ubuntu at this time. But don't panic, follow the steps below to fix grub2 booting without installing additional software.
Make Ubuntu's U Disk Boot Disk
In order to repair the boot entry, we need to use the software tools provided by the Ubuntu system. Although we are temporarily unable to access the original Ubuntu system, 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 official website https://ubuntu.com/download/desktop.
Make a U disk boot disk can use the installation-free, small and easy-to-userufus. You can use rufus to quickly create a U disk boot disk, pay attention to select GPT mode.
Boot U disk boot disk
Restart the computer, boot the U disk in the BIOS boot settings, and then enter the Ubuntu boot installer, select Try Ubuntu on the installation interface to enter Ubuntu Live.
Perform a Grub2 rebuild operation
Using fdisk, find the EFI partition, the partition where the /boot mount point is located (or / if you don't have a /boot mount point set).
Mount the partition where the /boot mount point is located to /mnt (my partition is on the nvme SSD).
% sudo mount /dev/nvme0n1p6 /mnt/
Mount the EFI partition, here you need to know which partition on your hard disk is the EFI system partition (I am the fifth partition here).
% sudo mount /dev/nvme0n1p5 /mnt/boot/efi
Link to 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
Change the root directory to /mnt
% sudo chroot /mnt
Fix Grub2 boot
The commands you need to run here are different for 32-bit systems and 64-bit systems. The corresponding commands are given below.
% sudo grub-install --target=i386-efi /dev/nvme0n1
% sudo grub-install --target=x86_64-efi /dev/nvme0n1
After executing one of the above commands, execute Recheck again
% grub-install --recheck /dev/nvme0n1
Subsequent cleaning steps (optional)
% exit % sudo umount /mnt/sys % sudo umount /mnt/proc % sudo umount /mnt/dev/pts % sudo umount /mnt/dev % sudo umount /mnt
Then restart, you will find that you have successfully entered the grub2 interface, and grub2 has recognized the Ubuntu system and Windows Boot Manager.
Rebuild the Windows Boot Manager boot entry in Grub2
Restart the computer, enter the Ubuntu system through Grub, and run the following command to regenerate the configuration file
% sudo update-grub