How to Backup and Restore the Raspberry Pi SD Card?
How to backup and restore the Raspberry Pi SD Card?¶
Introduction
We use the 'dd' command to backup and restore the Raspberry Pi SD Card. Normally, We use to 4M bytes to read and write at a time in backup and restore it. There are three parameters, including 'bs', 'if' and 'of'. The 'bs' means reading and writing up to BYTES bytes at a time. The 'if' means reading from FILE instead of stdin. I think you can imagine that it is an input file to read. The 'of' means writing to FILE instead of stdout. I think you can imagine that it is an output file to write.
Equipment
Operation System: Ubuntu 14.04 LTS
Usage
The 'dd' can create a partition data into a file. So, we can backup whole partitions of an SD Card into a file. You need unmount whole partitions on the SD Card before you are backing it up. Default Raspbian installation has three partitions made on the SD Card, so we need to unmount whole partitions. To check which partition is mounted to which device, use 'df -h' and see the lines refer to as below.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/root 29G 4.9G 23G 18% / devtmpfs 215M 0 215M 0% /dev tmpfs 44M 280K 44M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 88M 0 88M 0% /run/shm /dev/mmcblk0p5 60M 9.6M 50M 17% /boot /dev/mmcblk0p3 27M 397K 25M 2% /media/SETTINGS
Then unmount the corresponding folders. If your OS is Ubuntu, you should be into the folder/node (/dev) and then find out the three devices. As long as we are unmount three partitions and then we can use the largest partition name in the SD Card to backup it.
# cd /dev # ls autofs loop4 ram10 tty1 tty30 tty51 vc-mem block loop5 ram11 tty10 tty31 tty52 vcs btrfs-control loop6 ram12 tty11 tty32 tty53 vcs1 bus loop7 ram13 tty12 tty33 tty54 vcs2 cachefiles loop-control ram14 tty13 tty34 tty55 vcs3 char MAKEDEV ram15 tty14 tty35 tty56 vcs4 console mapper ram2 tty15 tty36 tty57 vcs5 cpu_dma_latency mem ram3 tty16 tty37 tty58 vcs6 disk mmcblk0 ram4 tty17 tty38 tty59 vcsa fb0 mmcblk0p1 ram5 tty18 tty39 tty6 vcsa1 fd mmcblk0p2 ram6 tty19 tty4 tty60 vcsa2 full mmcblk0p3 ram7 tty2 tty40 tty61 vcsa3 fuse mmcblk0p5 ram8 tty20 tty41 tty62 vcsa4 hidraw0 mmcblk0p6 ram9 tty21 tty42 tty63 vcsa5 hidraw1 net random tty22 tty43 tty7 vcsa6 hidraw2 network_latency raw tty23 tty44 tty8 xconsole input network_throughput shm tty24 tty45 tty9 zero kmsg null snd tty25 tty46 ttyAMA0 log ppp stderr tty26 tty47 ttyprintk loop0 ptmx stdin tty27 tty48 uinput loop1 pts stdout tty28 tty49 urandom loop2 ram0 tty tty29 tty5 vc-cma loop3 ram1 tty0 tty3 tty50 vchiq
If the Raspbian of the SD Card has three partitions, including /sdc1, /sdc3 and /sdc5, you should pick up the largest partition that is /sdc. Thus, we have the 'if' parameter that is /dev/sdc. Now, we are just setting up the 'of' parameter. It is that you want to output file name. Normally, we are just giving it a unique file name, such as '~/Image.img'. So, we need check to your hard disk space that enough saves your image file. We haven't compressed it. Therefor, The SD Card size is the image file size. To follow this command-line that you can backup your SD Card, as below.
# sudo dd bs=4M if=/dev/sdc of=~/Image.img
I prefer uncompress to create this backup SD Card. Because I have enough free space in my hard disk. I can do the restoring process to wire it to the SD Card.
# soud dd bs=4M if=~/Image.img of=/dev/sdc
You can try to do it. To backup and restore your SD Card. If you have more and more backup image, you would be safe about your Raspbian OS and your applications. There is one thing worth notice. You shouldn't use different kind of SD Card to backup and restore. Because it is very important that different kind of SD Card may be made with different size. For example, There are two 32GB SD Card. The ADATA is only 31.9GB. Another is TDK that has 32.0GB. So, we can restore smaller size into a larger size. But we cannot restore larger size into smaller size.
Acknowledge
Thank you (Ask Ubuntu) very much for this explain of the great tool.