Recovering Grub after installing Windows, using Ubuntu.

It so happened that after installing windows on my system (which already had linux, ubuntu, installed on it), the grub menu that used to come at the beginning stopped appearing. Instead, it started to boot directly into windows.

In order to solve this problem, I did the following. Of course, I found a lot of answers to this problem on the net, but what I did worked for me fine. But be sure to sit patiently and correct it in case something does not work fine. Never give up!

(Note: I also do believe that the following works only when the ‘vmlinuz’ and ‘initrd.img’ files are at the root directory itself. Check this in step 5. In step 5, ‘vmlinuz’ and ‘initrd.img’ should be there in the ‘temp’ folder we created.)

1. Boot using a live cd of ubuntu.

2. Open a terminal and run the command

sudo fdisk -l

It lists the complete partition table of the hard disk. In there, identify which partition you have got your linux installed on. You can identify it using the drive size you had allocated for it and looking at the last column of the output which will be ‘extended’ for all of your linux partitions. The partition will most probably be something like /dev/sda5 or something. Remember this partition.

3. Create a temporary folder in your home directory (Note: You can make the temporary folder anywhere you want. I’m using the home folder just for the sake of explanation). I’m calling it ‘temp’ for now. So that ‘temp’ folder’s path will be /home/ubuntu/temp.

4. Mount your linux partition there. That is, assuming that you found your linux partition to be /dev/sda5, you mount that at the ‘temp’ folder by doing the following command

sudo mount /dev/sda5 /home/ubuntu/temp

5. If you want to check whether you have mounted the correct partition, go to your home folder and open temp. You will be in the ‘/’ directory. In there you will find ‘home’, in which your home folder’s name will be there. Once you’ve confirmed you have mounted the correct partition, do step 6.

6. You have to install grub by showing the system where to read the data from the hard disk at the beginning. Don’t worry, just run the following command

sudo grub-install –root-directory=/home/ubuntu/temp /dev/sda

The ‘/dev/sda’ corresponds to your hard disk name. Replace it by whatever the command ‘sudo fdisk -l’ command showed you.

7. You’re done. You may restart your system.

You might want to check out how I upgraded to 12.04 too!

PS: For editing the grub menu that appears, check out my post

https://sosaysharis.wordpress.com/2011/04/29/editing-grub-menu-in-ubuntu-10-04-and-above/

Editing GRUB menu in ubuntu 10.04 and above.

1. Open a terminal.

2. Type in

sudo update-grub

Type in your password.

3. Go to the directory /boot/grub. To do this type

cd /boot/grub

4. Here if you type ls, a lot of files will be there. Fortunately, we’re only interested in grub.cfg.

5. Open grub.cfg with a text editor. To do this type

sudo gedit grub.cfg &

(The ampersand sign (&) is to run the gedit program in the background while we can use the terminal for other purposes. Try executing the above command without the ‘&’ sign and you will understand)

6. In there, find the following line

### BEGIN /etc/grub.d/10_linux ###

7. From the beginning of this line, select till the end of the file. The last line of the file will be

### END /etc/grub.d/40_custom ###

8. After you have selected it, copy it. Right-click, copy will do.

9. Now go back to the terminal and go to the /etc/grub.d directory. To do this type

cd /etc/grub.d

10. In this directory, type ls to see the files present. There will be a file called 40_custom. Open this up using the following command

sudo gedit 40_custom &

11. There will be a few lines at the top. Don’t worry. Just paste whatever you copied from grub.cfg over here. Right-click, paste will do.

12. After you have pasted, look closely at it. There will be something similar to the following

menuentry ‘Ubuntu 10.04 Lucid Lynx right here!!’ –class ubuntu –class gnu-linux –class gnu –class os {
    recordfail
    insmod ext2
    set root='(hd0,9)’
    search –no-floppy –fs-uuid –set cafb13dd-92cd-4618-acfe-de02a0ca49e5
    linux    /boot/vmlinuz-2.6.32-28-generic root=UUID=cafb13dd-92cd-4618-acfe-de02a0ca49e5 ro   quiet splash
    initrd    /boot/initrd.img-2.6.32-28-generic
}

The difference will be in what is written in between the quotes. You can change that to whatever you want displayed on the grub menu.

Also for whichever entries you want removed from the grub menu, just delete the corresponding menuentry blocks from the 40_custom file. Deleting a menuentry block means deleting the block starting from the words ‘menuentry’ till ‘}’.

Once you’ve done enough modifications, save the file and close it.

13. Now the terminal is staying in /etc/grub.d itself right? Run the following command from there.

sudo chmod -x /etc/grub.d/10_linux /etc/grub.d/20_memtest86+ /etc/grub.d/30_os-prober

14. Alright you’re almost ready to go. Just do one more thing.

sudo update-grub

15. Ah good. Restart your system and you will see your own grub. 🙂 Good luck. 🙂

For more detailed description (and a description that makes much more sense too), please visit

http://ubuntuforums.org/showthread.php?t=1195275

Thank you! 🙂