Friday January 4, 2008 02:26

Recover lost / corrupted GRUB (MBR) entry

Posted by shakir as Information Insemination





Often time the Master Boot Record (MBR) is also lost / corrupted when the we’re having problem with the partition table, and so here I extend my previous post on recovering lost partition table using the Ubuntu Live CD.

First of all, let’s mount the related stuff;

ubuntu@ubuntu:~$ sudo mount -o ro /dev/sda1 /media/
ubuntu@ubuntu:~$ sudo mount -o bind /dev/ /media/dev/
ubuntu@ubuntu:~$ sudo mount -o bind /proc/ /media/proc/

and then chroot

ubuntu@ubuntu:~$ sudo chroot /media/

Once we are in the chroot environment, run grub

bash:~# grub

Assuming you are installing grub on your first harddisk, and your root filesystem in the first partition of your first harddisk, your journey should be something like this;

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2
/boot/grub/grub.conf"... succeeded
Done.

grub> quit

Once you’re done with that, you might want to unmount whatever you have mounted before. Don’t forget to exit from the mount directory first;

ubuntu@ubuntu:~$ cd ..
ubuntu@ubuntu:~$ sudo umount /media/proc/
ubuntu@ubuntu:~$ sudo umount /media/dev/
ubuntu@ubuntu:~$ sudo umount /media

and then reboot to see if your problem is really fixed..





Tags: , ,



5 Responses to Recover lost / corrupted GRUB (MBR) entry

luke

January 28th, 2008 at 8:43 am

Your post just saved my a$$. Thanks!

Kevin

September 11th, 2008 at 10:08 am

Thanks! Fixed the mess WinXP made with my system.

Chris

October 26th, 2008 at 12:01 am

Thanks man, this really helped, one thing is you don’t specifically say to exit out of the chroot before you do the umount but i got it anyway

shakir

November 3rd, 2008 at 2:52 pm

Chris:
Thanks, I’ve updated the post.

Thorsten Stettin

February 23rd, 2009 at 2:31 pm

Hi,

you made my day!

Thank you.

My problem occurs when I tried to upgrade from grub to grub2 on ubuntu jaunty alpha4.

Best regards

Thorsten

Comment Form