Mirroring partition table?

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.


Solution 1:

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.

Solution 2:

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.