Backup & Restore the Master Boot Record

Some days ago I had to recover the Master Boot Record (MBR) of a damaged hard disk.

The MBR is the first 512 bytes of a storage device. It contains an operating system boot loader and the storage device’s partition table.

If you need to make a backup of the MBR type the following command:

dd if=/dev/sda of=/root/mbr.img bs=1 count=512

You only have to change sda with the device name that correponds to your hard disk.

To restore it:

dd if=/root/mbr.img of=/dev/sda bs=1 count=512

And as before, change sda with the device name that corresponds to the hard disk you are going to restore the MBR to.

The partition table has a size of 64 bytes and it starts at position 0x01BE (446) so if you want to only restore it:

dd if=/temp/mbr.img of=/dev/sda skip=446 seek=446 bs=1 count=64

It may come in handy when you mess with the partition table. Yes, that moment where you press w in fdisk and immediately regret it ;)

For more information the Wikipedia MBR article is very detailed.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields