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.

 

32 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:

      Simone,

      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.

    • jor says:

      Hi liudr, i’ve used Paragon BR 14 free version as you suggest , but encounter the same problem as described by simone. Then decided to use Paragon BR 16 full (29 euros), as you suggest in later posts, and repeated the same procedure. This time the raspberry loads for a few seconds (until appears the RPI logo) then reboots all over again. Can you please help me somehow? I need to replicate a few cards in order to deploy a small net.
      I am using a Raspberry Pi 3 Model B with Raspbian and all updates applied.
      Thanx in advance
      jor

      • liudr says:

        Jor,

        I was able to successfully duplicate my newer Raspbian Jessie SD cards using the free version of BR16. It has very few features since it is free. I suspect that the latest Raspbian Jessie and Stretch have something that BR won’t recognize. I tried several times to duplicate cards with the latest Raspbian Jessie with no avail. If you are stuck with the latest Jessie or Stretch that BR16 can’t handle, try the rufus program or the included sd card copier in Raspbian. I’ll raise some questions on paragon-soft’s forum hopefully they’ll get their program to handle latest raspbian.

  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:

      Justin,
      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.

  10. Marshall Cummings says:

    Hello Liudr! Thanks for an excellent post! I mean…I think it’s excellent, if I can just get it all to work!

    Basically, I’ve followed the directions exactly – I create the virtual image, I write the virtual image to a new SD card, no problem. I get the message from Paragon about needing to reinitialize the boot loader, which I ignore. But when I put my newly created SD card into my Pi and boot it, I get the following message every time;

    bcm2835-aux-uart 3f215040.serial: could not get clk: -517

    Any ideas what might be happening here? Are you sure this isn’t somehow related to needing to reinitialize the boot loader?

    A few details – I am using a Raspberry Pi 3 Model B (latest and greatest) with the latest full release of Raspbian Jessie (April 10, 2017) with all updates applied.

    Any thoughts or recommendations? Dying to get this to work!

    Thanks so much,
    Marshall

    • liudr says:

      Hey I wish I knew the solution. I will post an update once I get it working again with the most recent distro.

      • Ok, great – thank you so much! I will keep an eye out for a follow up. In the meantime, enjoy your weekend!

        Thanks,
        Marshall

      • Jan Bednar says:

        Hi Liudr,
        I’m having the same problem as Marshall. Does it have any solution as you wrote? Will you have a post about that?

        Thank you,
        Jan Bednar

      • liudr says:

        Jan,

        Sorry about the delay. Been very busy. I’ve given up on Paragon backup recover 2014. I was unable to back and clone my most recent raspberry pi with the most recent (July 2017) Jessie distribution. I was however able to back up and clone with the newer version Paragon backup recovery 2016. It has even less functions than 2014 but can back up and duplicate. The target card can be smaller in size as source, such as 16GB target card with 32GB backup. I was unable to resize the FAT partition as before so shrinking 32GB card into 8GB card become impossible because that would proportionally shrink the FAT partition too small. I’ll search for more tools. For now, use Paragon 2016 version if you’re just squeezing 32GB cards onto 16GB clone cards.

  11. Chris B says:

    @Liudr

    The 2014 version is on CNET still, 370MB download. I will hold onto it just in case it is needed later on down the road and CNET takes it down.

    http://download.cnet.com/Paragon-Backup-Recovery-Free-64-bit/3055-2242_4-10972187.html?tag=pdl-redir

    • Dave OB says:

      @ChisB
      Sorry, just noticed that it was you ( not Liudr ) that posted the link.
      PLEASE do you possibly have a dropbox copy of that 2014 version file ?
      The link in your last reply is no longer there.
      The ’16 version of Paragon fails to work.

  12. Dave OB says:

    @Liudr
    PLEASE do you possibly have a dropbox copy of that 2014 version file ?
    The link in your last reply is no longer there.
    The ’16 version of Paragon fails to work.

  13. Scott W says:

    All of this above is obsolete if you are running the operating system Stretch on the Pi. It ships with a backup program named SD Card Copier found in the Accessories menu.

    Get a USB stick that will hold your new (spare backup) SD Card. The backup SD card can be smaller or larger… It doesn’t matter about the exact size as long as your existing (running) SD Card software will fit on the new card. Put the stick in a USB port on the Pi and run SD Card Copier. In about 15 minutes you will have a 100% bootable backup. No kidding… you can replace the chip that was just running in the Pi with the backup you just made and voila!! It will work.

    • liudr says:

      Yes, it’s from a while ago so it’s mostly obsolete. What’s not obsolete is the idea to keep a copy of your RPI sd card on your hard drive. If you have a few snapshots of your RPI sd card and each requiring an actual sd card to hold, like the SD card copier would require, then you’re limited by how many sd cards you have. I still haven’t found a good solution to that but yes I use SD card copier to clone for another system and have extra sd cards to keep a copy. It’s a pain in the butt. You have to find a plastic bag and write what that sd card is about with a Sharpie on the bag since the sd card is so small 🙂

  14. A.R. says:

    Hi Liudr, you just saved me a ton of time!

    I’d like to add a couple of things in order to help your other readers –

    1. The restored cards don’t work on Raspberry Pi4 because it uses disk IDs (PARTUUID). To get over this problem, get the PARTUUID from the cmdline.txt file in the boot partition, and change the disk unique ID to this value using the “diskpart” utility on windows.

    2. Another benefit of using this approach for backups is that you can fully browse and inspect the contents of backups right from within Windows!

    Anwyay, thanks again, and keep going! 🙂

  15. kotlet says:

    Actually this method still works, only one extra steep is needed when restored.

    open diskpart in cmd and type
    SELECT DISK (you can find your sd by typing `list disk
    `)
    open cmdline.txt from boot partition and copy PARTUUID= number without last 3 characters (usually -01 or -02 or similar)

    go back to diskpart cmd and type:
    UNIQUEID DISK ID=paste your PARTUUID here

    exit diskpart and put your sdcard in raspberry pi, it will boot without any issue.

    • liudr says:

      Great! I’ll give it a try. The current methods are always whole sd images, unintelligent and huge in side and not editable once in image format.

Leave a Reply

%d