Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted
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.

share|improve this answer
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
    
Thank you, that is what I was looking for! –  K. Norbert Aug 17 '09 at 18:49
add comment

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.

share|improve this answer
    
Thank you for the explanation. –  K. Norbert Aug 17 '09 at 18:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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