How to back up your Raspberry Pi SD card, or copy it to another (larger?) Raspberry Pi SD card

By: ( +David Herron; Date: December 15, 2015

Tags: Raspberry Pi » Raspberry Pi Zero

SD Cards aren't exactly the most reliable of data storage devices. What happens if you've put hundreds of hours of work into a Raspberry Pi system, it's all on your SD Card, and the card craps out. Have you saved your work? Or maybe you need to move to a larger SD Card because you've run out of space. Or maybe you want to duplicate the card to have additional systems. These tasks are pretty easy, but not intuitively obvious. It'll take some time at the command line, but fortunately the commands are easy.
Raspberry Pi Logo

The root volume of a Raspberry Pi is, by design, an SD Card. The first thing to do is to shutdown the Pi, and remove the SD Card. You won't be able to do any of these tasks in the Pi itself, and instead you'll need to use another computer. That computer will itself need an SD Card slot, or else to use an SD card reader.

Something I'm not going to cover is if your computer runs Windows. Your answer is a program called Win32DiskImager. I know nothing about using that program, and cannot tell you anything about it.

Preparation - device pathname for SD Card

On your Mac or Linux machine, all devices have a path name like /dev/sdd1. The actual pathname depends on your operating system. To discover the pathname for the SD card, you first run this command:

$ df -k

Then insert the SD card and run that command again. Once the card is inserted the operating system assigns it a pathname, and you'll see the card as new entries in the table printed by df -k. On my computer this is what's printed:

/dev/sdb2    30G   9.4G    19G   34% /media/removable/SD Card
/dev/sdb1    60M    20M    41M   34% /media/removable/boot

There are two lines shown because the Raspberry Pi OS puts two partitions on the SD card. The pathname we're interested in is the portion before the partition number. In this case that is /dev/sdb. This is the pathname of the device itself, as opposed to the pathname of a partition on the device. On other systems the pathname might be /dev/mmcblk0p1 and in such cases it is p1 which is the partition number, and therefore /dev/mmcblk0 is the device pathname.

On a Mac the /dev/rdisk<n> pathname is preferred because it is far quicker than using the /dev/disk<n> pathname.

The next step is to make sure the SD card is not mounted by the operating system. As user-friendly behavior, most operating systems automatically mount an SD card as soon as it's inserted into the computer. To do any of these tasks the card has to be unmounted.

Backing up an SD card

In this task we're going to copy an image of the SD card to your desktop computer. Later we'll see how to write that image to another SD card.

$ dd if=/dev/device-pathname of=pi-disk-image.img bs=1M

The dd command does raw copying of data. The if= option specifies the input file (if), and of course of= specifies the output file. This simply means the dd command is copying from the device file to a file on the local computer. The bs= option specifies the buffer size used while copying.

Nothing will be printed while the "dd" command is running. When it's over, a message is printed saying how much was copied:

$ dd if=/dev/device-pathname of=pi-disk-image.img bs=1M
30703+0 records in
30703+0 records out
32194428928 bytes (32 GB) copied, 3054.01 s, 10.5 MB/s

You won't be able to do much with this file - to my knowledge, but at least it's safely stored on your computer.

Writing an image to an SD card

Suppose you've faithfully made backups of your SD card, and one day it dies. Thankfully your desktop computer has backup images, so what do you do?

$ dd bs=4M if=2015-11-21-pi-disk-image.img of=/dev/device-pathname
30703+0 records in
30703+0 records out
32194428928 bytes (32 GB) copied, 3054.01 s, 10.5 MB/s

Basically, we've reversed the order of the if= and of= arguments, and told dd to copy from the saved image to the SD card.

You would do this to get running again from a backup - or to duplicate an SD card to have two identical Raspberry Pi's.

By the way, very similar instructions are on ( the Raspberry Pi website for setting up a Raspbian image downloaded from their site.

Copying to a larger SD card, and increasing the file system size

Something I skipped over is the size of the SD cards. When copying an image to a new SD card, the destination card has to be equal in size or larger to the original SD card.

What you're copying is the raw data bytes that make up the file systems and partitions on the SD card.

When those bytes are copied to a new SD card, the disk partitions will be the same size as the original SD card. If you had a 32 gigabyte SD card to start with, the partition size shown once the new card is mounted in a Raspberry Pi will be about 32 GB (minus space for the boot partition).

If you bought a 128GB SD card hoping to get more space on your Raspberry Pi, you'll be disappointed to see only 32 GB of space. Fortunately it's easy to fix this - at least under Raspbian.

Simply run " ( raspi-config" and select the Expand Filesystem option. There's a command line version available, as well as a GUI if you run the GUI desktop.

Et voila, once you've done this (and rebooted the system) the partition will have filled out the disk.

Backing up source code and other files

While it's feasible to backup system images this way, there are other ways to skin this cat. You don't have to keep the one-and-only copy of your work on the Raspberry Pi.

For example, source code should be managed using Git or other similar tools. Simply set up a Git repository elsewhere, and every so often push your changes there.

The same is true of other sorts of files. Not necessarily to use Git for everything, but to simply copy your files to other machines on a routine basis.

For example, use "rsync":

$ rsync --archive --delete project-dir/ remote-user@remote-host:/path/do/remote/project-dir/

More info

See: (

« MEADS Capability Nodes Detect website visitors running ad blockers, gently remind them your livelihood is impacted »
2016 Election Acer C720 Ad block AkashaCMS Amazon Amazon Kindle America Amiga Android Anti-Fascism AntiVirus Software Apple Apple Hardware History Apple iPhone Apple iPhone Hardware April 1st Arduino ARM Compilation Astronomy Asynchronous Programming Authoritarianism Automated Social Posting Ayo.JS Bells Law Big Brother Big Finish Bitcoin Mining Black Holes Blade Runner Blockchain Blogger Blogging Books Botnet Botnets Cassette Tapes Cellphones Christopher Eccleston Chrome Chrome Apps Chromebook Chromebooks Chromebox ChromeOS CIA CitiCards Citizen Journalism Civil Liberties Clinton Cluster Computing Command Line Tools Comment Systems Computer Hardware Computer Repair Computers Cross Compilation Crouton Cryptocurrency Curiosity Rover Currencies Cyber Security Cybermen Daleks Darth Vader Data backup Data Storage Database Database Backup Databases David Tenant DDoS Botnet Detect Adblocker Developers Editors Digital Photography Diskless Booting Disqus DIY DIY Repair DNP3 Do it yourself Docker Docker MAMP Docker Swarm Doctor Who Doctor Who Paradox Drobo Drupal Drupal Themes DVD E-Books E-Readers Early Computers Election Hacks Electric Bicycles Electric Vehicles Electron Emdebian Encabulators Energy Efficiency Enterprise Node EPUB ESP8266 Ethical Curation Eurovision Event Driven Asynchronous Express Facebook Fake News Fedora VirtualBox File transfer without iTunes FireFly Fraud Freedom of Speech Gallifrey git Gitlab GMAIL Google Google Chrome Google Gnome Google+ Government Spying Great Britain Heat Loss Hibernate Hoax Science Home Automation HTTP Security HTTPS Human ID I2C Protocol Image Analysis Image Conversion Image Processing ImageMagick In-memory Computing InfluxDB Infrared Thermometers Insulation Internet Internet Advertising Internet Law Internet of Things Internet Policy Internet Privacy iOS Devices iPad iPhone iPhone hacking Iron Man Iternet of Things iTunes Java JavaScript JavaScript Injection JDBC John Simms Journalism Joyent Kaspersky Labs Kindle Kindle Marketplace Lets Encrypt LibreOffice Linux Linux Hints Linux Single Board Computers Logging Mac OS Mac OS X Machine Readable ID macOS MacOS X setup Make Money Online MariaDB Mars Matt Lucas MEADS Anti-Missile Mercurial Michele Gomez Micro Apartments Military Hardware Minification Minimized CSS Minimized HTML Minimized JavaScript Missy Mobile Applications MODBUS Mondas Monetary System MongoDB Mongoose Monty Python MQTT Music Player Music Streaming MySQL NanoPi Nardole NASA Net Neutrality Node Web Development Node.js Node.js Database Node.js Testing Node.JS Web Development Node.x North Korea npm NY Times Online advertising Online Community Online Fraud Online Journalism Online Video Open Media Vault Open Source Governance Open Source Licenses Open Source Software OpenAPI OpenVPN Paywalls Personal Flight Peter Capaldi Photography PHP Plex Plex Media Server Political Protest Postal Service Power Control Privacy Production use Public Violence Raspberry Pi Raspberry Pi 3 Raspberry Pi Zero Recycling Refurbished Computers Remote Desktop Republicans Retro-Technology Reviews Right to Repair River Song Robotics Rocket Ships RSS News Readers rsync Russia Russia Troll Factory Russian Hacking SCADA Scheme Science Fiction Search Engine Ranking Season 1 Season 10 Season 11 Security Security Cameras Server-side JavaScript Shell Scripts Silence Simsimi Skype Social Media Social Media Warfare Social Networks Software Development Space Flight Space Ship Reuse Space Ships SpaceX Spear Phishing Spring Spring Boot SQLite3 SSD Drives SSD upgrade SSH SSH Key SSL Swagger Synchronizing Files Telescopes Terrorism The Cybermen The Daleks The Master Time-Series Database Torchwood Total Information Awareness Trump Trump Administration Trump Campaign Ubuntu UDOO Virtual Private Networks VirtualBox VLC VNC VOIP Web Applications Web Developer Resources Web Development Web Development Tools Web Marketing Website Advertising Weeping Angels WhatsApp Window Insulation Wordpress YouTube YouTube Monetization