# 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.

My external drive hooked to the PI with a USB 3 cable occupies the name
`/dev/sda`.

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

```shell
$ ls -l /dev
```

Then, check which drives are actually mounted currently:

```shell
$ df -h
```

You should see something like `mmcblk0p1` or `sda` there.

Then make the image with `dd`:

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

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

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