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:
- 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.
- Store the image file on a server disk (so it in turn gets backed up)
- 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:
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.