Friday, May 24, 2013

Grub Rescue on Ubuntu 12.04

OS: Ubuntu 12.04

I have two versions of Ubuntu installed on a low-end PC. I resized partitions and it finally messed up the grub settings and I finally ended up getting a grub rescue > prompt on reboot:


I could finally resolve it but still I am not sure if it is the right method. If you know a better method, please let me know.  I basically followed the instructions given here.


Step 1.  It is necessary to identify and locate the partitions where the boot images of your distribution is available.

grub rescue> ls
(hd0)  (hd0,msdos3) (hd0,msdos7)  (hd0, msdos2) (hd0,msdos1)

grub rescue> ls (hd0,msdos1)/boot
... grub .. initrd.img-3.2.0-43-generic-pae ... vmlinuz-3.2.0-43-generic-pae ...

This is the right partition where we would like the grub to boot into

Step 2. It is necessary to find "linux.mod" file which usually lies inside /boot/grub folder.  Do the following:

grub rescue> set prefix=(hd0,msdos1)/boot/grub
grub rescue> insmod (hd0,msdos1)/boot/grub/linux.mod
grub rescue> insmod part_msdos
grub rescue> insmod ext2
grub rescue> insmod gzio

Last two may or may not be necessary. At least I don't get any errors so far.

Step 3. Now its time to tell grub to find the boot images.

grub rescue> set root=(hd0,msdos1)
grub rescue> linux /boot/vmlinuz-3.2.0-43-generic-pae root=/dev/sda1 ro 
grub rescue> initrd /boot/initrd.img-3.2.0-43-generic-pae
no partition found 
grub rescue> boot

The initrd command does not work for me. However, the system boots properly and I get back the login page of my distribution.

Once I log into the system, I open a terminal and install the 'boot-repair' package as follows:

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair
 
I go for the 'recommended step' and everything gets into its place. When I reboot, I get 
the usual grub menu. If you have a live CD or Live USB, then you can boot into the system 
and install & run boot-repair as explained above to restore your grub. 
 


2 comments:

Unknown said...
This comment has been removed by the author.
Unknown said...

Perfect muy friend. The only method that really worked for me. It was hard to solve, but thanks to you I got it!!
I really appreciate your help.
Thank you