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
Advertisements

7 thoughts on “Backing up Raspberry Pi SD Cards on Mac OS X

    1. lcww1 Post author

      Hi Noel,

      Thanks for commenting, and also apologies for the very long delay in approving your comment and responding!

      The unmount is only needed when restoring a previous SD card backup – so I suppose the unmount command should precede the commands given in sections 4. and 5. – restoring an SD card backup is essentially the same operation as writing a Raspbian image to an SD card and the instructions shown are very clear.

      Thanks again for commenting, and I’ll update the blog post at some stage to take account of your comment,

      Regards,

      lcww1

      Reply
  1. Biffer Rowley

    Just done a backup of some pretty major work! Thanks for this info. BTW i found it’s worth investing in a decent SD Card (Am using the Samsung ones). They seem to handle unplanned powerouts better than the cheap ones on the market. Thanks again!

    Reply
    1. lcww1 Post author

      Stephen,

      I’m really sorry about the ridiculous length of time it’s taken me to reply to your comment! I do hope you managed to find your way in the meanwhile?

      Just in case you still need help, and in case anyone else encounters a similar problem, here’s what’s up: where I give the example commands in sections 3, 4, and 5 I have used /path/to/backup.img as an example of the path to the backup output file called, in this case, backup.img. The /path/to/ bit is the “path”, and in actual real usage you need to replace this with a real “path”, for example: /Users/lcww1/mybackups/ – the actual “path” depends on your system. The name of the backup file can be anything that your Mac will allow, but the filename should have the suffix .img so that the file is recognised as a disk image.

      I hope that explanation is helpful, and apologies once again for neglecting the comments on this blog! Lastly, thanks for commenting on the blog, and in the light of your comment I’ll see about revising the instructions to make them clearer.

      Best wishes,
      lcww1

      Reply
  2. Pingback: Backing up Raspberry Pi SD Cards on Mac OS X | the technology cave

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s