Back Up the SD Card

After you have install the operating system of your choice into the SD card, configure the Raspberry Pi and install all the little bits and pieces that are critical for your project is always a good idea to make a backup image of your card. A lost SD card or a file system error or anything else that can broke the normal operation can break your day. The result will be to start all over again from ground zero… and thats time consuming and unnecessary if you just follow a few simple steps!

I will start from the OSX as this is my primary system and next the Windows process will follow.


Using a Mac

Plug the SD card into the card reader. Open a terminal window and type:

diskutil list

You will presented with a list of all attached storage devises on your system (picture below). Have a look at the size section column in order to recognise the desired storage devise that includes the RPi operating system. In my case this is the /dev/disk2 with the 7.9 GB of storage (this is a regular 8GB SD card from SanDisk). The name that we want is the disk2. Pay attention to this! If you select and other disk then you probably going to “brake” the operation of your PC/Laptop!

Now type:

sudo dd if=/dev/rdisk2 of=~/Downloads/NameOfYourImage.img bs=1m

This will tell OSX to make an image file (.img) under the name NameOfYourImage (in my case OpenELEC_Backup) and store it on the Downloads folder. You can select any folder you want (of course not the SD card that you are cloning) and the file name of choosing.

Despite that our SD card was mounted on the /dev/disk2, we prefix the letter r before the disk2. This will point to the card’s raw storage space and speed up the process. You can also type just /dev/disk2 but it will take significant longer time to clone the SD card into the image file.

Type your OSX password and wait. You are not going to see any progress bar here nor anything else between the process. Don’t worry! This is 100% normal!

When everything ends correctly the result will be like the one on the photo below

And you are done! It simple like that! Now, the next time you want to use exactly the same combination of OS and configurations for your Raspberry Pi you can use the backup image file instead of the original. It will save you time and effort!

The only problem with this is the size of the produced image. It is the same as the size of the original SD card. This is OK if you store the file on your PC/Laptop HDD but not good for a USB transfer or even an upload over the internet.

The best solution to this “problem” is to directly compress the image during the cloning process. This is happening by modifying slightly the dd command that we already used above.

Instead of:
sudo dd if=/dev/rdisk2 of=~/Downloads/NameOfYourImage.img bs=1m

you have to type:
sudo dd if=/dev/rdisk2 bs=1m | gzip > ~/Downloads/OpenELEC_Backup.gz

This command will tell OSX to route the output of dd not to a raw image file but to the gzip utility. This is happening by using the Unix pipe symbol |. When it finish you are going to have the same output as by using the original dd command

The resulted .gz file is significant smaller compared to the raw image produced before. For example those are the sizes of the two files (.gz and .img) produced by backing up the same SD card

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: