How to repair grub after installing Windows in preinstalled Ubuntu

You might want to use Windows and Ubuntu OS system in one machine. In this progress, when you install Windows, it might happen that when you start the system, Windows straight starts without asking which OS to run.

This happens because when you install Windows OS, it replaces grub with windows boot loader. To fix this issue, you have to do is replace the Windows boot loader with GRUB.

In this article, We will go step-by-step how to replace how to replace the Windows boot loader with GRUB. This can be fixed by command line as well as GUI tool.

Method 1: Command line

Folow the below steps to fix with command line.

Step 1

Boot Ubuntu from live CD or USB stick, select "Try Ubuntu" option.

Step 2

Now you need to find partition number of your main partition. You can check with command sudo fdisk -l Or sudo blkid Or you can use GParted application, which is preinstalled in Ubuntu. In most cases this should be /dev/sda2 but make sure you got correct partition number.

Step 3

Now mount your partition with below command.

sudo mount /dev/sda2 /mnt

If you have a separate /boot, /var or /usr partitions, mount all these partitions to /mnt/boot, /mnt/var and /mnt/usr respectively. For example,

sudo mount /dev/sdaX /mnt/boot
sudo mount /dev/sdaY /mnt/var
sudo mount /dev/sdaZ /mnt/usr

Where sdaX, sdaY, and sdaZ are partition number you find in step 2.

Step 4

Bind mount some other necessary stuff:

for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done

Step 5

If Ubuntu is installed in EFI mode, use sudo fdisk -l | grep -i efi or GParted to find your EFI partition. It will have a label of EFI. Mount this partition, replacing sdaX with the actual partition number for your system:

sudo mount /dev/sdaX /mnt/boot/efi

Step 6

chroot into your Ubuntu install with below command:

sudo chroot /mnt

Step 7

Now Update grub with below command. You're already running as root.

update-grub

If you get errors or didn't fix your problem, ignore it.

Step 8

If Ubuntu is installed in EFI mode and EFI partition UUID has changed, you may need to update it in /etc/fstab. Compare it:

blkid | grep -i efi
grep -i efi /etc/fstab

If current EFI partition UUID (from blkid) differs from the one in /etc/fstab, update /etc/fstab with current UUID.

Step 9

If everything worked without errors, then you're all set:

exit
sudo reboot

At this point, you should be able to boot normally. If this method didn't fix, you can use the below Boot Repair application.

Method 2: Boot Repair application

There is also GUI Boot Repair tool available to repair grub.

Boot Ubuntu from live CD or USB stick, run "Try Ubuntu" option.

Open the terminal and run the following commands to install Boot Repair.

sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install boot-repair

Now open Boot Repair and select Recommended Repair option.

When repair is finished, then reboot and check if you recovered access to your OSs.

Here is the oficial website, you can also change from advance option.

Was this article helpful?

0 out of 0 person found this article helpful.

Leave a comment

Or

No Comment