Jul 222012
 

Why bother backing up your SD card?

I had a difficult time getting the new Raspbian image up and running. That wasn’t because there was anything wrong with it. It was because I am in an unusual position. I’m away from base without my normal Samsung HDTV/monitor, and without ethernet, so I’ve been running my Pi “headless” via ssh and VNC, using wifi.

I’d also brought with me one of the Neewer HDMI-VGA adaptors that I’ve tested successfully on a couple of monitors. We have a TV here with a VGA input, so I figured this would be OK if needed (and it works fine with Wheezy beta – although I’m not using it).

So, when the new Raspbian image was released, I flashed a new SD card (well I overwrote my Arch card as I haven’t used it since I got FUSE working on Debian). Obviously I couldn’t ssh into a new installation until I’d installed the wifi dongle drivers (no ethernet). So in order to do that I needed to attach a screen. This is where the trouble started. With the Neewer HDMI-VGA adaptor attached, the new image failed to boot. Just the red power LED and nothing else (the same as happens when you have a corrupted SD card).

I eventually got it to work by removing the Neewer adaptor, powering up the pi, waiting until the green OK led started flickering and then attaching the Neewer, after which I could see enough of the display to get through the “first boot” screens. The timing was a bit hit or miss, but eventually I got the screen displaying properly by tweaking settings in the /boot/config.txt file. After that I installed the wifi drivers and it was bye bye screen. :laugh:

So how does this bring me to backing up? Well, I like to mess about with my installation trying new things. In the past if I messed up, I just reimaged the SD card and started again. In this case, I don’t want to go through that process again :cry:  so I figured I’d back up an image of the fully working SD card before I break it. Now I’m going to show you how to do the same.

Using Windows

You may well have used Win32diskimager already to write your SD card. I’ve had great success with this using version 5. Download here. Then unzip the file win32diskimager-binary.zip, then double-click Win32DiskImager.exe in the unzipped folder called win32diskimager-binary. Click Yes to confirm you want to run the program. Then it will start. Once you’ve established that it works, close it down and plug in your SD card. Then restart the program. Choose the drive you want to copy the image from (in  my case F:\).

choose the drive with your SD card to read from

Then click on the folder icon and choose where to place your backup image – also give it a name e.g. backup345.img then click save

choose location and name for your backup card image

Then, the counter-intuitive bit. You have to click READ so it will read the SD card and write the image in the location you just chose.

click Read to read and backup your SD card

It might take a while. It took about half an hour to do an 8 Gb card. It will back up the whole image including empty space on the partitions. You can compress this later with winzip or 7zip, but if you want a really compact image you’ll have to shrink the partitions first and then regrow them later. Since messing with partitions is potentially disastrous – and what you’re trying to do here is protect your installation – I would recommend not shrinking the partitions. If you want to make an image to share with others by download, you could always do this AFTER you’ve backed up the data and then make another, more compact, image.

Using Linux

Use DD with extreme caution. It’s nicknamed Destroy Disk for a good reason. It’s a very powerful command and you can all too easily wreck your hard drive by being careless here.

dd if=/dev/sdb of=/path/to/backupfile.img

where sdb is the SD card location and backupfile must be a file name.img and not a disk identifier (or instead of writing a single file to the hard disk it will try to rewrite the whole disk).
This will copy the entire contents of sdb and dump it into the file backupfile.img

If you’re not sure what your SD card’s identifier (sdb, sdc etc.) is you can use the tail command as we did in the attaching a USB stick post.

Use DD with caution. You have been warned! If you have access to both, I’d say using the Windows option is safer, unless you really know what you’re doing (in which case what are you doing here? :-P )

Enjoy peace of mind now you know how to back up your Raspberry Pi Operating System SD cards.

  9 Responses to “How to back up your Raspberry Pi SD card”

  1. [...] developed and updated image of Raspbian, so I made an exact copy of the SD card for Pi #2. (see: how to backup an SD card image here | how to write an SD card [...]

  2. I tried using the windows solution but it only reads and images the windows readable partition of the SD Card – approx 60 MB. Did I miss something?

    • Although Win32diskimager copies the whole card, you can only see the FAT partition in windows. If you plug the SD card into a linux machine you will see at least one other partition as well, depending on which distro you backed up. Or just try the card on your Pi and see if it works. :-)

  3. [...] Ce post reprend les explications presente ICI et ICI. [...]

  4. My old fashioned way :
    * assuming /dev/sdc is your SD card with sdc1 is the FAT boot partition and sdc2 the root extended file system

    * backing up
    sudo mount -o ro /dev/sdc1 /mnt

    cd /mnt
    sudo tar -zcvf /tmp/Backup/RPi/boot.tgz .
    cd
    sudo umount /mnt

    sudo mount -o ro /dev/sdc2 /mnt
    cd /mnt
    sudo tar –exclude=var/log –exclude=lost+found -zcvpf /tmp/Backup/RPi/root.tgz .
    cd
    sudo umount /mnt

    * to restore on a new SD :
    - fdisk, parted, gparted to create the 2 partitions : one FAT and one EXT3 or EXT4
    - mount each one after one in /mnt and change dir to /mnt
    - finally restored with an extraction :
    tar -zxvf boot.tgz
    tar -zxvf root.tgz

    8-)

  5. Um, sorry, don’t understand…
    “If you’re not sure what your SD card’s identifier is you can use the tail command as we did in the attaching a USB stick post.”
    But you cannot boot the pi from the SD card and then tail the messages file while you plug in the SD card it already booted from!

    ls -l /dev | grep sd
    brw-rw—T 1 root floppy 8, 0 Nov 28 18:57 sda
    brw-rw—T 1 root floppy 8, 1 Nov 28 18:57 sda1
    This is my external 1TB USB drive, so I have no sd* device for my SD card the pi booted from!

    Help required please because taking the SD card out for a windows cold backup is not going to be easy for me, I’m after 100% uptime and it’s going to be on a dark site…

    • That applies to taking the card out and putting it into a card reader in another Linux machine. If you don’t know what the ID of your card in the card reader is, use the tail command. Will update it so it’s clearer. :)

      This procedure is not intended to be used for “in situ” SD card backup. There is a thread on the Pi forums where someone runs a backup on a live system. I suggest you seek it out. It’s not something I know how to help with. Sorry. :(

      • OK, thanks, makes sense now.

        Plugged another SD card in via a USB dongle and the new SD card shows as sdb:

        ls -l /dev | grep sd
        brw-rw—T 1 root floppy 8, 0 Nov 29 00:21 sda
        brw-rw—T 1 root floppy 8, 1 Nov 29 00:21 sda1
        brw-rw—T 1 root floppy 8, 16 Nov 29 00:21 sdb
        brw-rw—T 1 root floppy 8, 17 Nov 29 00:21 sdb1
        brw-rw—T 1 root floppy 8, 18 Nov 29 00:21 sdb2

        I guess sdb is the device, sdb1 is the boot partition and sdb2 the data bits and pieces.

        I’ll go search for live backups.

        Thanks,
        Mart

        • I guess sdb is the device, sdb1 is the boot partition and sdb2 the data bits and pieces.

          Yes – that seems to be the case. :-)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>