Backing up portable things like SD cards and USB flash drives on Linux is easier than it sounds, and it can happen right from the terminal, using the DD copy and convert tool. DD is truly versatile, and with it, users can copy large amounts of data from one place to another. Suffice it to say; the DD tool has many uses. One of it’s best uses is backing up data storage. On Addictivetips in the past, we’ve used this method to make copies of hard drives. It can also be used to back up SD cards and flash drives. Here’s how it works.

Back Up SD cards And Flash Drives

To start off, open up a terminal window and plug in the SD card/USB you’re trying to backup. Use the lsblk command to print, all available devices on the system.

Keep in mind that SD cards will not follow the generic /dev/sdX structure, especially if you’re using a built-in memory card reader. Instead, you should see /dev/mmcblk, followed by partition information.

Note: Backing up a USB should follow the traditional /dev/sdX naming scheme.

Your SD card may not show up as /dev/mmcblk (or similar) if you are using a USB adapter. The device label name all depends on how the SD card adapter works with Linux. It is best to read your adapter’s manual.

Once you’ve figured out the label, you’ll need to figure out exactly how you’re trying to backup. Choose the method below that fits your use-case.

if (navigator.appVersion.indexOf(“Mac”)!=-1) document.write(”);


Backing Up Image File

The first method of backup with DD is using it to save everything to a simple image file. To do this, you’ll need to enter the following command. Keep in mind that the imaging process will take a long time, especially if you have a large SD card or USB stick.

USB Flash Drives

sudo dd if=/dev/sdX of=~/image-of-usb.img

Running this command will take a complete copy of the USB drive and save it to a file named image-of-usb.img. Take this image file and back it up somewhere safe. If you’d like increased security, follow the steps below to encrypt it with GnuPG.

gpg -c image-of-usb.img

The output of GnuPG should be image-of-usb.img.gpg.

Once the encryption process completes, delete the original file and keep the encrypted one.

rm image-of-usb.img

Extract the image from the encrypted file at any time with:

gpg image-of-usb.img.gpg

SD Cards

Note: 0 means SD 1.

sudo dd if=/dev/mmcblk0 of=~/image-of-sd-card.img

Running this DD command will take a snapshot of your SD card, and save it to a file on your file system labeled image-of-sd-card.img. You’ll be able to move this archive image, upload it to Dropbox, Google Drive, a home server, etc. Keep in mind that this archive is not secure and sensitive data can easily be accessed if someone gets their hands on it. That’s why we recommend you also encrypt your SD backup with GnuPG.

To encrypt, run this command:

gpg -c image-of-sd-card.img

Encrypting should output a file with the label of image-of-sd-card.img.gpg

You should remove the original, source file when the encryption finishes.

rm image-of-sd-card.img

To extract the encrypted archive, rerun gpg, without -c.

gpg image-of-sd-card.img.gpg

Duplicate USB And SD Cards

If you’d rather create a duplicate of the SD card, rather than back everything up to an image, follow these instructions. The first step is to plug in both the SD/USB you want to back up, as well as the second SD/USB you’ll use as the receiver of the duplication. Then, use the lsblk command to list the devices. Find all the device labels and make a note of them.

For example, to duplicate SD card 1 to SD card 2, I would need to use /dev/mmcblk0 and /dev/mmcblk1. Once again, refer to lsblk –help if needed.

When you’ve figured out the correct labels, follow the instructions below.

USB Flash Drives

The command we used earlier to save a USB to an image can work in this situation. The only thing that changes is the “of=” aspect of the command. Rather than having it output to of=~/image-of-usb.img, we’ll have it output to the second USB flash drive.

In this example, USB flash drive #1 is /dev/sdc and USB flash drive #2 is /dev/sdd. Yours may differ.

sudo dd if=/dev/sdc of=/dev/sdd

When DD completes, all of the data from drive #1 should be present on drive #2!

SD Cards

Like the USB section, DD will take the data from SD card #1, duplicate it and place it on SD card #2. Write out this command in the terminal to start the duplication process. In this example, SD card #1 will be /dev/mmcblk0 and #2 will be /dev/mmcblk1.

sudo dd if=/dev/mmcblk0 of=/dev/mmcblk1

You’ll know the process is complete when the terminal can accept text from the keyboard again.

Restoring Backups

The quickest way to restore a DD backup image to an SD card or USB flash drive is to flash it with the Etcher tool simply. Using this tool for restoring data might sound a bit weird, as Etcher is mainly for burning OS images, but it works very well!

Start off by downloading the latest version of the Etcher flash tool for Linux, open it up and insert your USB flash drive or SD card.

Inside the Etcher program, click “Select image” to bring up the image selection window. In this window, browse for image-of-sd-card.img or image-of-usb.img and select it. When the image is loaded up, click “Flash” and let the restoring begin!

When Etcher shows the end-screen window, your data should be on the device.

Leave a comment

  • Pingback: How To Back Up SD cards And Flash Drives On Linux With DD | SkyNet Chronicles()