Page 1 of 1

Master Boot Record

Posted: Wed Apr 01, 2009 5:46 pm
by AK Dave
Excellent article in April 2009 of Linux Journal (www.linuxjournal.com) on restoring the MBR.
Link for subscribers here: http://www.linuxjournal.com/article/10385
A few extracts:

Backup your MBR:

Code: Select all

sudo dd if=/dev/sda of=mbr_backup bs=512 count=1
Restore your MBR:

Code: Select all

sudo dd if=mbr_backup of=/dev/sda bs=512 count=1
Blank your MBR if you've buggered it up (EXTREMELY DANGEROUS COMMAND):

Code: Select all

sudo dd if=/dev/zero of=/dev/sda bs=512 count=1
Most of the article from there on has to do with use of and interpretation of results from 'gpart'. Not 'gparted', but 'gpart'. Short for "Guess Partition".

View the gpart version of your partition table:

Code: Select all

sudo gpart /dev/sda
Use gpart to write a new partition table (assuming you trust gpart):

Code: Select all

sudo gpart -W /dev/sda /dev/sda
Obviously the first step should be creating a good backup. Since it is simple to create a backup of your MBR, and simple to restore, it should be a no-brainer to do so. But fixing these sorts of problems requires being able to boot the computer from an alternate media source that will allow you to do this work. For this reason, I keep Knoppix on a thumbdrive. It has dd and gpart, as well as scads of other nifty tools. There is ample room on that Knoppix stick for backups of important files, like shared keys and MBR images. Never know when one of those might come in handy.

Destroying the MBR is something that could happen to anyone. Unfortunately.
Fixing the MBR should be well within the reach of anyone. Fortunately.

Re: Master Boot Record

Posted: Sun Apr 05, 2009 8:41 am
by Husse
Blank your MBR if you've buggered it up (EXTREMELY DANGEROUS COMMAND):
I cannot agree more - if you don't have a backup of your MBR or know the MBR by heart you've lost all content on that drive and need expert advice to get it back
Perhaps testdisk* can save you but I'm not sure
*You find testdisk in the repositories

Re: Master Boot Record

Posted: Tue Apr 07, 2009 2:25 am
by AK Dave
gpart can fix it if you've royally buggered it up.

You'll need to blank it (see above), then use gpart to whistle up a new one (see above).