Create a raw backup of a device with dd

I am sure there are lots of clever programs for backing up memory cards or disks with pretty graphic interfaces but there is a very simple command-line for doing that called “dd”. It simply copies an entire file to another completely as a mirror image. How is that useful? Remember Linux sees every device as a file. This means your SDCARD you have plugged in can be copied away. So does that USB disk or even your hard disk. All you need is a spare place to copy the device to and the dd command.

Before you start make sure the device is not mounted or being used. The clone will work but the resulting information might be horribly corrupt

df -h
and maybe run
ps -aux | grep DEVICE_NAME
ps -aux | grep sdc1

to make sure the device is not being used by a process. If everything is ok run

dd if=DEVICE of=/path/file

dd if=/dev/sdc of=/pi-sdcard.dd

The file does not need to be called .dd it is just a handy way to end a filename when you go back to it.
Once it is finished you can compress the file as it will be the same size as the source. A 16Mb SDcard will create a 16Mb file and a 20Gb USB disk will create a 20Gb file.

A image file like this can be investigated like a real device so

sfdisk -l /pi-sdcard.dd

will show what partitions are in the image

You restore an image by running a very similar command just with the if and of reversed so

dd if=/path/fileDEVICE of=DEVICE

dd if=/pi-sdcard.dd of=/dev/sdc

Finally for storage you probably want to compress the file. For example using gzip –

gzip /pi-sdcard.dd