Back Up Raspberry Pi SD Card: Full Guide
In this article
To back up your Raspberry Pi SD card, you create a full image of the card—including the operating system, settings, and files—and save it to another storage device. This guide covers the two main methods (using a computer or using the Pi itself), how to restore the backup, and common pitfalls to avoid.
Why Back Up Your SD Card
SD cards are the most common failure point in a Raspberry Pi setup. They wear out from constant read/write cycles, can be corrupted by sudden power loss, and are easily lost or damaged. A backup lets you restore your entire system to a working state in minutes, rather than spending hours reinstalling the OS and reconfiguring everything. Even if you only use your Pi for a hobby project, a backup saves you from repeating tedious setup steps.
What a Full Backup Includes
A complete SD card backup is a byte-for-byte image of the entire card. This includes:
- The boot partition (contains the firmware and kernel)
- The root filesystem (the OS and installed packages)
- Any user data, settings, and logs
- Unallocated space (if you back up the whole card, not just partitions)
Because it is a full image, restoring it puts the card back to exactly the state it was in when you made the backup. This is different from copying files to a folder, which would not preserve boot flags, partition layouts, or file permissions.
Method 1: Back Up Using a Computer (Windows, macOS, Linux)
This is the most reliable method because it works even if the Pi's OS is corrupted. You need a card reader and a destination drive with enough free space (at least the size of your SD card).
- Shut down the Pi properly (
sudo shutdown now) and remove the SD card. - Insert the card into your computer's card reader.
- Use imaging software to create a backup image. On Windows, use Win32DiskImager or Rufus. On macOS, use Apple Pi Baker or the built-in
ddcommand. On Linux, useddor GNOME Disks. - Select the SD card as the source and choose a destination file (e.g.,
pi-backup.img). - Start the backup. It can take 10–30 minutes depending on card size and speed.
Example using dd on Linux/macOS:
sudo dd if=/dev/sdX of=~/pi-backup.img bs=4M status=progress
Replace /dev/sdX with the correct device identifier for your SD card (check with lsblk or diskutil list). Using the wrong device can overwrite your computer's hard drive—double-check before running.
Method 2: Back Up Using the Pi Itself
If you cannot remove the SD card, you can create an image while the Pi is running. This is useful for remote backups, but it is riskier because the filesystem is in use. For a consistent backup, you should stop most services and avoid writing to the card during the process.
- Install a backup tool like
piclone(pre-installed on Raspberry Pi OS) or useddwith the card mounted. - For
piclone, run it from the menu or terminal. It can clone to another SD card or to a USB drive. - Alternatively, use
ddto pipe the card to a file on an external drive:
sudo dd if=/dev/mmcblk0 of=/mnt/usb/pi-backup.img bs=4M status=progress
This copies the entire card, including unused space, so the file will be as large as the card (e.g., 32 GB). To reduce size, you can compress the image with gzip:
sudo dd if=/dev/mmcblk0 bs=4M | gzip > /mnt/usb/pi-backup.img.gz
Restoring a compressed image requires decompressing it first.
How to Restore a Backup
Restoring is essentially the reverse of backing up. You write the image file back to an SD card. The card should be at least the same size as the original, or larger if you plan to expand the filesystem later.
- Insert the SD card into your computer.
- Use the same imaging tool you used for the backup (e.g., Win32DiskImager,
dd). - Select the image file as the source and the SD card as the destination.
- Write the image. This will erase everything on the card.
- After writing, you may need to expand the filesystem to use the full card size if the new card is larger. On Raspberry Pi OS, this happens automatically on first boot.
For dd restore:
sudo dd if=~/pi-backup.img of=/dev/sdX bs=4M status=progress
Common Mistakes and How to Avoid Them
- Wrong device letter: Always verify the SD card device identifier before using
dd. Mistaking/dev/sdbfor/dev/sdacan wipe your main hard drive. - Not shutting down cleanly: Removing the card while the Pi is running can corrupt the filesystem. Always shut down first.
- Backing up a corrupted card: If the card has errors, the backup may be unusable. Run a filesystem check (e.g.,
fsck) before backing up if you suspect issues. - Using a card that is too small: The destination card must be at least as large as the original card's used space. If it is smaller, the image will not fit.
- Forgetting to compress: Full images take up as much space as the card. If you are short on storage, use
gzipor a tool likepiclonethat only copies used blocks.
Choosing a Backup Tool
There are several reliable tools, each with its strengths:
- Win32DiskImager (Windows): Simple GUI, works well for both reading and writing images.
- Rufus (Windows): Primarily for writing images, but can also read.
- Apple Pi Baker (macOS): Designed for Raspberry Pi, offers compression and easy restore.
- GNOME Disks (Linux): Can create and restore disk images with a GUI.
- piclone (Raspberry Pi OS): Clones the SD card to another card or USB drive while running.
- dd (all platforms): Command-line, powerful but requires care.
For most users, a GUI tool is safer because it shows the target device clearly. If you are comfortable with the terminal, dd is fast and scriptable.
Frequently Asked Questions
How often should I back up my Raspberry Pi?
It depends on how often you change the system. If you use the Pi for a static project (e.g., a media player), a backup after initial setup is enough. If you frequently install packages or change configurations, back up weekly or before any major change. A good rule is to back up whenever you make a change you would not want to redo.
Can I back up a running Raspberry Pi without shutting it down?
Yes, but it is less reliable. Tools like piclone can clone a running system, but the filesystem may change during the copy, leading to inconsistencies. For a clean backup, shut down the Pi and remove the card. If you must back up while running, stop all non-essential services and avoid writing to the card.
Why is my backup file so large?
Because a full image copies the entire card, including empty space. A 32 GB card will produce a 32 GB image (or slightly less). If you want smaller backups, use a tool that only copies used blocks (like piclone) or compress the image with gzip. Compressed images are often 2–5 GB for a typical Raspberry Pi OS install.
Can I restore a backup to a larger SD card?
Yes, but the extra space will be unallocated until you expand the filesystem. On Raspberry Pi OS, the root partition is automatically expanded on first boot if the card is larger. If you use a custom OS, you may need to manually resize the partition using raspi-config or gparted.
Is it safe to use the same SD card for backup and restore?
Yes, but be aware that writing an image to a card erases everything on it. If you are using the same card you are backing up, you will overwrite the original data. Always back up to a different card or a computer drive, and only restore to a card you intend to wipe.
What if my backup is corrupted?
If the image file is corrupted, you may not be able to restore it. To reduce risk, verify the image after creation by comparing checksums (e.g., sha256sum) or by mounting the image to check its contents. Also, store backups on a reliable drive and consider making two copies.