How to recover grub2 in Ubuntu 9.10, Karmic Koala

This is a common problem you will often face. Even though it was my first encounter with grub2 it wasn't as simple as I expected. May be its because things are handled a bit differently in grub2 as compared to the old grub. Anyways, in this article I will tell you how to recover grub2 when you have lost it after windows installation, got some error while installing linux or somehow messed it up while changing its configuration.

If you have a live CD, using it boot into a live session and follow the following steps (don't skip any unless you are know you are doing).

1) Open a terminal (Applications->accessories->terminal) and run this command

[ubuntu]$ sudo fdisk -l

2) The above command will list out the partition table of your hard disk. After identifying your linux installed partition. Run this command, I will use the partition as /dev/sda1 you will have to replace it with yours.

[ubuntu]$ sudo mount /dev/sda1 /mnt

3) If you have /boot on a different partition other then you need to mount it too. After identifying your /boot partition run this command (i am assuming it to be /dev/sda2)

[ubuntu]$ sudo mount /dev/sda2 /mnt/boot

4) Now, mount the rest of the devices

[ubuntu]$ sudo mount --bind /dev /mnt/dev/

5) Now, using chroot we will be allowed to run commands considering a specified root directory.

[ubuntu]$ sudo chroot /mnt

Now, we will be chrooted as root considering /mnt as the root directory. So, from now we won't need sudo to execute commands as root

6) If you need to make some changes to /etc/default/grub, open the file in your favourite editor ( i will use vim)

[root]$ vi /etc/default/grub

7) Make whatever changes you want to make and run update-grub to create the configuration file.

[shredder12]$ sudo update-grub

In case you don't want to use this command or the reader doesn't use Ubuntu then you can use this alternate command to update grub(this will the default command for all grub2 installations).

[root]$ grub-mkconfig -o /boot/grub/grub.cfg

8) If you want to install grub2 to MBR run this command.

[root]$ grub-install /dev/sda

If you want to install it to some partition then use that partition name instead of /dev/sda e.g. /dev/sda1 for the second partition etc. Or if you want to install grub2 on another drive then you may use that name e.g. /dev/sdb for an external hard disk. 

You will have to resolve the names using fdisk -l command. (be careful while doing that)

9) If you faced some error while installing grub2 then you may want to run it with --recheck attribute.

[root]$ grub-install --recheck /dev/sda

10) Once you are done with this either press Ctrl-D to exit chroot or type exit.

11) And then umount the partition you have mounted starting from /dev

[ubuntu]$ sudo umount /mnt/dev

[ubuntu]$ sudo umount /mnt

12 Comments

jippie (not verified)
November 20th, 2009 01:40 am
As a LVM user I had to edit the /boot/grub/grub.cfg file too! Every single occurence of: insmod ext2 I had to replace with insmod lvm insmod ext2 But I still have a kernel panic at boot time :(
November 20th, 2009 10:59 am

Hi Jippie,

I don't know much about LVM internals but i guess that grub is still not able to correctly map the partition/device with the filesystem. I found 2 bugs, not sure if they help to solve your problem but you may have a look at them.

https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/385428

https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/413345

I would still suggest you to post the problem on Ubuntu forums, if you haven't already done that and to help other users with similar problems you may post the link of the forum's post here.

 

Regards,

shredder12

retardus (not verified)
February 7th, 2010 04:55 am
duz we need to modify grub/devices.map?
February 8th, 2010 12:28 am

In trivial cases, like MBR overwritten by Windows boot loader on your main hard disk etc. you don't have to modify /grub/devices.map. My suggestion would be to try modifying this file only when you get a grub error stating you to do so.

March 3rd, 2010 07:10 am
I have just been able to recover grub2 in Ubuntu Karmic but it does not give the menu when it boots. Instead it drops into the grub> shell and then I must load the modules and boot. I had to reinstall win xp so after I was able to load and run Karmic I performed "sudo grub-install /dev/sda". I tried "grub-update" but got a message "grub-update: command not found". The response to a "grub-install --recheck" was: "alp910@alp910-desktop:~$ sudo grub-install --recheck /dev/sda [sudo] password for alp910: Installation finished. No error reported. This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (fd0) /dev/fd0 (hd0) /dev/sda (hd1) /dev/sdb (hd2) /dev/sdc" Do you have any idea what I should do to get grub to read the /boot/grub/grub.cfg?
March 3rd, 2010 12:35 pm

Hi alp36,

'grub-update' doesn't exist, you should use "sudo update-grub". This should fix the problem.

estabanarreando (not verified)
May 3rd, 2010 04:18 am
I tried to follow these because my grub is death steps but when I typed sudo mount --bind /dev /mnt/dev/ it mount answers thath the point /mnt/dev doesn't exist What can I do?
May 3rd, 2010 01:52 pm

Did you first mount your linux partition, step 2? If yes, then what do you see when you list all the files in /mnt ( promp$ ls /mnt)?

estabanarreando (not verified)
May 9th, 2010 02:08 am
Thank you very much but, I decided to reinstall ubuntu since I had barely anything to back up. Thank you anyway.
walleye (not verified)
June 3rd, 2010 10:10 pm
Thank you for the tutorial it helped me recover my system after deleting and resizing my swap and temp partitions on a second hard drive, system could not find read or find boot drive. After following your tutorial all is well, back up and running.
Дима (not verified)
June 10th, 2010 10:00 am
tnx
Hopf (not verified)
August 1st, 2010 06:32 pm
You should mount the /proc into the /mnt chroot directory before to chroot with : sudo mount --bind /proc /mnt/proc Otherwise, the grub-update won't work.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.