arrow_back Back to Learn
Author: Raspberry Street Press

HOW TO: Backup Raspberry Pi SD Card

January, 2022

One command to rule them all! The fastest way to backup the SD card on your Pi is to make a direct copy from the running SD card onto a second SD card that has been connected via USB. Best of all, you do it all from the Pi itself! No need for another host or shutting down your Pi or transferring files.

This HOW TO assumes you have the knowledge to execute commands from a terminal window on the Raspberry Pi desktop or over an SSH connection.

Make sure you are running the latest version of Raspberry Pi OS on your Raspberry Pi 4. You can download it from Raspberry Pi. You will also need to make sure the OS is all up to date.
sudo apt update
sudo apt full-upgrade
sudo reboot

Make sure you remove ALL existing USB drives you may have connected before proceeding!

1. Connect your USB SD card reader to your Pi.

You can format your destination SD card if you want but it is not necessary. Just keep in mind everything will be erased on the destination during the backup, duh!

2. Locate your Source and Destination SD cards.

Your newly inserted USB SD card device will be located under /dev. List the devices and you'll find sda which is your destination SD Card. You'll also find the source (the SD card your Pi is currently booting and running) called mmcblk0. If you want (just to test), you can remove the destination SD card and you'll notice that sda will disappear from the listing. Connect it again, and you'll see it listed again.

cd /dev
ls

3. Run the backup with the dd command.

sudo dd bs=4M if=/dev/mmcblk0 of=/dev/sda

Just a bit of explanation on the dd command. bs=4M sets our block size to 4 megabytes. if=/dev/mmcblk0 sets our input file and of=/dev/sda sets our output file. Very simple!

If you listed the devices in the /dev folder you probably noticed other partitions named mmcblk0p1 and mmcblk0p2. We want the entire SD card and that is why we need to reference mmcblk0. The same goes the the destination sda, you may have seen sda1, sda2, etc.

As you will notice, running this command does not provide any feedback at the command line. However, you may notice that an LED on your SD card reader will start to flash, indicating activity. The time it takes to complete the backup will vary. In our case we have a 32G SD card and it took around 20 minutes.

After the command prompt comes back, you are all done! You need to test your backup, so boot it up when it's done. After that keep it in a safe place ready to use when you might need it.

You can use this method to make clones of your SD cards and provision a fleet of Raspberry Pi devices. Very handy!

Check out the video below and see how it's done!



Share this

Test drive for free today

See how Raspberry Street is revolutionizing the world of enterprise IoT – one Raspberry Pi at a time.

Dashboard

Your Cart

close
Subtotal $0.00