Backup MBR using dd

DD is being said to stand for "destroy disk" or "delete data", since, being used for low-level operations on hard disks, a small mistake, such as reversing the if and of parameters, may accidentally render the entire disk unusable.

But people who say these stuff are the ones who can't harness it's real power.
Messing around with unix and linux hard drivers and file systems is going to be a risky operation no matter what you do. Just take the chance and do it, don't look back, if it turns out to be alright your confidence will go through the roof.

The MBR is a 512 byte segment on the very first sector of your hard drive composed of three parts: 1) the boot code which is 446 bytes long, 2) the partition table which is 64 bytes long, and 3) the boot code signature which is 2 bytes long.

We will be using dd to back it up. (for a full list of dd's acceptable parameters type : man dd)

dd if=/dev/hda of=/mbr_backup bs=512 count=1
This is how you backup your MBR to a file /mbr_backup.

if (stands for from where should I cp)
of (stands for to where should I cp)
bs (how big should the segment that I cp be)
count (block count)

To restore it reverse the if and of parameters:
dd if=/dev/sda/mbr_backup of=/dev/hda bs=512 count=1

If you want to destroy the MBR but leave the partition table intact then simply change 512 to 446.

And now for the second part of this little tutorial, have you ever tried to install windows on a hard drive that has never seen a windows operating system in it's happy little life (only linux and unix like OS)?
Well if you did you might have noticed that usually the Windows installs fails to start, the solution here is to wipe out the mbr using the "dd" and the install should continue fine after that. This is the command for doing that:

dd if=/dev/zero of=/dev/hda bs=512 count=1
Again if you want to keep the partition table intact replace 512 with 446.

Happy Sysadmining!

Tags:

Comments