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

ls /dev

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.

sudo dd if=/dev/X | gzip > /path/to/sd_card_backup.img.gz

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.

sudo gzip -dc /path/to/sd_card_backup.img.gz | sudo dd of=/dev/X

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 thoughts on “How To Backup an SD Card Image

  1. Sompom on June 25, 2014 at 8:15 pm Reply

    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. ShawnHymel on June 25, 2014 at 10:40 pm Reply

      I know it has to do with setting the block size (how much stuff is copied at once). Good to know. Thanks!

  2. Mark R on October 20, 2015 at 9:39 pm Reply

    How do I know if Linux has auto-mounted any of the partitions? What do they display as?

    1. ShawnHymel on October 21, 2015 at 3:20 pm Reply

      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 Comment

Your email address will not be published. Marked fields are required.