How to Backup your Raspberry Pi SD Card on MacOS

I have a bunch of raspberry Pis laying around waiting to be put back into action so I have done a fresh install in a RPi 3 Model B. I have installed the following:

It was lenghty process, specially compiling Ruby! This is something you want to avoid repeating as much as I possible and this is where backing up / clonning your SD card makes sense!

Backing up your SD card is not difficult but it comes with some gotchas! Will enumerate the ones I have encountered:

  1. Cloning your SD card does not mean you can go rampage and use the same configuration/setup for every Raspberry Pi model! It is important to remember that the installation process fine tune part of the configuration based on hardware. Do not be surprised if what you cloned from your RPi 3 does not work on RPi 2. It does help if you are using Raspbian Lite as there a lot less drivers available.
  2. Always use a slighty bigger SD card than the original one. For example, if you had clone an 8GB SD card then your new SD Card should be larger than that i.e. 12GB. Reason is that some times SD cards come with a number of bad blocks so their capacity can be smaller than it claims to be. You have been warned!
  3. If possible let the clonning process run overnight - the safest method is trully slow! Do not sit around waiting for this process to finish anytime soon.
  4. You may be tempted to clone your SD card directly into a folder inside Dropbox/OneDrive. Don’t!!! Syncing with cloud will make your process a lot slower, I learnt this the hard way.

I have a combination of Pis 3 Model B and B+ and the same backup works fine for all.

Perfect, let’s now have a look to the backup up process.

Plug in your SD card into your Mac

Fire up Disk Utility and look for your SD card. There are a few things we need to get deadly right:

You need to make sure you are looking at the correct disk, failing to do so it can harm/damage your laptop/desktop! Looking at the above image we need to identify the Device name disk2, Location and Connection Type. I have used a USB card reader to plug in my SD card but if you plug it directly you may see something like Secure Digital Internal Volume. SD means Secure Digital.

Some times you get to see disk2s1 in the device name. This is the logical volume the disk still disk2.

Alternatively you can run diskutil list from your terminal/iterm2 to get the same information.

Once we have identified your SD card we need to choose a location where to save your backup. I have folder in ~/Desktop/backup so from your terminal just cd into it.

cd ~/Desktop
mkdir backup
cd backup

Now to copy our SD card we will use the dd command:

Beware: In this example my disk name is disk2 in yours could be different to so do not go blindly and run the same commands

sudo dd if=/dev/rdisk2 of=name-of-my-backup.dmg

You may ask what this rdisk2 is? Didn’t we agree the name was disk2? There is no difference from location point of view. The difference comes in speed improvement. rdisk uses a different driver that makes the process a lot faster.

The above process is really slow (a few hours) but 99 out 100 you will have no errors. You can add the bs option to make the process faster:

Choose one:

sudo dd if=/dev/rdisk2 of=name-of-my-backup.dmg # Slowest but secure
sudo dd bs=1m if=/dev/rdisk2  of=name-of-my-backup.dmg # Slightly faster and should be ok
sudo dd bs=32m if=/dev/rdisk2  of=name-of-my-backup.dmg # Very fast but riskier!

You can play with any combination of bs that make sense to you. My strategy is to make the backup with the slowest/safest version and the fast version when copying to a new SD card.

You now have a backup of your memory card - You can unplug it and put it back in your Raspberry Pi.

Copy Image to a new SD card

Here we have to go through the same process of identifying the SD card correctly. Feel free to use either Disk Utility or the command line. For the sake of this post I will assume that the new SD card is in disk3 (it could have been disk2 again!).

We need to unmount the card by:

diskutil unmountDisk disk3

and to write the data to the new card you can choose one of the following:

sudo dd if=name-of-my-backup.dmg of=/dev/rdisk2 # Very Slow
sudo dd bs=32m if=name-of-my-backup.dmg of=/dev/rdisk2 # Ultra fast

When it’s finally done you can unplug your SD card and try it!

Hope it was helpful!

Comments

comments powered by Disqus