It’s a lot of fun to start a new Raspberry Pi project. It’s a little less fun, though, to redo one that you already worked hard on. That’s why it pays to back up your Raspberry Pi’s storage on your PC or Mac. And, since the Raspberry Pi uses a microSD card for storage, creating a backup of your Raspberry is quite easy on any platform. Here’s how to back up your Raspberry Pi’s SD card on Windows, macOS, or Linux – and how to restore it from that backup, too.
First things first: shut down your Pi safely (how you do this will depend on the OS you’re running – for Raspbian, it’s just sudo shutdown now in the command line) and remove your microSD card. Then put the card in your computer’s card reader and meet us down in whatever section is relevant to your computer’s operating system.
How to back up your Raspberry Pi’s SD card on Windows
Step 1: Open Win32 Disk Imager
You may recognize this program from our guide to installing Raspbian. It’s our go-to for SD card writing and re-writing, and we’ll use it here, too. If you don’t have it yet, you can download it here.
Step 2: Set the drive and destination folder
In Win32 Disk Imager, use the drop-down menu labeled Device to choose the drive that corresponds to your SD card. Then click the little button with the folder on it and select the folder that you want your backup to end up in – but don’t hit Open quite yet. Type a new filename into the File name: box – this will be the file name of your backup. The file type will be .img by default, which is good, because that’s what you want. You can go ahead and hit Open now.
Step 3: Write the file
Now just hit the Read button – which should be easy enough to do, especially since Win32 Disk Imager will gray out the Write button when it sees that the .img file you’ve chosen doesn’t exist (yet). Your work here is done! Win32 Disk Imager will do the rest. Eject your SD card when it’s all done and keep enjoying your Pi with a little extra peace of mind.
Restoring your Raspberry Pi on Windows
If that grim day comes that you have to use this little backup, you’ll find the process looks very familiar. Once again, you’ll put an SD card in and select the proper drive from the drop-down window. Once again, you’ll select your .img file – only this time, of course, it will already exist! And since it already exists, you’ll see that the Write button is a viable option. That’s exactly what you should hit, of course, and once you do Win32 Disk Imager will replace whatever is on your SD card with the backup disk image. Easy!
How to back up your Raspberry Pi’s SD card on macOS
Step 1: Open the Terminal and find your SD card
Open up Terminal on your Mac and enter this command:
This is going to list every drive in your Mac, but identifying your SD card is as easy as spotting the one that’s roughly the right size. Jot down the location of the drive.
Step 2: Back up your SD card in Terminal
Now that you know where your SD card is, you can refer to it in a command asking your Mac to back it up. Here’s the command:
sudo dd if=/dev/disk1 of=~/MyPiBackup.dmg
The first part in bold is the location – it may look different for you. The second part is the file name of the image we’re creating, and you can of course feel free to change that to whatever you want. You’ll have to wait a while and won’t get a progress bar or anything to watch, so go have a cup of coffee or something. Eventually, you’ll be all set with a backup copy of your Pi’s SD card.
Restoring your Raspberry Pi on macOS
If something goes wrong and you need to restore your Raspberry Pi’s SD card, you’ll have to open Terminal back up and once again run diskutil list. Track down your SD card again, and enter this command (with the location of yours replacing the part in bold):
diskutil unmountDisk /dev/disk1
Now we can re-write the SD card from our backup.
sudo dd if=~/MyPiBackup.dmg of=/dev/disk1
Again, the bold parts might look different for you: the first is whatever you named your backup, and the second is the location of the SD card. And, as with creating the backup, this will be a long and lonely process. Grab another coffee. Once the SD re-write is finished (and you’ve finished that coffee), you can eject your SD card.
sudo diskutil eject /dev/rdisk3
How to back up your Raspberry Pi’s SD card on Linux
Step 1: Find your SD card
In the command line, enter this:
That will list all of your drives. Which one is your SD card? If you can’t figure it out, try running the command before you stick the card in (I know, we told you at the top to put it in already – sorry). Then add the card and run the command again. The newcomer is the one you want. Jot down the location listed in the Filesystem column.
Step 2: Back up the SD card in Terminal
Thanks to their shared UNIX ancestor, Linux and macOS also share an identical step in this guide. Here’s the command you’ll need next, which is what we used in Step 2 for the Mac, too:
sudo dd if=/dev/sda of=~/MyPiBackup.img
As with the Mac version, the two parts in bold will vary: the first should be whatever location you wrote down in Step 1, and the second can be any file name you want to use for your backup. As with Mac, you’ll have to wait around without any word from your computer about how things are going. Trust it to do the job and go run an errand, or something. When it finally finishes up, you’ll have your backup.
Restoring your Raspberry Pi on Linux
So you need to restore your SD card? No problem. Back to the command line we go. Find your SD card once again with df -h. Then unmount it with this command:
sudo unmount /dev/sda1
Swap out the bold part for whatever location is listed for your SD card under Filesystem in the list the df -h command returned. Now run this command, once again swapping out the bold parts (first is whatever file name you gave your backup, and the second is the location of the SD card again):
sudo dd bs=4M if=~/MyPiBackup.img of=/dev/sda
Again you wait without any feedback. Run more errands, drink more coffee, and return to find your Pi’s SD card restored. Hooray!