Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What's the fastest way in Linux, using free tools, to duplicate a mostly disk onto another identical disk? In this case, SD cards, but I think the same would apply to USB drives, HDDs, etc.

I have a 512MB drive, with only about 10 MB of data on it. I would like to be able to make an exact, byte-for-byte duplicate like you would get if you just do dd if=/dev/source of=/dev/dest, however, I would like something that is aware of the file system on the source drive enough to know that it only needs to copy a very small portion of the disk.

Yes, I know I could string together sfdisk, mkfs and tar. But what I'm really looking for is a one-liner for creating an image, and another oneliner for writing it to disk.

EDIT: I need a tool that works with FAT16. ntfsclone seems to do approximately what I'm looking for, except NTFS-only.

EDIT #2: partimage looks promising in that it is incredibly fast, but it doesn't handle cloning the partition table.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

it depends on your filesystem and their size, and whether your data is in the beginning of the disk. because you can use bs and count (maybe also skip) in dd only to duplicate the data portion if you know where the data is. then you would have to resize your filesystem if the resulting filesystem is different.

or you can preshrink your partition only to include the data portion, and then do a dd until the partition is duplicated, again, making use of dd options as above. if your data is sparsely and randomly distributed, then it will not work.

is there any reason to do that? rsync or cpio should work better if you just want to duplicate data.

share|improve this answer
    
I mentioned both the sizes and file systems involved in my question. The reason is that I need to wipe out whatever partition and filesystem might already be on the disks and replace it with an exact duplicate. –  Brian McFarland Apr 12 '12 at 20:53
1  
the empty space mentioned above can be filled with /dev/zero. this avoid reading empty space in the original, but typically write is the slow operation so i don't think it would save much time. typically sfdisk + partimage would be your best bet. if it is a bootable one you need to copy the boot sector as well. –  johnshen64 Apr 12 '12 at 21:53
    
Ultimately sfdisk + partimage does the trick. Just took me a while longer than it should have to realize sfdisk -d can be used to generate the input to sfdisk for formatting the new disks. I accepted this since the answer is in the comments. –  Brian McFarland Apr 12 '12 at 22:01

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.