Back up and clone raspberry pi

In this post, I will explain how to back up and restore or clone a raspberry pi. I am assuming that you have installed Raspbian or Ubuntu mate on your raspberry pi. Since a raspberry pi runs its OS entirely on an sd card, it is easy to clone your system so you can pass along to a friend or create your special distro for others to use. For example, a company that makes compact optical spectrometer, Ocean Optics, has created a spectrometer program that runs on raspberry pi and has its own web interface. You just have to download their raspberry pi image and put it on your card. No need to do multiple build from source and apt-get etc. to get what you need.

If you are already a Linux guru, this post is NOT for you. I am assuming that you don’t have a Linux machine other than raspberry pi or you are still learning Linux.

The “easy” way:

Raspberry pi foundation has raw images of their Raspbian and NOOB on their website. On a windows system, all you need is win32 disk imager. It reads in the image and writes it on an SD card. You can save the image it reads and keep it as a backup or use it to clone a system.

The catch:

Since win32 disk imager only reads and writes in raw format, it actually doesn’t know what it is reading/writing. Say if you want to clone your raspberry pi 2B running Raspbian Jessie on an 8GB Kingston microSD card onto an 8GB SanDisk microSD card, you simply can’t. Although both cards claim to be 8GB, the SanDisk card is about 20MB smaller than the Kingston. Not understanding what it reads and writes, win32 disk imager is unable to shrink even one byte of what it reads (the whole 8GB from Kingston) to try to fit it onto a smaller card. This has pushed people into buying larger cards, such as 16GB. Then when they try to clone a system again, they run into the same issue unless they have bought a few identical SD cards as clone targets. Even that has issues (read the end of the post for details). So they have to step up to 32GB!!!

The solution:

We need a disk/partition reader and writer that understands what it is processing and is able to resize the partitions so they fit. If you are not hosting a lot of large files, you should be OK with an 8GB card or more than OK with a 16GB card. I’ve looked around for quite some time and found my solution: Paragon backup and Recovery 14 Free edition (Home edition for $39,99 has more features not useful for us). It is only for windows so those mac users will either need to become Linux gurus or shell out a small amount of money to get a win 10 netbook.

What the program does is that it is able to back up a whole disk or SD card and restore it on disk or SD card of different size. The reason is it understands most common file systems such as FAT, NTFS, HFS, and EXT. Besides, it also automatically compresses the backup so it doesn’t take more space than it should on your PC.

How to do it:

First you make a backup of your raspberry pi card using back up to VD. It is a virtual hard drive. This backs up both BOOT partition (FAT partition) and your Linux partition (ext4).

backup_to _vd

Next, insert your new SD card (you need to quit the program and restart it). Select restore from VD. It will ask you whether to resize partition and you can choose yes. This way you can even squeeze your clone from a larger card (32GB) to a smaller card (8GB) if your Linux partition has a lot of space.

Another neat trick:

What else you can do is to resize BOOT partition. Although BOOT partition has not much use for most of us, it IS the only partition that windows will recognize. If you are using your pi as a data logger or need to copy files from and to it (without the hassle of SSH and network setting), then the best way to get data is if it is written to the BOOT partition. You turn off raspberry pi and put its SD card on your windows machine. Immediately you have access to BOOT partition. You can copy your data out, you can change some config files of your data logger etc. It is useful to have a large BOOT partition. To do this, you will have to restore one partition at a time. Restore BOOT first. You will be prompted to select the size of the restored partition. Make your selection, say 500MB. Then when the restore is over, use the rest of the space on card to restore your Linux partition (make sure you leave enough space for Linux partition).

Why buying identical cards may not solve clone/restore issue?

Well, say you purchased 10 Kingston 8GB microSD cards, they are all the same size, correct? Wrong! I learned it the hard way. I had a friend that sent me an image he saved from such a card. I have identical cards. But, when I was telling win32 disk imager to write the image on my card, it complained: the target card doesn’t have enough space! Guess what, the target card is one sector less than the image file has?! But how can this happen? It’s simple now that I got my answer: some sectors on the SD card may have become bad either at factory or post purchase. The SD card controller (inside the card there is a controller) has disabled those sectors, making not all “identical” cards identical.


17 Responses to Back up and clone raspberry pi

  1. amrosik says:

    paragon says I got to reinit the boot loader. I dont have any running linux system to do that.

    • liudr says:

      That’s OK. It is a generic warning. We don’t need to worry about it. It is intended for a PC linux system since paragon detects ext4 partition, thinking it just duplicated some PC linux partition. Raspberry boots simply without the bootloaders that PC uses. The “bootloader” for raspberry pi is always on the FAT partition, FYI. I’ve done dozens of duplication of my raspberry pi and this is NOT a problem.

  2. I have a raspberry pi working with retro pi, thousands of games etc…I wish to build one for a family member for xmas. So I have used ApplePi-Baker to backup the working sd card (32GB) so that I can then restore the backup image to a new 32GB sd card. It doesn’t work. I get a series of error messages when turning on the pi: end kernel panic – not syncing: No working init found etc etc. Can’t work out where I’m going wrong! All I want to do is clone the card! Any help and advice greatly appreciated!!

    • liudr says:

      What about using a PC and the Paragon backup and restore free version I mentioned in my post? That has been proved to work by myself over a couple dozen times and never failed. I am not familiar with ApplePi-Baker software. I’ll give it a try on my mac when I get the time.

      Yes, holiday season, classic games. That brings back memories. Good luck getting your family member the gift.

  3. Hi. I’ve been looking for a solution for a few days (8GB image on a slightly smaller different 8GB SD card). This has worked beautifully. THANK YOU!

    • liudr says:

      You’re welcome Antonio. I did the same fruitless search for solutions. I brooded over it for a couple of years and decided to search again. This time I was using Paragon’s software on my PC and happened to have downloaded their other free software. BAM! Do try their free EXTFS PC software if you run a windows PC. It makes your PC able to read any Linux partitions. Copy files, move stuff around on your RPI partition is made very easy now.

  4. drabelincoln says:

    I tried using Paragon back and recovery free 14 but it didnt recognize my linux partition. Not sure what I did wrong or if i need additional software to see the other partiations. All I get is a partition for Local Disk and shows it as unformatted.

  5. Simone says:

    Hi liudir, i’ve tried using paragon for cloning my rpi sd card multiple times and keep failing. It looks like the cloning worked fine however whenever i try to use the cloned sd card, the rpi will not boot. It won’t do anything at all. Any idea why that would be? i’ve made sure to follow your instructions with the intent of cloning an 8 GB sd card with NOOBS raspbian into a 16 GB sd card. I’ve also tried to resize the each partition to fit into the bigger sd card, leaving it with no unallocated space.
    Any tip on why the rpi won’t boot up would be much appreciated. Thanks

    • liudr says:


      I’ve never used a NOOBS SD card so I can’t say that the method I showed here will work on NOOBS. I’ll give it a try probably during the winter break.

  6. Jose says:

    Liudr, thank you very much for the blog entry. This approached worked very well for me as well, I was attempting to clone a 32GB Samsung microSD into a 32GB Toshiba microSD and the sector count was just lower on Toshiba to prevent a “normal” approach with Winimager.

  7. Joshua DeFelice says:

    for some reason , it tells me a resize is required, but doesnt actually give me the option. just fails

  8. Justin Modra says:

    Thanks for your detailed post, but it looks like the functionality of the Paragon Backup and Recovery Free Edition 14 has changed in 2017. When I tried to restore a VD that was 1Mb larger than the target SD card, all the software said was there was a size mismatch. No option to resize. The software looks different than your screenshots. It is now much more Windows 10 app-like and does not provide many options.

    • liudr says:

      Is it possible that you enabled (by default) the easy interface? I recall right after install and running for the first time the program gives you a dialog with square box icon buttons like win10 style. There is a button to go to full version or something like that. I remember choosing that option. Could you post a screen shot of your program’s interface? I suspect they just gave you the easy interfaces that don’t have any options.

      • Justin Modra says:

        Thanks very much for your reply. Switching out of easy or Windows 10 App mode (Express Mode) is accomplished by selecting Switch to Full Scale Launcher. Unfortunately, it still seems that the resize partition functionality is broken or disabled. I also installed a trial version of Paragon’s Hard Disk Manager but this did not improve the functionality.

  9. Terry says:

    Justin: Appears they want $$$ now to resize a partition. If in the full scale launcher, select
    partition sizing in the top menu bar, and you will see all partition functions are greyed
    out….except the “unlock” icon….which is a quicklink to paid edition.

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: