Backing Up a Raspberry Pi with dd

in raspberrypi •  6 years ago 

This post origonally appeared two years ago on my Blogger account, click here to view the origonal.The only differences between this article and the origonal are this intro, the afterthought, and some updated links. If attemping to follow the instructions below, I would recommend using the Disk Utility's built in restore/create disk image feature instead. The process below is still useful for working in a terminal or when the Disk Utility isn't available.




While making another tutorial, I realized one thing I forgot that every Pi owner should do regularly:

Backup the SD card in case of a crash

 So this tutorial will show how to use our favorite operating system, Linux, to clone an SD card to an image file.



Prepare



First, you will need to find the path of your SD card. One easy way to accomplish this on Ubuntu systems is to open the "Disks" utility by opening the Unity Dash and searching "Disks".




Here is another screenshot of the icon on a Ubuntu system running the Cinnamon desktop:



Once the window opens, select your device from the left and the device path should be displayed(See highlight below).



If you use a different distribution, you may have to use a different method to find the disk path. Different versions of Ubuntu may also call Disk Utility slightly different names.
Now we start to backup the SD card!
We're going to be using the dd command, which looks like this:

sudo dd bs=XM if=/path/to/source of=/path/to/target

Command breakdown


"sudo" gives you root, or super user, access, allowing you to write to drives when restoring.

"dd" starts the dd program

"bs=XM" customizes block size, change "X" to preferred block size in megabytes. 4 is recommended. If you run into any issues, try changing "X" to 1.

"if=..." gives dd the image source. This can be a device or an image file.

"of=..." gives dd the target to write the image to. This can also be a device or an image file.

Running the Command


Open up a terminal by pressing Ctrl+Alt+T or opening the terminal app.
To backup the card, run the command:
sudo dd bs=4M if=/dev/sdb of=/home/ben/Pi-Backup/raspberry1.img

To restore, tun the same command but swap the source and target:
sudo dd bs=4M if=/home/ben/Pi-Backup/raspberry1.img of=/dev/sdb




Be patient, as this process could take some time.
Also remember, as a security precaution Linux will not display any character being typed when entering your root password.
NOTE: When writing an image to an SD card, all data currently on the SD card will be lost!

That's it for this time, hope this was of some help! Remember to visit our home page!

Contact us with any questions or comments!

UPDATE: Raspbian Jessie includes an application called "SD Card Copier" that can back up the SD card to a flash drive without the need to use the command line, remove the SD card, or even power down the Pi.



Afterthought: Although this article was written with the Raspberry Pi in mind, the same process applies to backing up any SD card, flash drive, or any other storage devices you want to use.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!