Duplicating Your Raspberry Pi’s SDHC Card

There are a few reasons you might want to duplicate (clone/copy) your Raspberry Pi’s Secure Digital High-Capacity (SDHC) card. I had two, backup and a second Raspberry Pi. I spent untold hours installing and configuring software on your Raspberry Pi with Java, OpenCV, Motion, etc. Having a backup of all my work seemed like a good idea.

Second reason, a second Raspberry Pi. I wanted to set up a second Raspberry Pi, but didn’t want to spend the time to duplicate my previous efforts. Nor, could I probably ever duplicate the first Pi’s configuration, exactly. To ensure consistency across multiple Raspberry Pi’s, duplicating my first Raspberry Pi’s SDHC card made a lot of sense.

I found several posts on the web about duplicating an SDHC card. One of the best articles was on the PIXHAWK website. It only took me a few simple steps to backup my original 8 GB SDHC card, and then create a clone by copying the backup to a new 8 GB SDHC card, as follows:

1) Remove the original SDHC card from Raspberry Pi and insert it into a card reader on your computer. I strongly suggest locking the card to protect it against any mistakes while backing up.

2) Locate where the SDHC card is mounted on your computer. This can be done using GParted, or in a terminal window, using the ‘blkid’  (block device attributes) command. My Raspberry Pi’s SDHC card, with its three separate partitions was found at ‘/dev/sdb’.

GParted View of SDHC Card

GParted View of SDHC Card

Terminal Window View of Partitions

Terminal Window View of Partitions

3) Use the ‘dd’ (convert and copy a file) command to duplicate the contents of the SDHC card to your computer. This can take a while and there is no progress bar. The command I used to back up the card to my computer’s $HOME directory was:

sudo dd if=/dev/sdb of=~/sdhc-card-bu.bin

4) Unmount and unlock the original SDHC card. Mount the new SDHC card. It should mount in the same place.

5) Reverse the process by copying the backup file, ‘sdhc-card-bu.bin’, to the new SDHC card. Again, this can take a while and there is no progress bar. The command I used was:

sudo dd if=~/sdhc-card-bu.bin of=/dev/sdb

Using ‘dd’, backups and restores the entire SDHC card, partitions and all. I was able to insert the card into a brand new Raspberry Pi and boot it up, without any problems.

Obviously, there are some things you may want to change on a cloned Raspberry Pi. For example, you should change the cloned Raspberry Pi’s host name, so it doesn’t conflict with the original Raspberry Pi on the network. This is easily done:

sudo nano /etc/hostname
sudo /etc/init.d/hostname.sh start

Also, changing the cloned Raspberry Pi’s root password is a wise idea for both security and sanity, especially if you have more than one Pi on your network. This guarantees you know which one you are logging into. This is easily done using the ‘passwd’ command:

Changing the Root Password on Raspberry Pi

Changing the Root Password on Raspberry Pi

, , , , , , , , ,

  1. #1 by david on May 10, 2013 - 10:50 am

    thank you!

  2. #2 by Nazaire on November 1, 2013 - 4:33 pm

    Hi, Thanks for writing this article. I successfully copied 8GB card into my computer, but when i copy the backup .bin file to a 16GB card, after 30 mins nothing seems to be advancing in the dd command. When i try wih file explorer my SD Card has same old content with one single partition. I wonder whether it will work from 8GB to 16GB, or is it that i should unmount the card before copying the backup ? Any clue ?

    • #3 by Gary A. Stafford on November 1, 2013 - 6:55 pm

      My first guess is that it didn’t finish or it was copying to the wrong location. I usually copy to a blank card not one with current content.

      • #4 by Nazaire on November 3, 2013 - 2:31 pm

        Thanks Gary,
        As you gussed, it took more than an hours to copy 8 GB of card, since there is no progress indicator in the console i was lost. Thanks anyways.

      • #5 by Gary A. Stafford on November 3, 2013 - 2:37 pm

        Great. Thank you.

  3. #6 by Mike on May 7, 2016 - 5:48 pm

    What is GParted? I can’t find that anywhere. I opened a Command Window and tried the command sudo blkid but get the errror:
    C:\Users\Mike>sudo blkid
    ‘sudo’ is not recognized as an internal or external command,
    operable program or batch file.

  1. Raspberry Pi-Powered Dashboard Video Camera Using Motion and FFmpeg | ProgrammaticPonderings
  2. Pixhawk Sd Card Problem

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: