I would like to mirror one drive's partition table, that is, have exactly the same partition on both sda and sdb. I have heard that one of the fdisk utilities can export a partition table into a file, and that file can be read back into another drive, but I can't seem to find this in the manuals.

Can someone help?

To summarize: I want to have the exact same partitions on both drives, same labels, same filesystem types, and same sizes. The data on the drive does not matter, I just want the partition table.

sfdisk -d /dev/sda | sfdisk -f /dev/sdb

sfdisk -d dumps the partition table and throws it to stdout. This is being piped to sfdisk /dev/sdb with the --force, and so being written to /dev/sdb.

  • 1
    +1 For actually providing a - dangerous - solution :) – wzzrd Aug 17 '09 at 12:51
  • hmm. I think it's less dangerous dd'ing the MBR. :) I've used this method lots of times, just made one partition table, copied it and put everything into separate raid1's. :) – blauwblaatje Aug 17 '09 at 14:44

You can use dd to copy the Master Boot Record (MBR) from one device to another (or to a file). For example, copying the MBR from sda to sdb would be done with

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

The flags are

  • if, input file (either device or ordinary file)
  • of, output file (either device or ordinary file)
  • bs, block size in bytes
  • count, number of blocks to copy.

The MBR contains the partition table for the four primary partitions, so this solution alone will not copy the definition for the extended partitions.

Wikipedia has good articles describing master boot records and extended boot records, explaining their relation to each other and their disk format.

Note: This solution is possibly only valid for MS-DOS, Microsoft Windows and Linux on PC compatible systems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.