How To Backup an SD Card Image

Backing up an image for the Raspberry Pi, BeagleBone Black, OLinuXino, etc.

Let’s say you’re trying to build Linux for your single board computer, and you need to back up the operating system (which, more than likely, is on an SD card). With a relatively small SD card (say, 4GB), you can copy the whole card, zip it, and be able to store/share the image file. It also makes restoring pretty simple.

Backup Image

I recommend using Linux to copy and zip the file in one fell swoop. If you use gzip, people on Linux/Mac can unzip it pretty easily and Windows people can use 7-zip.

Plug in the SD card and issue the command

to figure out where the SD card is located (mine is /dev/mmcblk0). We will call this /dev/X from now on.

If Linux auto-mounted any of the partitions, make sure to unmount those.

Copy and compress the card to a location of your choosing.

That’s it! If something goes awry, restoring is easy.

Restore Image

In Linux, we can perform the opposite operation: unzip the image file and use dd to copy it directly to the SD card.

On Windows, it is a bit more tricky. You’ll want to first use a program like 7-Zip to unzip the image. Then, download Win32 Disk Imager, unzip it, and run the .exe (Note: you might have to run the Disk Imager utility under an administrative account).

In the Imager, select the sd_card_backup.img for the “Image File,” and select the drive letter of the SD Card (e.g. F:\). Click write.

And there you have it. Backing up and restoring image files isn’t too bad. It just takes some time as you have to wait for every bit to be read from or written to the card.

4 Responses

  1. If you add bs=4096 (or some other large power of 2) to your dd command, it will run a lot faster. I can’t remember the exact reason, but the hand-wavy reason is because it’s copying more stuff at once.
    So you would instead have:
    sudo dd if=/dev/X bs=4096 | gzip > /path/to/sd_card_backup.img.gz
    sudo gzip -dc /path/to/sd_card_backup.img.gz | sudo dd of=/dev/X bs=4096

    1. You can check the file browser to see if there is a new drive. Additionally, most versions of Debian (and probably some other distros, too) will auto-mount to /media. Do an > ls /media to see if there is something mounted there.

Leave a Reply