Raspberry Pi uses SD-cards to as their root filesystem. Unfortunately SD-cards are not the most trustworthy medium of data storage and lower class cards’ filesystems have tendencies to get corrupted.

Fortunately, it’s very easy to make image-files out of SD-cards. Image files are handy, since they store the whole system as is with configurations and applications installed. In this post I will explain how I do a image file out of your Raspberry Pi SD-card. First, you need to locate device-name of your SD-card.

On a Mac you would do this using Disk Utility, selecting the SD-card and the selecting Info. A device name point listed among the information.

Alternatively you could run the following command in Terminal:

diskutil list

On a Linux-based system, run in your shell the following command to find the device name:

df -aTh

You could use the mount command to get similar listing, but df will give you more human readable listing.

Now that we have our device name we can create the actual image file. For this we will use dd command. This will copy the content of the SD-card into a image file that can be in turn copied back to a SD-card if needed with everything set up and configured.

The following instructions will work both on OS X and Linux-based systems.

sudo dd if=/dev/<device name> of=~/path/to/backups/<back-up name>.img

What we ask here dd to do, is copy from input file (if) to an output file (of). Put what ever you like inside the brackets and change the output file path to your liking.

Now, stay patient. This will take some time. For 8GB SD-card it can take easily 10 minutes. DD is an old program and the command I give here is not verbose.

When it’s done it will let you know by printing out how many records were moved in and our as well as how many bytes was transferred.

That’s it.