Cloning/Backing Up Raspberry Pi using a Mac

This grew out of the need to create multiple SD card Raspbian images for my Raspberry Pi Hadoop cluster. I was constantly experimenting and really wanted not to create the Raspbian OS from scratch every time (note that Raspbian OS is really Linux of the Debian variant).

I sought about how to create an image file of a Raspbian installation so I could flash the image to an SD card when I needed a fresh Raspbian OS installed.

A running Raspbian OS installation configured as necessary is required.That installation’s SD card is used to create the image and clones.

Cloning doesn’t really save time, the time taken to write the image a scratch SD card is the same as writing the clone image, but it saves on errors from human forgetfulness and typing. It also makes the base configuration easy as Pi (LOL), known and fixed.

First thing to know is the size of the source SD card matters. The disk image can only be flashed to an SD card of the same or larger size. I chose 16GB size as they are readily available for a reasonable price.

First, I use Mac’s Disk Utility tool. Applications -> Utility-> Disk Utility app.

Second, I insert the micro SD card with a Raspbian OS installation into the micro SD card reader and then insert the reader in the Mac’s USB port. A new disk shows up in Disk Utility.

Third, I click on the disk and then click on the “New Image” item on the menu bar on top, choosing “DVD/CD Master”as the Image Format and click “Create”. I use cloneimage.cdr as the filename, this will actually create an .ISO file, it will create the image file to be used later to clone an installation.

Whenever I need a new Raspbian installation I do the following.

First, I insert a new micro SD card in the card reader and insert the reader in your Mac’s USB port.

Second, I launch the Terminal utility application from Applications -> Utility. I enter “diskutil list” and make note of the disk name, this would be in the form of /dev/diskN where N is a number. I typically find the right disk by looking at the SIZE column and find my 16GB card that way.

Third, I unmount the disk using: “diskutil unmountdisk /dev/diskN”

Forth, this step overwrites the card in the reader. WARNING: this step will not pause for confirmation. If the wrong disk is specified, that disk will be overwritten, so I’m very careful and double check. Enter: “sudo dd if=cloneimage.cdr of=/dev/rdiskN bs=10m”

Fifth, well, I wait until the image has finished writing, there is no ongoing progress status output but pressing Ctl-T will print some status information.

About the only indication is the app finishes running and the console prompt shows again.

That’s it, the only way to know is to boot up the new Pi with the new card.

Cleanup, I usually clean up the new Pi by changing the hostname, if I picked an installation with a static IP address then I’ll update the static IP address. Depending on the installation, sometimes I also change users and passwords.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s