Friday, February 7, 2014

How To Recover Grub After Installing Windows | Ubuntu / Kali / Debian Linux

Written by Pranshu Bajpai |  | LinkedIn

A Little Rant


It's 2014 and Windows still assumes that it's the only OS out there.

When you install windows and then install Linux, in the grub boot menu you would find Windows properly accounted for. Grub recognized windows and creates an entry for it in the Boot Menu.

Should we assume Microsoft likes bullying (since there's no apparent technical reason for why they won't make a windows boot-loader that would recognize and make an entry for Linux in the Boot menu).

So if you have Linux and then you try to install Windows, it's nasty boot-manager would remove the linux entry and all you will see at Boot time is Windows and no entry for linux.

Kali Linux is the primary OS that I use on my laptop. I rarely ever use windows so I removed it altogether. However I was developing an App for Windows and needed to code in Windows SDK (Visual Studio) since I needed some libraries like 'wlanapi' that weren't present in Linux IDEs

Long story short, I installed Windows on top of Kali and as I expected, it removed the entry to Kali from the boot menu.

Here are a few commands that I used to solve this issue. This is by far the easiest way to bring the Linux / Ubuntu / Kali boot entry back.

How To Recover Grub (Kali Linux Boot Menu Entry) After Installing Windows 

For this you need:

1. Ubuntu (or Any linux) Live CD / USB
2. Eyes to read and Fingers to Type some commands 

Step 1. Boot from the Ubuntu / Kali / Fedora (any linux) live disk OR USB

Step 2. After the 'Live CD Desktop' loads up, Find Terminal.

Step 3. After the Terminal comes up. Type the following commands:

#sudo mount /dev/sda10 /mnt 

#Note that here for me the root ( / ) of my Kali Linux was on device '/dev/sda10'. For you this would be different and you should check this out under 'Disk Manager' in your Live CD. You are looking for the partition number of your main partition

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

#sudo chroot /mnt

#update-grub

#grub-install /dev/sda

#update-grub


Step 5. That's it. Exit the Terminal and reboot.

You should now see Grub restored. This is one of the ways in which you can easily and quickly restore grub after installing windows

Note that sometimes you may loose the entry to your Windows OS after these steps. But all you need to do is run these 3 commands to get it back:

#apt-get install os-prober

#os-prober

#update-grub

 

Update

 

I recently lost Linux grub again after installing Windows 7 on my laptop and this time I decided to try an ISO called 'boot-repair disk'. I had heard of this a lot and seems to be the tool of choice for people who don't want to get their hands dirty using the linux terminal.

The tool is pretty good in that it does what it is meant for, without any glitches. This is all you have to do:

1. Download 'boot-repair disk' ISO
2. Burn it to a CD or make a bootable Pendrive
3. Boot into the boot-repair disk ISO

After that, it is all automated. As soon as you boot into this live disk, it will automatically begin mounting all your file systems and looking for grub. Once it is located, it will be restored automatically and at the end a message will be displayed to you.

So if you are someone who isn't all that thrilled about typing commands on a Linux terminal in the method I discussed previously, this ISO is for you.

References:
AskUbuntu.com

5 comments:

  1. I did it all.still no grub!
    I use win8.1 64bit and kali 1.6 64bit, I installed windows first,and left 80gb unallocated space for kali,then installed kali.but only windows directly booting

    ReplyDelete
  2. I did it all. Even better: I understand what I did except the "for i... " loop. Why do we need to run that ?

    ReplyDelete
  3. The "for i ..." loop is necessary to have /sys, /proc, /run and /dev available in the chroot environment.
    "update-grub" needs those in order to work correctly.

    ReplyDelete
  4. I'm getting "chroot: can't execute '/bin/bash': exec format error" when I try to do "sudo chroot /mnt"

    ReplyDelete