How to clone Raspberry PI operating system

I’ve been playing around with RPIs lately, and I’ve found it handy to take snapshots of my Micro SD card as I’m messing around, so that I’ve got backups when something inevitable goes wrong.

First, you need to find the device (the Micro SD card). To my understanding it’s always something like /dev/sdb or /dev/mmcblk0p1. For me it happens to be the latter.

You can do an ls on the /dev (device) directory:

$ ls -l /dev

Then, check which drives are actually mounted currently:

$ df -h

You should see something like mmcblk0p1 or sda there.

Then make the image with dd:

$ sudo dd bs=4M if=/dev/mmcblk0p1

It’s smart to pipe that right into into gzip to save a bit of time:

$ sudo dd bs=4M if=/dev/mmcblk0p1 | gzip > raspbian.img.gz