Is there a way to do a sector level copy/clone from one hard drive to another?

Without going into distracting details, I'm attempting to duplicate the contents of the 500GB drive in my MacBook to another 500GB drive. But this is turning out to be an unexpected hassle because the drive contains both the OS X partition and an NTFS partition with Win 7 via Apple's Boot Camp.

With the exception of Clonezilla, the tools I have looked at so far all have some limitation. The Mac tools don't want to deal with the NTFS partition. The Windows tools are totally clueless about either the HFS+ partition and/or the hybrid MBR/GPT Boot Camp partitioning.

Clonezilla looked like it would do what I want but apparently I can't figure out how to use it. After doing what I thought was a sector to sector copy I found that only the NTFS partition had been migrated. The others were apparently empty. (And frankly, I'm not positive Clonezilla migrated the partition table correctly either).

Note: It takes over 2 hours using SATA to read/write all sectors with these drives. So I'm not up for using trial & error to narrow in on the right combination of Clonezilla options to use.

I'm beginning to think that maybe the answer is to boot Linux (probably Ubuntu) and then use some ancient BSD command. Trouble is I don't know what command (or parameters to use) in order to do a sector level copy from one drive to another. As far as I know the drives have the same number of sectors so this should be trivial. Sigh.


Yes, dd does work. (Phew!)

I especially appreciated the link in the answer to the corresponding question/exchange on serverfault.com as I never would have thought to look there.

Here are some additional tweaks I used after learning about them from the exchange on serverfault.

  • Don't use the default transfer size of 512 bytes. In my case I used the form
    dd if=/dev/sda of=/dev/sdb bs=8192
    since this significantly increased the data transfer rate. (It happened that the size of both my drives was a multiple of 8192. Not sure if that mattered, but it felt safer to do it that way).

  • There is a way to get some progress status from the dd command. Apparently dd displays its current transfer status when it receives the right signal. I used the method suggested in this serverfault answer. However, I used an interval of 120 seconds, not 10 as I didn't want to get "flooded" with progress info.

It took about 2 hours 20 minutes to completely clone my 500GB drive to another 500GB drive. The final status message from dd was
500107862016 bytes (500 GB) copied, 8353.86 s, 59.9 MB/s

What it lacks in terms of options this process certainly makes up for in simplicity and completeness. :-)


Solution 1:

In linux the dd command can do what you want.

https://serverfault.com/questions/4906/using-dd-for-disk-cloning

Just make sure not to clone the empty drive onto the drive you want to clone.

Solution 2:

If you want to it fast... then dd is not what you want. Why?

Because it is single-threaded. It means, it works on this way:

  1. reads a block from the source, waits until it is ready
  2. writes this block to the target, waits until ready
  3. goto 1

Actually, the writing and the reading of the next block could happen in the same time, but dd can't do that.

To do quick backups, you can use the buffer tool. Similarly to the dd, it works basically from standard input to standard output, so you can use it in a pipe, to make its two site really parallel working.

The parametrization which would you probably most like:

buffer -i /dev/sdX -o /dev/sdY -s 8192 -b 2048

It will clone /dev/sdX to /dev/sdY, quickly.

You can also use buffer to accelerate any piped shell command:

pipe-chain-commands1 | buffer -s 8192 -b 2048 | pipe-chain-commands2

This will result that the first chain should not wait until the second chain doesn't eat its output.