Restore GRUB 2 after Windows installation wipes it out

One of the biggest problems of installing windows after installing ubuntu is that windows wipes out the Grub 2 and makes Ubuntu inaccessible. The solution to it is available everywhere on the internet and some are on mytechspace too. But since there are different methods, it is natural for anyone to get confused. So here I've summarized all the known methods to restore GRUB 2.

Before getting started, I assume you are in this situation. You have just installed some version of Windows, it could be Windows XP or 7 or Vista or anything. Your GRUB (Boot loader) is gone and you have no way to boot Ubuntu. You have a Ubuntu Live/Installation CD but you do not want to install it afresh again. You boot windows and open mytechspace and you follow one of these methods.

Method 1


Step 1: Boot Ubuntu using the Ubuntu Live CD and open Terminal through it.

Step 2: Execute the following command and find out which partition the Linux (Ubuntu is installed)

[stextbox id="grey"]sudo fdisk -lu[/stextbox]

The output of the instruction will be a few columns. Check the row that ends with "Linux". The First column of that respective row gives the partition where your Linux is installed.

In my case it is /dev/sda3

Step 3: Create a directory to mount this partition

[stextbox id="grey"]sudo mkdir  /media/mntlinux[/stextbox]

Step 4: Mount the Linux ( Ubuntu ) partition.

[stextbox id="grey"]sudo mount /dev/sda3 /media/mntlinux[/stextbox]

Step 5: Now Install Grub.

[stextbox id="grey"]sudo grub-install --root-directory=/media/mntlinux /dev/sda
[/stextbox]

Method 2


Install Grub-Customizer. This is one of the easiest way of installing GRUB. Just install grub customizer by executing the following in your terminal -

[stextbox id="grey"]sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
[/stextbox]

If you find any problem with any part of this, please comment here. We will be glad to help.