Tag Archives: Backup

Backing up Raspberry Pi SD Cards on Mac OS X

I enjoy messing about with Arduino, Raspberry Pi, and Lego Mindstorms. At the moment I’m quite interested in constructing robots that combine all three of these devices. In the course of this messing about I quite often come across minor technical problems which are usually easily solved by consulting the web. I’ve started this blog as a way of documenting these solutions for my own benefit, and hopefully also for the benefit of others who may come across the same problems.

I’ve been using a Raspberry Pi now for more than six months, and I’ve invested quite a bit of time setting up my current Raspbian installation. Whilst SD cards are reasonably reliable, there’s always scope for data loss and corruption, so backing up the Pi’s SD card is only sensible. The Raspberry Pi Wiki has a very helpful guide to setting up an SD card for use with a Pi, but the wiki entry on SD card backup is rather limited, particularly for those looking for guidance on how to create an SD backup on Mac OS X.

Fortunately, there are a few other sources on the web that explain how to backup a Raspberry Pi SD card on Mac OS X. I found a particularly useful answer on the Raspberry Pi section of StackExchange on this topic. Most of the information provided there relates to other OSes, but if you look down the list of contributions there is a very nice summary of backing up a Raspberry Pi SD card on Mac OS X by Alex Coplan. I’ve reproduced the steps in the Raspberry SD card backup process for Mac OS X below.

1. Insert the SD card into a USB card reader, and plug it into your Mac

2. Open Terminal.app and use the following command to list the disks attached to your Mac and identify which /dev/disk corresponds to the SD card (look for the disk that includes a partition of type Linux):

diskutil list

3. Having found the identifier of the SD card, use the dd command to backup the SD card. For the case where the SD card is on /dev/disk1, the command is:

sudo dd if=/dev/rdisk1 of=/path/to/backup.img bs=1m

Notice that the dd command refers to /dev/rdisk, rather than /dev/disk. Some of the differences between these two ways of accessing a disk on Mac OS X are explained here, but the upshot is that the dd copying process is much faster if you use /dev/rdisk to access your SD card, rather than /dev/disk.

4. To restore an SD card from a backup use the following command:

sudo dd if=/path/to/backup.img of=/dev/rdisk1 bs=1m

5. It’s also possible to create compressed SD card backups as follows:

sudo dd if=/dev/rdisk1 bs=1m | gzip > /path/to/backup.gz

Restore from a compressed backup as follows:

gzip -dc /path/to/backup.gz | sudo dd of=/dev/rdisk1 bs=1m