Raspberry Pi Backup: The Best Backup Tutorial

 

Raspberry Pi Backup Tutorial DIY hacking

Raspberry Pi Backup

For all those who have worked on a raspberry pi, you might have experienced the frustration associated with having a corrupted SD card. Especially, when all the work you have done is stored in it. But, it doesn’t have to be that way. Using a couple of really simple commands in Linux , you will be easily able to backup your Raspberry Pi SD card. And, when required, to restore the raspberry pi backup on to a new SD card.

The process is really simple and straight forward. Once you have restored the image of your raspberry pi backup to your new SD card, you will be able to just plug it in and use it like your old system. This post also covers general dilemmas such as: how to backup a raspberry pi SD card having multiple partitions and also the solution to the infamous dd command error: “dd: writing to `/dev/sdc’: Input/output error”. It also addresses the problem of not being able to use your full memory capacity of your raspberry pi SD card after restoring an image file onto it. So, use this DIY Hacking tutorial to safeguard all your precious work on a raspberry pi. Get started with this Raspberry Pi Backup tutorial!

What are the stuff required to do this ?

  1. Raspberry Pi model B or Raspberry pi 2 with memory card preloaded with an OS.
  2. A new SD card having a memory capacity equal to or greater than the SD card you would like to backup.
  3. A linux pc with a memory card reader.

How does it work?

Here, we are using simple dd commands to create an image (.img) of the SD card we want to backup. This image can then be zipped and stored in your pc for future. While restoring the raspberry pi backup , you again use the dd command in the reverse order and prepare the new SD card. However, please note that restoration of an .img file can only be done on to a memory card having equal or greater memory capacity than the original backed up SD card. Take extra precaution while performing the dd command , as it can cause you to corrupt your hard disk if you enter improper destination or source addresses in it.

Raspberry Pi Backup Tutorial DIY hacking

Raspberry Pi Backup

Step 1 : Backing up your SD card

First of all, insert your raspberry pi SD card into the memory card reader / slot of your PC. Next, use the dd command to create an image file of the SD card. To correctly identify your card, perform “df -h” before and after inserting the SD card and observe the new paths . These, new paths represent your SD card. You might notice that you have more than one partition for the memory card, for example: when you perform “df -h” , it might list your SD card as /dev/sdc1 and /dev/sdc2. In this case, use just “/dev/sdc” while performing the dd command, to include both partitions. Like so :

sudo dd if=/dev/sdc of=/home/ars/backup.img

The memory card should be specified under “if” and the destination of the backup under “of”.You can use “bs=1M” or “bs=4M” to specify writing speed with the command too.

However, after performing the above command some of you might experience an error like : dd: writing to `/dev/sdc’: Input/output error. For those haven’t got this error, please proceed to step two. This error is usually caused due to some errors encountered while reading the SD card. It is normally experienced by people who see a warning while booting the pi , saying that they should perform an fsck operation manually. It is caused due to improper unmounting of the SD card. To get over this error, you have to perform the fsck operation on the SD card. Before doing it, unmount the SD card as so :

  • umount /dev/sdc1
  • umount /dev/sdc2

Next, perform the “fsck” operation to rectify the errors in the memory card. Like so:

  • sudo fsck -C /dev/sdc1
  • sudo fsck -C /dev/sdc2

Now, remove the card reader or the SD card and re insert it. And again perform the dd command like below, it should work without any errors. If it again shows dd errors , repeat the above steps.

sudo dd if=/dev/sdc of=/home/ars/backup.img

Step 2: Restoring your Raspberry Pi backup to a new SD card

Now, we will restore the Raspberry Pi backup from the first step. If you have a used SD card having some data in it, then you would have to format it first. If you have a brand new card, it might not be necessary to format, even though it wouldn’t hurt to. Insert the new card to the card reader. Use “df -h” command to identify your new memory card. If you have multiple partitions on the card like /dev/sdc1 and /dev/sdc2 , format the card by using /dev/sdc to include both partitions.

Before formatting the card, unmount the SD card. Like so, for an SD card with no partitions:

  • umount /dev/sdc

Like so, for a used SD card having multiple partitions:

  • umount /dev/sdc1
  • umount /dev/sdc2

Next , format the card using this command :

sudo mkdosfs -I -F32 /dev/sdc

After this, you will have a completely blank and formatted SD card. Now, remove the card reader or the SD card and re insert it into the PC. Next , perform the dd command to restore your raspberry pi backup on this new card. Use the location of the image file created using the first step under the “if” section and the new SD card location under the “of” section. Like so:

sudo dd if=/home/ars/backup.img of=/dev/sdc

Now, you have created an identical copy of your original raspberry pi SD card. Plug it in your raspberry pi and it will be just like how it used to be before :)

In cases, when you are using a new SD card of greater memory capacity than the original card. You will notice that, when you perform “df -h” command, the size of the new card is identical to the original SD card even though it is actually a bigger SD card. In order to utilize the entire space of the new SD card, simply plug in the card into your raspberry pi and start it up. Enter the command “sudo raspi-config” and select “Expand root partition” option. It will ask to reboot when you exit by selecting “Finish”. After rebooting, perform “df -h” command, you will notice now that the maximum size of the SD card is its full capacity.

In any case , if you experience the dd error : dd: writing to `/dev/sdc’: Input/output error , in the second step. Please perform the fsck operation like in the first step and perform the dd command again after removing and re inserting the raspberry pi SD card or the memory card reader onto the PC. Having a Raspberry Pi backup will make your life a lot easier :)

 

 

Recommended Posts
Showing 7 comments
  • janine
    Reply

    I cant expand the filessystem with raspi-config. I’ve replaced an 8g card with a 16 g,
    sudo raspi-config says:
    Your partition layout is not currently supported by this x
    x tool. You are probably using NOOBS, in which case your x
    x root filesystem is already expanded anyway.

  • suhail
    Reply

    ARAVIND SANJEEV U R GREAT

    i heard about ur invention from the news channel, i also like to create onem. but i have so many confusions and doubts would you please hewlp me.

    1. were i can find rasberry pi model b board and its software
    2. how i install the software to the board
    3.hopw i connect the internet to the rasberry pi board
    4. where i got the onother aprts

    would u pls e mail me a better and all detailed tutorial plssss

    i request u plsss

    i have ni idea withconecting part

  • masmoj
    Reply

    how can we get this raspberry pi board?

pingbacks / trackbacks
  • […] For instructions on how to install this image file onto your SD card , look at step 2 of this tutorial. To begin using the voice commands , just enter the command given below and start using the system […]

Leave a Comment

89 + = 94

Start typing and press Enter to search