Clone Windows HD on Apple OSX machine

Last week, lightning struck at my parents apartment building (literaly). Other damages aside, my dad’s PC also died.

The guy at the PC repair shop warned my dad that “we may need to wipe the HD, do you have a backup”? Ofcourse, all data was backed up daily and “off-site” at my house so all important data was safe. But just in case, we wanted to make an exact disk image of the drive, so that we could easily restore it when the PC returns from the store

I wanted to have a future proof process, run on a Mac, something as follows:

  1. Make an image file of the complete source harddisk including all partitions (in our case there were 3 NTFS partitions on the disk). The image file includes any boot records or loaders if they exist, and is an Apple DMG file so it can be mounted on OSX.
  2. Store the image file on a server disk (so it in turn gets backed up)
  3. When there’s trouble, we now have 2 options, which are
    a) mount the image and restore 1 or 2 important files
    b) write/restore the image to a new disk

So we bought a second 500GB drive to play around with, and try the restores on.

With the Mac Disk Utility, I made an “MBR” disk image of a drive. Mounting this image gave me the access to all 3 NTFS partitions and data on them. However, for some strange reason, Disk Utility could not restore it’s own disk image to the drive,  because it does not allow me to drag the target disk into the target disk field (use google to find more people having this problem). Mucking around with the command line tool “dd”, I actually managed to restore the DMG back onto a physical drive, but for some reason, the primary partition was damaged.

Digging around on the internet, I found that the following method may be the only reliable way to do this and meet all my requirements. It’s relatively simple, although it does take a trip to the command line (which is really not very Apple like).

Backup the DRIVE, not a PARTITION

What Apple calls a “drive” or “disk” is actually often just a partition on a physical disk. A physical disk can have multiple partitions, which appear as multiple “disks” in the Finder or Disk Utility. Because we want to make an image of the physical disk, we need to find out where that disk is. In the Terminal, use to following command:

diskutil list

You’ll get a list of all the physical drives, and the partitions which are on there. For example, our testdisk shows up as follows:

/dev/disk3
   #:                   TYPE NAME      SIZE     IDENTIFIER
   0: FDisk_partition_scheme          *465.8 Gi disk3
   1:             DOS_FAT_32 TESTDISK  465.8 Gi disk3s1

The physical disk is known to the system as /dev/disk3, and the first (and only) pastition on there is a FAT32 partition, and the name of the partition is TESTDISK. To make a DMG of the complete disk with all it’s partitions, the following command is enough:

dd if=/dev/disk3 of=/Users/rolf/MyCompleteDisk100GB.dmg

The command will take a (long, long) while to complete. I’ve read some posts where people were waiting for days for dd to complete their image. There’s also no progress bar. Terrible, but for now I can’t help you with this without getting into rediculous trickery as found on some l33tsp34k hippie h4xor blogs out there.

The fun thing about this trick is, that OSX is able to mount that DMG file. You just double-click it, and “boom“. There are your partitions. A big problem is that these images are uncompressed. So you’ll need 500GB free space to backup a 500GB drive. That’s not funny. You can circumvent that by having the data zipped before writing it to disk but that means you’ll not be able to mount it.

Writing it in compressed form (which is even slower) can be done like so:

dd if=/dev/disk3 | gzip -9 > /Users/rolf/MyCompleteDisk100GB.dmg.gz

Restore the DRIVE (not the partition)

To restore a dmg onto a physical disk, get a disk which is at least the size as the original disk. Having the original disk’s size in the filename like in the example above helps you to remember that in a few months.

After checking which disk you need to write to with the diskutil (as shown abve), restoring an uncompressed disk image merely requires you to swap input and output parameters, like so:

dd if=/Users/rolf/MyCompleteDisk100GB.dmg of=/dev/disk3

Please note that this works because in my case I haven’t rebooted or reconnected drives, so the drive I need to write to is still /dev/disk3.

If you did the gzip compression trick mentioned above, you need to get a bit more fancy:

cat /Users/rolf/MyCompleteDisk100GB.dmg.gz | gzip -d | dd of=/dev/disk3

Although all of this works, I hope that somebody, somewhere can show me a simple, clean, OSX native, GIU based solution to this, meeting the 3 requirements in this article.

About these ads

18 Responses to Clone Windows HD on Apple OSX machine

  1. [...] that you forget to move stuff. So keep your old PC for another month or so, or even better: Make a disk image from the harddisk. You can now safely trash your PC (wipe that harddisk first) without having to [...]

  2. Sasha S. says:

    Excellent post!

    Big thanks to the author (bedankt!) for helping me upgrade disks on several of my Linux based devices. I started with NAS disk from LaCie (compression trick worked nice to get a few 10’s of MB image instead of 320GB of mostly empty space), then encouraged I went to upgrade internal hard disk (for TV recording) on my LOEWE Individual TV and soon I plan to do the same hard disk upgrade on my Apple TV (40GB -> 320GB).

    I could not finish the process in OSX alone – I also used UBUNTU live CD (works great on my iMac) to resize some of those partitions in order to use new larger drives.

    This was a first crucial step to get those exact structures from one disk to another. Thank you!

  3. drewsta says:

    great tips…

    when making the dd, you can list the folder where the .dmg is being created to watch the size of the Disk Image increase, at least you can see the progress that way…

    thanks!

  4. velvetandsilk says:

    Thanks for the helpfull article.

    You can open an other terminal window and issue:

    kill -SIGINFO “Process-ID of dd”

    The Process-ID of dd can be found in the Activity Monitor utility on macs.

    That will give you an overview of the bytes writen so far and will be written to the dd process Terminal window.

    See http://de.wikipedia.org/wiki/Dd_(Unix) (german)

  5. Chris Pierce says:

    easy way to get this done in a GUI from apple is to open up disk utility from the Utilities. Then click on the Drive (not the partition) and click New Image). After you’ve saved it somewhere on your computer you can restore it to another drive by clicking on that drive and clicking restore. Select the image and the destination will be the new drive. This does have a progress bar and seems to move a lot faster than using dd by itself. The other nice thing is you don’t have to guess at the disks or using diskutil list to find what drive /dev device you have.

  6. Kevin Smith says:

    Very helpful!!! Going to repost this with a link back to
    your page. Thanks also to “velvetandsilk” that was nice to see
    progress. My Testing: Mac OS X 10.6.5 250GB sata to USB connected
    (the problem drive) 320GB usb WD passport (backup
    location)

  7. Dude says:

    A couple of hints:

    use bs=16k for the dd command, so that it uses big chunks during copy, therefore is much faster (ex: dd if=/dev/disk0 of=/Volumes/backup/disk0.raw bs=16k)

    Simpler way to kill dd: killall dd

    Last but not least: for the (usually) best compression-to-time ratio I recommend gzip -2 or -3 ( ex: gzip -3 file.txt or gzip -3 -c file.txt >file.txt.gz )

    Cheers!

  8. Dude says:

    Also: you might be able to get around the Disk Utility issues with ar (Apple’s recovery tool), which I think comes with the dev tools. I forget right now.

  9. Moon47 says:

    Is there anything comparable to dd that does NOT copy unused blocks… ??

    IE i want to copy a 160gb drive with Windowns 7 partitions over to a smaller 120gb drive so i can use the larger drive for something else… !!

  10. Moon47 says:

    Edit… My windows drive only uses 10gb of the 160gb so without the unused blocks there should be no problem… =]

  11. Rooster says:

    Thanks for the helpful tips. I use dd-gui as a gui front end for the dd utility. It can duplicate a whole drive to another. It gives a progress indicator which is helpful. As you noted, the process can take a very long time. http://www.gingerbeardman.com/dd-gui/

    I’ve had good luck with cloning an entire HD containing multiple partitions.

    My next project is to clone a drive containing a Windows XP bootcamp partition to a new drive. Not sure how that will work as far as creating a bootable XP partition.

  12. christian says:

    couldnt the dmg be a sparce image?

  13. Nick says:

    Everytime I double click on the dmg my computer reboots.
    I am using mountain lion & cloned a windows drive that I took out of a laptop & placed it into a usb enclosure.
    Cloning to another external hfs drive.
    Size of dmg & hard drive are the same.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 30 other followers