Master Boot Record Oops

| No TrackBacks

One of my colleagues has a laptop that dual boots with Windows XP (R) and Ubuntu (Hardy Heron). He received a new laptop and wanted to move the partitions from the old hard drive to the new laptop's hard drive.

The data migration went well, and the laptop would boot straight into Windows, so we needed to install grub back to the master boot record (MBR). Naturally, we booted off the Hardy CD, and I figured we'd just reinstall Grub to the MBR straight from the Grub menu.

Now, this is quite straightforward. You simply boot from a livecd, mount the root and/or boot partition(s), chroot and drop to the grub shell. Finally, do something like:

grub> root (hd0,0)
root (hd0,0)

or

grub> find /boot/grub/stage1
find /boot/grub/stage1
 (hd0,0)
grub> setup (hd0)

However, we received:

grub> find /boot/grub/stage1
Error 15: File not found

Well, that's not good! I considered trying

# dd if=/boot/grub/stage1 of=/dev/sda count=1

but didn't have the courage to do it and looking back on it now it wouldn't have worked anyway. So instead I ignorantly copied the MBR from the other disk as it was supposed to be a clone and applied it to the new disk using dd of course.

The outcome WAS NOT PRETTY! Grub could not find any partition. In short, the file allocation tables were all wrong. Not to worry, we just loaded up Winternals ERD and ran a lengthy scan on the disk. I figured the $2345245 software would surely bail us out of this mess. Wrong!

The solution was this gem of an open source beauty. I loaded this on a USB stick, booted off the Heron livecd, and ran the binary it ships with. Within minutes it found the correct partitions and we were able to restore the MBR with the correct file allocation tables.

However, we were just back to square one and needed to install Grub to the MBR. We figured out that what done us over in the first place was the fact the Ubuntu partition was not the active partition. Easily fixable:

# fdisk /dev/sda 
... 
Command (m for help): a 
Partition number(1-5): 2 
... 

At this point we were able to boot back into the livecd and run grub correctly. Lesson learned -- just because you've done something numerous times that should be straightforward -- backup!


No TrackBacks

TrackBack URL: http://www.secnix.com/mt-cgi/mt-tb.cgi/2

About this Entry

This page contains a single entry by Justin published on August 21, 2008 3:53 PM.

2008 Olympics is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages