BONUS! Make a Backup Image!

It took a while to get your SD card set up, didn't it? Bet you don't want to have to do that again, do you?


Back it up!

Forum user, Mac user, and Adafruit Customer phil.drummond took it upon himself to find the best way to back up his system image.

And he found a fast and easy way - a script which quickly creates a clone of your running Raspberry Pi system, ON THE PI ITSELF!

Note: This script only works with occidentalis 0.2 and older versions of Raspbian
The script comes to us by way of Pastebin user BILLW.

What You'll Need

  • USB SD Card Reader
  • Blank SD Card
  • Booted and Running Raspberry Pi

Get the Script File

First, get a copy of the script file onto your Pi. You can do that in any one of several ways:
  • First, download the file to your computer
  • Use ssh or vnc to transfer the file from the computer to the Pi
  • Pop the blank SD into your USB Card Reader
  • Plug the Card Reader into your computer
  • Copy the file to the blank SD
  • Move the Card Reader to the Pi
  • Copy the file from the SD to the Pi
  • Use the Pi's Web Browser to navigate to this page and download the script file directly

Run the Script

  1. Put the blank SD card into your USB Card Reader, and plug it into one of the PI's USB ports.
  2. Open a Terminal window on the Pi
  3. Navigate to the folder where you stored the script file. (If you stored the file on the Pi's Desktop, simply type 'cd Desktop')
When you run the script, you will have to specify the name of your SD card. Raspbian and occidentalis assign the names 'sda', sdb', etc. to SD cards found on USB. If you only have one USB card reader attached, the name of your new SD card will be 'sda'.

If you're not sure that sda is the right card, you can run this command to list the cards connected to your Pi.
Download: file
sudo fdisk -l
The SD card slot with your running Pi system will show up as /dev/mmcblk0. Your blank card will be listed as /dev/sda1 (or possibly /dev/sdb1, if you have more than one USB card readers attached to the Pi).

Note that you don't enter the '1' - if your card is listed as '/dev/sda1', then you would still enter 'sda' when you run the script ('sda' is the name of the card, 'sda1' is the name of the first partition on the card).

Ok, so now you should be ready to run the commands
Download: file
chmod +x
sudo ./rpi_clone sda -f
As noted earlier, the first parameter passed to the script is is the name of the target SD card, in this case 'sda'. The -f tells the script to entirely re-format the card.

The script will ask you if you're sure you want to initialize the destination card. Type 'y', and hit the return key.
If you see an error message instead, check below for solutions!
Next, the script will ask you if you want to give your new backup a label. It's not necessary to do this - just hit the return key.

Finally, the script will ask you if you're sure you really want to do this, before it begins creating the backup. Type 'y', and hit the return key.

Now it's time to wait - the process will take a little while.

When the process is complete, the script will ask if it should unmount the card with your new system clone/ Reply with 'y', and you're done!

Now you can shutdown the Pi, swap the clone into the Pi's SD Card Slot, and restart - Bingo! a fully-operational clone of your Raspberry Pi system!


If you see an error message like this: means that your SD card is mounted in the file system. You have to unmount it before you can proceed. In the picture, I'm writing over an earlier clone of my system, which has two partitions: /dev/sda2 and /dev/sda1. You might only have one partition.

In any case, issue the umount command for each mounted partition on your destination SD card:
Download: file
sudo umount /dev/sda1
Now try to run the script again!
This guide was first published on Dec 03, 2012. It was last updated on Dec 03, 2012. This page (BONUS! Make a Backup Image!) was last updated on May 04, 2015.