Archive for October, 2009

Howto Fix MBR – fixmbr – Linux DD – partition table

October 14, 2009

I just spent an hour fixing up my partition table after I made the mistake of over writing all 512 bytes of my MBR.  I was trying to fix a GRUB error I got when I wiped my linux boot partition (I was in the process of installing Gentoo but hadn’t finished yet).  I’ve made this mistake a few times and thought I’d just confess my sins and perhaps I’ll remember next time :-) .

The MBR is the first block on the physical disk and contains TWO parts: the master boot code and the partition table.  I wanted to copy the standard windows boot code in there so I would be able to boot into Windows and get back to work.  I used a linux live-CD and something like:

dd if=/MBR_backup.dat of=/dev/sda count=1 bs=512

unfrotunately this replaced the partition table with some random one I had when I made the backup as well as replacing the GRUB boot code with the Windows code.  What I should have done was:

dd if=/MBR_backup.dat of=/dev/sda count=1 bs=446

so that the copy stops short of the partition table which starts at byte 446.

So, it’s a great idea to have a MBR backup handly but remember – don’t over write the last part of the block!  That’s where the partition table is kept.

Another way to restore the master boot code is to use the fixmbr command in the Windows recovery console (an option available on the install CD).  That does the same as the above DD command and is safer but that option was not available to me – I have a 320GB disk and the XP install CD can not recognise it unless I provide an updated disk controller driver.  The older ones can’t see disks that big.

I’m glad I got that off my chest…

The way I fixed it was to use the linux live CD and fdisk to re-create the first partition, starting at cylinder 1 and with a size just a bit bigger than I knew the partition to be.  The I could boot up into Windows and am currently making a backup.  Later, perhaps I’ll even be able to figure out where first partition ends and the next starts and recover the second partition as well.


Follow

Get every new post delivered to your Inbox.