Backup And Restore Raspberry Pi SD Card

Backup Raspberry Pi SD Card

1. Insert the SD card in your PC using a USB or built-in card reader. Now open a Terminal window, and enter the command sudo fdisk -l. This will list all the filesystems present on your system.

2. Try to find out the device name of your SD card. I have a 16GB SD card, so it is easily identified as the device /dev/sdb which has a size of 14.9GB. This is because the actual storage on a device is always slightly lower than advertised. Note down this device name.

fdisk

3. Use the dd command to write the image to your hard disk. For example:

sudo dd if=/dev/sdb of=~/raspbian_backup.img

Here, the if parameter (input file) specifies the file to clone. In my case, it is /dev/sdb, which is my SD card’s device name. Replace it with the device name of yours. The of parameter (output file) specifies the file name to write to. I chose raspbian_backup.img in my home directory.

Note: Be careful, and double check the parameters before executing the dd command, as entering the wrong parameters here can potentially destroy the data on your drives.

You will not see any output from the command until after the cloning is complete, and that might take a while, depending on the size of your SD card. Once it is complete, you will see an output like the following.

dd-success

You can now remove the SD card and use it in your Pi. Once you are ready to restore the backed up image, follow the instructions below:

Restore Raspberry Pi SD Card

1. Insert the SD card in your PC. Before we restore the image, it is important to make sure that the SD card’s partitions are unmounted. To verify this, open the Terminal, and execute the command sudo mount | grep sdb. Here, replace sdb with your SD card’s device name.

If you see a blank output, you do not need to do anything. If you do see some mounted partitions, unmount the listed ones. For example:

sudo umount /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4

2. Use the dd command to write the image file to the SD card:

sudo dd if=~/raspbian_backup.img of=/dev/sdb

This is like the command we used to make a clone, but reversed. This time, the input file if is the backup image, while the output file of is the SD card device.

Again, verify, and double-verify the parameters here, as entering the wrong command here will cause permanent data loss.

Once the write is complete, you will see a confirmation from dd. You can then remove the card from your PC, and insert it back in the Raspberry Pi.

Alternatif Bilgi

On Linux or OSX I use dd to make a backup from SD card. Reverse if and of (i.e. to where they point – source and destination) afterwards to restore, but be careful not to restore to a wrong disk. It will be destroyed without a warning!!!

First use fdisk to get the device id of you SD card (check the size)

fdisk -l

then I use dd to make a diskimage (change /dev/sdb with what you found with fdisk -l):

dd bs=4M if=/dev/sdb of=image1-`date +%d%m%y`.img

or this to make a compressed imag:

dd bs=4M if=/dev/sdb | gzip > image1-`date +%d%m%y`.img.gz

on OSX find device with:

diskutil list

then dd with something like if=/dev/rdisk1 (the ‘r‘ in rdisk1 stands for raw which is faster)

On OSX you can also use ‘Disk Utility’

by making a crontab like this it will give you a status every minute:

* * * * * /usr/bin/pkill -USR1 -x dd