How to create a backup image of your Raspberry Pi SD on a Macintosh:


08/19/2014 - applicable to RPi B+, Sony 32GB SD, Mac OSX 10.9.4

WARNING: If you mess up on the below, you can waste the hard drive of the Mac or the SD. This is offered as friendly talk and nothing more. Learn what you are doing with root, dd, diskutil and the command line shell. I wrote this to remind myself when I have to do a backup. It may not work for you at all and could be disastrous. If you understand and agree with this paragraph, you may continue reading.

1. Pull the little SD from the Pi and put it into a USB SD convertor (looks like the old SDs only has a hole that lets you plug the micro SD in) and plug it in to a USB port.

2. Go root (type su and enter the password) in a terminal window from your mac desktop (terminal.app is in the Utilities folder of Applications).

3. Type "diskutil list" and look for the non-mac file system. Usually you can identify this because your real mac drives will have an EFI partition, and Apple HFS partitions... do not touch those. Here is mine, you can see that /dev/disk2 is the only candidate that could be the Pi SD.

sh-3.2# diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            999.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS Ench Backup             2.0 TB     disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *7.9 GB     disk2
   1:             Windows_FAT_16 RECOVERY                1.5 GB     disk2s1
   2:                      Linux                         33.6 MB    disk2s3
   3:             Windows_FAT_32 BOOT                    62.9 MB    disk2s5
   4:                      Linux                         6.3 GB     disk2s6


4. cd to a directory where you want the Pi image saved on your computer. If you don't have one, make one, like this:

mkdir /Users/yourusernameonyourmac/piimage cd /Users/yourusernameonyourmac/piimage

yourusernameonyourmac means just that, the username you use to login to your Mac.

5. Copy the SD into an image on your mac

dd if=/dev/disk2 of=./mypi.img bs=4m

6. Go to Finder and eject the SD, then physically remove it from the USB, and put it safely back in your Pi.

7. Take out your brand new micro SD that will be your emergency boot for the Pi. Stick in the USB SD device like you did the other, and plug it in.

8. Go back to the terminal window and do another diskutil list. Mine looks like this:

sh-3.2# diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            999.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS Ench Backup             2.0 TB     disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.7 GB    disk2
   1:             Windows_FAT_32 NO NAME                 31.7 GB    disk2s1


As you see in my listing above, that SD is called "NO NAME". We need to unmount that. Do so by typing:

diskutil unmountDisk "NO NAME"

Use the name yours has if it's not NO NAME. It will be something pretty generic on a new SD.

9. Copy your image onto this new SD with:

dd if=./mypi.img of=/dev/disk2 bs=4m

10. When done, go to Finder and eject that USB SD.

11. Physically remove it and go try to boot your Pi with it. If it works, great, put it in a safe place and mark it clearly as your backup.

12. On the Mac, type gzip mypi.img just to make sure you save some space. When you next need to use this image (you will not likely need to), you would have to type unzip mypi.img.gz to get it back to where you can copy it again. Do this from time to time as your schedule allows. The more often you do, the less work you lose, but it takes quite awhile to do, so you have to balance which is the greater loss.