Creating an image of an SD card

It is possible to create an disk image of a block device such as a hard drive, USB stick or SD card. This can be handy for simple backups or creating clones of disks.

Firstly connect any removable media to the Mac, then open a terminal and use the diskutil command to list the current partitions available as follows:

diskutil list

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI ⁨EFI⁩                     209.7 MB   disk0s1
   2:                 Apple_APFS ⁨Container disk1⁩         121.0 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +121.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume ⁨Macintosh HD - Data⁩     84.2 GB    disk1s1
   2:                APFS Volume ⁨Preboot⁩                 543.6 MB   disk1s2
   3:                APFS Volume ⁨Recovery⁩                1.1 GB     disk1s3
   4:                APFS Volume ⁨VM⁩                      4.3 GB     disk1s4
   5:                APFS Volume ⁨Macintosh HD⁩            15.4 GB    disk1s5
   6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 15.4 GB    disk1s5s1

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.8 GB    disk2
   1:             Windows_FAT_32 ⁨boot⁩                    268.4 MB   disk2s1
   2:                      Linux ⁨⁩                        15.6 GB    disk2s2

All of the block devices connected to the system will be shown. In example above /dev/disk2 is a 16Gb SD card we wish to create an image for.

The disk image file size will equal the size of the source disk so ensure that there is enough disk space available for the image.

Its recommended to compress the resulting image to save space, in the example below we will use gzip with maximum compression enabled.

We will be using the dd command to directly access the source block device, this functionality does require admin privileges. Either login as an administrator or use sudo to give dd more privileges just for this specific command line.

sudo dd bs=4M if=/dev/disk2 status=progress | gzip -9 -c > /tmp/usb_image.img.gz

In the example above we are stating two important options for the dd command, the first which is the bs or block size, different values can be used here to increase the imaging speed but the optimum block size will vary depending on the system and drive being imaged.

We then use the if or input file parameter to specify the block device to be imaged.

Note that we do not specify an output file or of parameter, this will cause the block device's data to be sent to STDOUT which we then pipe into the gzip command for it to be compressed. We then also do not specify an output file for this command and redirect it's output to a file with the arrow syntax.

A .gz file extension is used to show that the image is compressed. And use the .img extension to ensure that imaging tools are automatically associated with the file.

The resulting file can be used to restore data back to a device using dd command or other popular imaging tools.

Last updated: 19/04/2025