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
































6 Comments
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
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.
Hi alp36,
'grub-update' doesn't exist, you should use "sudo update-grub". This should fix the problem.
Post new comment