Logo
Published on

How to clone a Raspberry PI SD Card on nacOS

Authors
cover

Photo by Katarzyna Pe on Unsplash

How to clone a Raspberry PI SD Card on nacOS

Backup Raspberry Pi SD Card

  1. Using a USB or built-in card reader, insert the SD card into your Mac. Launch a Terminal application and type the command diskutil list. Try to determine your SD card's device ID. Mine, for instance, appears as /dev/disk4, its size is 32GB.
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:             Apple_APFS_ISC Container disk2         524.3 MB   disk0s1
   2:                 Apple_APFS Container disk3         994.7 GB   disk0s2
   3:        Apple_APFS_Recovery Container disk1         5.4 GB     disk0s3

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +994.7 GB   disk3
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            10.3 GB    disk3s1
   2:              APFS Snapshot com.apple.os.update-... 10.3 GB    disk3s1s1
   3:                APFS Volume Preboot                 6.2 GB     disk3s2
   4:                APFS Volume Recovery                939.1 MB   disk3s3
   5:                APFS Volume Data                    628.6 GB   disk3s5
   6:                APFS Volume VM                      7.5 GB     disk3s6

/dev/disk4 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.3 GB    disk4
   1:             Windows_FAT_32 system-boot             536.9 MB   disk4s1
   2:                      Linux                         30.7 GB    disk4s2
  1. Unmount the SD card
diskutil unmountDisk /dev/disk4

Replace disk4 with the device ID identified in step 1.

  1. Use the dd command to write the image to your hard disk
dd if=/dev/disk4 of=./raspberry_backup.img
# 61067264+0 records in
# 61067264+0 records out
# 31266439168 bytes transferred in 7700.384380 secs (4060374 bytes/sec)

The if parameter (input file) specifies the file to clone. In this case, it is /dev/disk4, which is my SD card’s device ID. Replace it with the device ID of yours. The of parameter (output file) specifies the file name to write to.

⚠️ Be careful, and double check the parameters before executing the dd command, as entering the wrong parameters here can potentially destroy the data on your disks.

Depending on the size of your SD card, it may take some time for you to see any output from the command until the cloning is finished.

💡 From another termincal, you can check the size of the file with ls -l raspberry_backup.img

After that, you may take the SD card out. When ready to restore the backed-up image, just follow to the guidelines provided below.

Restore Raspberry Pi SD Card

  1. Insert the new SD card in your Mac. Open a Terminal window, and unmount it using the following command:
diskutil unmountDisk /dev/disk4

Replace disk4 with the Device ID of your SD that you identified in step 1 on the previous section.

  1. Use the dd command to write the image file to the SD card
sudo dd if=./raspberry_backup.img of=/dev/disk4
# 61067264+0 records in
# 61067264+0 records out
# 31266439168 bytes transferred in 10118.822302 secs (3089929 bytes/sec)

This is essentially the opposite of the clone command we used. This time, the SD card device is the output file, and the backup image is the input file.

Make sure you check and double-check the parameters one more because putting the incorrect command here will result in permanent data loss.

You will receive an email from dd confirming the write. After that, you may take the card out of your Mac and put it back into the Raspberry Pi.

Same as in the previous section dd confirm only when wrting is done. Then remove the card from your Mac.

The cloning operation is done.