How to back up and restore your Raspberry Pi SD card to your Mac

I periodically take a “snapshot” of my Raspberry Pi’s SD cards, especially before I make a major change, by copying the SD card image to one of my Macs.  Subsequently, that image file gets backed up again by Time Machine running on the Mac. This allows me to return the pi to some determinate state if the card gets corrupted or if I mess something up experimenting.

Note these instructions are for Mac OS X but you can probably figure out other platforms by looking at this page.

These are Terminal commands. Therefore…
DISCLAIMER: if you don’t know what you’re doing on the command line leave this post now. I take no responsibility for you obliterating either your Mac or your SD card. I use both of these procedures on a regular basis but again, you need to understand what you’re doing here, don’t just type away blindly.

Back up the SD card to OS X:

  1. Type “diskutil list” to find the SD Card (it’s helpful to do this before you insert the SD card into your reader, it will be obvious which one is the pi’s SD card). If your Mac doesn’t have an SD card reader you can find a USB card reader fairly cheap, such as this one.
  2. Note the disk number of SD card. I’ll use disk2 in this example.
  3. Type “sudo dd if=/dev/disk2 of=~/Desktop/raspberrypi-[date].img” to create a disc image of the SD card on the desktop.
    Obviously you can supply a directory path there other than Desktop.
    Note: If you are running as a non-admin user on a Mac, type “su <adminusername>” and it will prompt you for the password for that account. This will switch your session to an admin session. Then include the sudo in the command above and type the admin user password again.

Restore the SD card from an OS X back up:

  1. Type “diskutil list” before you insert the card so it’s obvious which one is the SD card.
  2. Insert a blank SD card into the Mac’s SD card reader. If your Mac doesn’t have an SD card reader you can find a USB card reader fairly cheap, such this one.
  3. Type “diskutil list” to find the SD Card to be restored. I’ll use disk2 in this example. Again, you need to know what you’re doing here. Don’t blame me if you wipe out your Mac’s system drive. If you don’t understand these commands don’t type them into a terminal window.
  4. Unmount the SD card with this command: “diskutil unmountDisk /dev/disk2”.
  5. Format the SD Card: “sudo newfs_msdos -F 32 /dev/disk2”. Make damn sure you’ve got the correct disk number.
  6. To restore from the SD card image in the backup sample above: “sudo dd if=~/Desktop/raspberrypi-[date].img of=/dev/disk2”. This may take a very long time and you’ll get no feedback while it’s working. Don’t touch anything until you get the command prompt again, it will give you a summary of the blocks written when it’s complete.