Back up an SD card with macOS Terminal

A Raspberry Pi, digital camera, navigation systems and other devices use an SD card. In such cases, the SD card often contains the software, images or other information used by the device.

In some cases it may be useful to back up the SD card. If something goes wrong with the SD card, you can always restore the backup, whether or not on a new SD card.

Below you will find the instructions for backing up an SD card as well as the steps to restore a backup to an SD card.

Look up the SD card’s device ID

Before a backup of the SD card can be made, we need to find out what the device ID of the SD card is. Insert the SD card into your Mac and open the Terminal app (Apps â–¸ Utilities).

In the Terminal window, type the command below:

Copy
$ diskutil list

An overview of connected storage locations will now appear. You will find the SD card under ‘external, physical’. You can often recognize this by the “Windows_FAT_32” boot partition.

Back up an SD card with macOS Terminal

If you have multiple external disks, you can find the size of the storage medium under SIZE. In the example above, “/dev/disk6” is the device ID of the SD card. We will use this device ID further in this article as an example.

Make full SD card backup

If you have determined the device ID of the SD card, we can make a backup of the card. We do this using the ‘dd’ command (disk dupe). This command takes two parameters, ‘if’ (input file) and ‘or’ (output file). As if (input file) we enter the disk ID of the SD card, at ‘or’ you enter the file name (possibly a path) that the backup file should have.

Copy
$ sudo dd if=[device-id] of=[bestandsnaam]

If you want to make a backup of the SD card with device ID “/dev/disk6” and save it in the file sdkaartbackup.img, use the command below:

Copy
$ sudo dd if=/dev/disk6 of=sdkaartbackup.img

The backup will start after you enter your password, no visual feedback will be shown until the process is fully completed.

Depending on the size, speed and contents of the SD card, the backup process may take several tens of minutes (or longer). Also make sure that you have sufficient disk space at the location where the backup file is written.

SD card backup completed

After the backup is complete, you can safely unmount the SD card from your Mac from macOS Finder or with the command below:

Copy
$ diskutl unmountDisk [device-id]

[device-id] Here again, replace it with the disk ID that we found earlier with the diskutil list command. In our example we use the following command:

Copy
$ diskutil unmountDisk /dev/disk6

Restore SD card backup

To restore a backup to an SD card, we again use the ‘dd’ command under macOS Terminal. As ‘if’ (input file) you now use the file name of the backup, with ‘or’ the disk ID of the SD card.

It is wise to first unmount the volume, in the example below we again use ‘/dev/disk6’ as an example device ID of the SD card.

Copy
$ diskutil unmountDisk /dev/disk6

After this, we write the backup file ‘sdkaartbackup.img’ back to the SD card ‘/dev/disk6’ with the command:

Copy
$ sudo dd if=sdkaartbackup.img of=/dev/disk6

Once the backup is complete, you will need to safely unmount the SD card again as described above. You can now use the SD card containing the backup in the device again.

Recent Articles

Related Stories