⌚ Time to complete: 15 min

Planned outcomes

You will have a backup file containing all data from the original SD card you copied. Also, you will be able to restore this backup to any other SD card of similar or greater capacity.

Prerequisites

To perform this guide, you need access to a Linux machine where you can plug in your SD card.

Steps

Creating a backup

  1. Connect SD card to the machine.

  2. Find the name of your SD card storage device:

    1. List all storage devices using the following command:

      sudo fdisk -l
      

      If on Mac, use this command:

      diskutil list
      
    2. In the output, you will see a long list of devices ending with similar entries:

      Device     Boot Start     End Sectors  Size Id Type
      /dev/sdc1  *       63   80324   80262 39,2M  6 FAT16
      /dev/sdc2       80325 3903794 3823470  1,8G  b W95 FAT32
      

      Here, you can see the SD card mounted at /dev/sdc with two partitions (/dev/sdc1 and /dev/sdc2). Remember the base name (e.g. /dev/sdc) - you will use it in the next step.

      <aside> 💡 Your device may be named differently, but the general naming logic stays the same. Partitions can be numbers appended to the device’s name (i.e. 1, 2) or also have letter “p” (i.e. p1, p2).

      </aside>

      <aside> 💡 If you struggle to identify your device in the list, disconnect the SD card, run sudo fdisk -l again and check which device is missing from the list now. This will be your card.

      </aside>

  3. Save device and backup file paths to the variables:

    DEVICE_NAME=/dev/sdc
    BACKUP_IMAGE_PATH=~/sd_card_backup.img
    

    <aside> 💡 Change the device and output file name according to your use case.

    </aside>

  4. Create the backup using the following command:

    sudo dd if=${DEVICE_NAME} of=${BACKUP_IMAGE_PATH} bs=1M status=progress
    

    <aside> 💡 This will take multiple minutes depending on the size of the SD card and its speed.

    </aside>

  5. Done! 🎉

Restoring from the backup

  1. Connect SD card to the machine.

  2. Find the name of your SD card device (see Step 2 above).

  3. Save device and backup file paths to the variables:

    DEVICE_NAME=/dev/sdc
    BACKUP_IMAGE_PATH=~/sd_card_backup.img
    

    <aside> 💡 Change the device and output file name according to your use case.

    </aside>

  4. Restore the backup using the following command:

    sudo dd if=${BACKUP_IMAGE_PATH} of=${DEVICE_NAME} bs=1M status=progress
    

    <aside> 💡 This will take multiple minutes depending on the size of the SD card and its speed.

    </aside>

    <aside> 💡 In case you are getting dd: <disk_name>: Resource busy error when running this on Mac, follow this Stackoverflow answer.

    </aside>

  5. Done! 🎉

Notes

This guide is based on the following Stackoverflow answer: