Clone Raspberry Pi SD Card Image Using dd on Mac OS

If your Raspberry Pi is running then shutdown the OS to protect the SD card disk image as follows:

sudo shutdown -h now

The green light on the Raspberry Pi will not be illuminated after the Raspberry Pi fully powers off. Once the green light is off then it is safe to remove the SD card from the Raspberry Pi.

Insert your SD card into an SD card reader and locate the device path for your SD card:

df
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1 1951825920 1344682872 606631048 69% 2398791 4292568488 0% /
devfs 401 401 0 100% 694 0 100% /dev
map -hosts 0 0 0 100% 0 0 100% /net
map auto_home 0 0 0 100% 0 0 100% /home
/dev/disk2s2 9728205344 6114898176 3613307168 63% 13935184 4281032095 0% /Volumes/archive
/dev/disk2s3 1991904392 790614920 1201289472 40% 1570576 4293396703 0% /Volumes/calvin
/dev/disk3s1 62309376 5120 62304256 1% 0 0 100% /Volumes/NO NAME

In this example the SD Card is /dev/disk3 and the disk partition or slide is s1. This can be identified because it has "NO NAME" as the name. Most SD cards are delivered new with "NO NAME". Usually the SD card will have the highest disk ID. The most important thing to note is the mount points such as "/", "/Volumes/archive", "/Volumes/calvin".

diskutil list

/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_CoreStorage Macintosh HD 999.7 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3

/dev/disk1 (internal, virtual):
#: TYPE NAME SIZE IDENTIFIER
0: Apple_HFS Macintosh HD +999.3 GB disk1
Logical Volume on disk0s2
895CB7FC-D9BB-4BD7-921E-CA6D4BFAF2FA
Unencrypted

/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *6.0 TB disk2
1: EFI EFI 209.7 MB disk2s1
2: Apple_HFS archive 5.0 TB disk2s2
3: Apple_HFS calvin 1.0 TB disk2s3

/dev/disk3 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *31.9 GB disk3
1: Windows_FAT_32 NO NAME 31.9 GB disk3s1

In this example the SD Card is /dev/disk3 and can be identified because it has Windows_FAT_32 type and "NO NAME" as the name.

Load the current date and time into a timestamp variable:

timestamp=`date +%Y%m%d_%H%M%S`

Create an SD card disk image backup:

Replace # in this command with the disk id of your SD card such as if=/dev/disk3

sudo dd bs=4096 if=/dev/disk# of=pi_backup_${timestamp}.dmg
7593984+0 records in
7593984+0 records out
31104958464 bytes transferred in 9013.851196 secs (3450796 bytes/sec)

Note This operation takes about 2.5 hours on my Mac. The default block size on Mac OS is 512 and bs=4096 speeds things up a bit. I have seen discussion on forums that indicates that block size of 131072 (128K) may be fastest.

Remove the SD card that you backed up and insert the SD card that you want to clone to.

Locate the device path for the new SD card. The device ID will probably be the same as it was when you performed the backup above but verify:

diskutil list

DANGER: Be VERY CAREFUL not to unmount or overwrite one of your other disk devices!

Replace # in these commands with the disk id of your SD card such as if=/dev/disk3

diskutil unmountDisk /dev/disk#
Unmount of all volumes on disk3 was successful

Format the new SD card with a FAT16 filesystem.

sudo newfs_msdos -F 16 /dev/disk#

Restore the SD card disk image from the backup

sudo dd bs=4096 if=pi_backup_file.dmg of=/dev/disk#
7593984+0 records in
7593984+0 records out
31104958464 bytes transferred in 9013.851196 secs (3450796 bytes/sec)
Note: this takes about 2.5 hours on my mac.

Eject the SD card because it will have been automatically mounted after the copy completes.

diskutil unmountDisk /dev/disk#
Unmount of all volumes on disk3 was successful

Now place this SD card into a Raspberry Pi and it should boot up from the a cloned disk image.