Mike's PBX Cookbook

Disk Cloning with DD

How to clone a hard disk or USB stick using the MacOS terminal

dd (disk duplication) is a MacOS command-line utility which can read raw data off a disk, even if the Mac doesn't understand the filesystem. There's also a freeware version of dd for Windows available, with instructions.

USB_SATA

It's as simple as:

dd if=<source> of=<destination> bs=<n> <options>

dd arguments:

If the operation stops with an I/O error, try to salvage all readable data with conv=noerror,sync
This option can often recover a dead hard drive, or an unreadable file, but it does not repair the error.

Make a working copy of a Signalling Server hard disk

If the installation has primary and backup signalling servers, clone one at a time to avoid service interruption.

Open Terminal and try this:

1. Attach and identify the source disk ⇒diskutil list
2. Unmount the source disk ⇒diskutil unmountDisk /dev/disk2
3. Copy the source disk to the desktop ⇒sudo dd if=/dev/disk2 of=/Users/mike/diskimage.img
4. Attach and identify the destination disk ⇒ diskutil list
5. Unmount the destination disk ⇒diskutil unmountDisk /dev/disk2
6. Copy the image to the destination disk ⇒sudo dd of=/dev/disk2 if=/Users/mike/diskimage.img

The second dd command is almost the same, but if and of are reversed. BECAREFUL!

If the copy fails due to disk errors, try using the following command at step 3:

dd if=/dev/disk2 of=/Users/mike/diskimage.img conv=noerror,sync

dd will take much longer using this option, errors are written as NUL bytes. chkdsk it.

Notes:

You can use this procedure with any drive: eg, to clone an MGC Compact Flash from one with a known password.

Example:

Attach the SOURCE disk...
If the following warning appears, click Ignore:

Disk Not Readable box

Open Terminal, identify the disk and unmount it:

$ diskutil list                                    ⇐ list attached disks and partitions

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *120.0 GB   disk2
   1:                      Linux                         100.0 MB   disk2s1
   2:                      Linux                         18.0 GB    disk2s2
   3:                 Linux_Swap                         4.1 GB     disk2s3
   4:                      Linux                         35.6 GB    disk2s5
   5:                      Linux                         18.9 GB    disk2s6
   6:                      Linux                         12.6 GB    disk2s7
   7:                      Linux                         12.6 GB    disk2s8
   8:                      Linux                         8.6 GB     disk2s9
   9:                      Linux                         6.3 GB     disk2s10
  10:                      Linux                         2.1 GB     disk2s11

$ diskutil unmountDisk /dev/disk2                  ⇐ unmount the source disk
Unmount of all volumes on disk2 was successful

Now we can make an image with dd.
This will take a long time, and there is no progress bar. You also need enough local disk space for the image.
Or, if you can concurrently attach both disks, copy directly: sudo dd if=/dev/disk2 of=/dev/disk3 bs=64k

$ sudo dd if=/dev/disk2 of=/Users/mike/diskimage.img bs=64k     ⇐ create an image file
Password:
1831680+0 records in
1831680+0 records out
120040980480 bytes transferred in 5906.100320 secs (20324914 bytes/sec)

Switch disks, and copy the image to it. Here, it also mounts as /dev/disk2
The dd command is almost the same, but if and of are reversed. BECAREFUL!

$ diskutil list

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                                                   *120.0 GB   disk2

$ diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
$ sudo dd of=/dev/disk2 if=/Users/mike/diskimage.img bs=64k     ⇐ copy image to disk
Password:
1831680+0 records in
1831680+0 records out
120040980480 bytes transferred in 3474.585549 secs (34548287 bytes/sec)

If you can attach both drives, copy directly from one to the other.
Attach one at a time, and use diskutil list to identify each device name.

$ sudo dd if=/dev/disk2 of=/dev/disk3 bs=64k                    ⇐ copy disk2 to disk3
Password:
61184+0 records in
61184+0 records out
4009754624 bytes transferred in 836.553549 secs (4793183 bytes/sec)
$ diskutil unmountDisk /dev/disk2                               ⇐ unmount both drives
Unmount of all volumes on disk2 was successful                    before removing
$ diskutil unmountDisk /dev/disk3
Unmount of all volumes on disk3 was successful

Always diskutil unmountDisk /dev/disk... before removing.