UNIX / Linux: copy master boot record (MBR)

by Vivek Gite · 6 comments

Q. How do I copy MBR from one hard disk to another hard disk under Debian Linux? I need to do this because of RAID 1 configuration.

A. To copy MBR simply use dd command. dd command works under all Linux distros and other UNIX like oses.

dd command to copy MBR

Type dd command as follows:
dd if=/dev/sda of=/dev/sdb bs=512 count=1

Above command will copy 512 bytes (MBR) from sda to sdb disk.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 6 comments… read them below or add one }

1 caiken 12.21.07 at 10:02 pm

This is correct for EXACTLY the same partition sizes. In the case you want the MBR only on a drive that has a root partition of a different size then issue the same command with a smaller block size.

dd if=/dev/sda of=/dev/sdb bs=446 count=1

Thus preserving the partitioning schema.

2 graysky 10.31.09 at 2:11 pm

Right… be VERY careful with doing this w/ two discs with different size partitions! In fact, the safest way to backup/restore JUST THE MBR:

dd if=/dev/sda of=mbrbackup bs=512 count=1

To restore the MBR (on to the same drive or any drive):

dd if=mbrbackup of=/dev/sdb bs=446 count=1

3 graysky 10.31.09 at 2:14 pm

Caiken is right! BEWARE of using the above dd line on two discs that don’t have IDENTICALLY sized partitions! You will lose data!

Here’s what I do to copy just the MBR from a hdd:

dd if=/dev/sda of=mbrbackup bs=512 count=1

Now to restore the image to any hdd:

dd if=mbrbackup of=/dev/sdb bs=446 count=1

4 Sicarius 11.11.09 at 9:15 pm

Thanks a lot, this was just the kind of short note I was looking for ,)

5 Brandon 11.27.09 at 12:33 am

MBR is 512 or 446 bytes?

6 Bolo 12.21.09 at 8:57 pm

MBR is divided into 3 sections
1. Bootstrap . 446 bytes
2. Partition table. 64 bytes
3. Signature. 2 bytes

Leave a Comment

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

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All