For dd, follow these following steps. But before you do so, I need to write this:
DISCLAIMER These instructions contain examples of device names that are specific to my situation. Do not copy and paste and command and execute them without making sure that your Mac is using the same device names. Failing to do so may overwrite the contents of a disk unintentionally and it will be impossible to revert. Proceed with caution and make sure to follow all steps and replace any device in the command examples with the ones used on your Mac!!!
First thing to do is to see what OS device the BOOT partition is on. This can be done with
In my case it shows that the SD card is the /dev/disk2 device. When the SD card gets connected to the Mac, the BOOT partition gets mounted automatically and this needs to be unmounted for dd to work properly. You can see all mounted devices with
In my case I see
/dev/disk2s1 on /Volumes/BOOT (msdos, local, nodev, nosuid, noowners)
so I need to unmount that. This is how to do that
diskutil umount /Volumes/BOOT
Issuing the mount command again, you can see that the partition was unmounted. Now you can create a backup. The dd command requires root privileges and the general command structure is
dd if=<source> of=<target> bs=<bs>
Source is where you want to copy the data from and target where to. bs is the block size. If you want to back up the SD card then source is the SD card device and target a file. If you want to restore the SD card then source is the file and target the SD card device. The block size specifies how many bytes get read from source and written to target at the same time. for MacOS and SD cards a sensible block size is 4 megabytes which is specified as 4m.
Now here's a little trick. MacOS has two layers of devices. The first layer we just saw when we checked what OS device was assigned to the SD card. However, MacOS also knows about raw devices and using dd with the raw device is MUCH faster. The raw device corresponding to an OS device has exactly the same name prepended with an r. So in my case the SD card was assigned to /dev/disk2 and therefore the raw device is /dev/rdisk2. Knowing this it is easy to backup the SD card. The command (in my case) is
sudo dd if=/dev/rdisk2 of=2021-05-09_asiar-backup.img bs=4m
This will back up the full contents of the SD card to a file called 2021-05-09_asiar-backup.img which gets created in the directory where the dd command gets issued. You are of course free to choose whatever filename you wish.
Once done, do not simply pull the SD card out of the Mac. The SD card partitions still are known to MacOS and need to be ejected first. So first issue
diskutil eject /dev/disk2
and you should be good. If you want to make sure that the partitions indeed have been ejected, you can issue
If you want to restore a backup, you can follow exactly the same steps but you need to swap the source and target. So the dd command then becomes
sudo dd if=2021-05-09_asiar-backup.img of=/dev/rdisk2 bs=4m
Note that after restoring the SD card, MacOS will mount the BOOT partition again. It is not necessary to first unmount the BOOT partition and you can eject the device because that will take care of unmounting as well.
Please let me know if you have any questions regarding the use of dd.