Disk image raspberry pi: How to Back Up Your Raspberry Pi as a Disk Image

How to Back Up Your Raspberry Pi as a Disk Image

(Image credit: Tom’s Hardware)


When you work hard on a Raspberry Pi project, you’ll want to make a complete disk backup of the entire OS and software, not just your code. Even the best Raspberry Pi microSD cards can fail or get lost and you may also want to re-use the project on another card or share it with others. For example, at Tom’s Hardware, we have a Raspberry Pi web server we use for battery tests and we have multiple Pis that all have the same exact image.

There are a few ways to backup a Raspberry Pi. You can use Raspberry Pi OS’s SD Card Copier app, which is under the Accessories section of the Start menu, to clone your microSD card directly to another microSD card. But unless you need a second card right away, it’s a better idea to create a disk image: a file you can store on a PC or in the cloud, distribute to others and write to a new microSD card at any time, using Etcher or Raspberry Pi Disk Imager.

Some folks recommend taking your microSD card, sticking it in a Windows PC and copying it sector-for-sector with Win32 Disk Imager, but that creates two problems. First, the card you are writing to has to be exactly the same size as the one you backed up or larger. Because there are subtle differences in the number of sectors on different makes and models of card, a 32GB San Disk card may have a few more sectors than a 32GB Samsung card and, if the destination card is smaller, the copy process won’t work properly and the card won’t boot. Second, your backup file will be huge: the full size of your card, even if you only were using 3 out of 32GB.

Fortunately, there’s a way to create a compressed disk image that’s even smaller than the amount of used space on the source microSD card you’re backing up. To create the disk image, you’ll need an external USB drive to connect to your Raspberry Pi and write it to. If the USB drive is a higher capacity than the source microSD card (ex: a 32GB USB drive to image a 16GB card), you can back up the whole card before shrinking it. However, if you don’t have a USB drive that’s big enough, check out the section at the bottom of this article on shrinking your rootfs partition. 

 How to Make a Raspberry Pi Disk Image 

1.  Format a USB Flash or hard drive as either NTFS (if you are using Windows on your PC and plan to read this drive on a PC) or EXT4 (for Linux). Make sure the Flash drive is larger than the capacity of the used space. Make sure to give the drive a volume name that you remember (ex: “pibkup” in our case). You can also format the drive directly on the Raspberry Pi if you like.  

(Image credit: Tom’s Hardware)

2.  Connect the USB drive to your Raspberry Pi.

3. Install pishrink.sh on your Raspberry Pi and copy it to the /usr/local/bin folder by typing: 

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
sudo chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin

 4. Check the mount point path of your USB drive by entering 


(Image credit: Tom’s Hardware)


You’ll see a list of drives connected to the Raspberry Pi and the mount point name of each. Your USB drive will probably be mounted at /media/pi/[VOLUME NAME]. In our case, it was /media/pi/pibkup. If your drive isn’t mounted, try rebooting with the USB drive connected or you can mount it manually by typing sudo mkdir /dev/mysub to create a directory and sudo mount /dev/sda1 /dev/myusb to mount it. However, you can’t and shouldn’t do  that if it’s already mounted.

5. Copy all your data to an img file by using the dd command. 

sudo dd if=/dev/mmcblk0 of=[mount point]/myimg.img bs=1M

However, if you shrank a partition on the source microSD card, you’ll need to use the count attribute to tell it to copy only as many MBs as are in use. For example, in our case, we had had a 16GB card, but after shrinking the rootfs down to 6. 5GB, the card only had about 6.8GB in use (when you count the /boot partition). So, to be on the safe side (better to copy too much data than too little), we rounded up and set dd to copy 7GB of data by using count=7000. The amount of data is equal to count * block size (bs) so 7000 * 1M means 7GB. 

sudo dd if=/dev/mmcblk0 of=[mount point]/myimg.img bs=1M count=7000

(Image credit: Tom’s Hardware)

Only do this if you have previously shrunk the partition. If you use count and copy less than the full partition you could have an incomplete image that’s missing data or won’t boot. 

6. Navigate to the USB drive’s root directory.

cd /media/pi/pickup

7.  Use pishrink with the -z parameter, which zips your image up with gzip. 

sudo pishrink.sh -z myimg.img

(Image credit: Tom’s Hardware)

This process will also take several minutes but, when it is done, you will end up with a reasonably sized image file called myimg. img.gz. You can copy this file to your PC, upload it to the cloud or send it to a friend.  

How to Shrink a Partition on Raspberry Pi 


If you want to make a disk image of a microSD card, but don’t have an external USB drive of a greater capacity, you have a problem. Even though the eventual .img.gz file you create in the tutorial above should be much smaller than your source card, you still need enough space to accommodate the uncompressed .img file as part of the process. 

What’s particularly frustrating is that, by default, the dd file copy process makes an image out of ALL the space on your microSD card, even the unused space.For example, you might have a 64GB microSD card, but only be actually using 6GB of space. If you don’t shrink the rootfs partition, you will end up copying all 64GB over to your external drive, which will take a lot more time to complete and will require that you have at least 65GB of free space. 

So the solution is to shrink the rootfs partition of your microSD card down to a size that’s just a little bit bigger than the amount of used space. Then you can copy just your partitions over to the USB drive.

To do the shrinking, you’ll need a USB microSD card reader and a second microSD card with Raspberry Pi OS on it.

1. Put your source microSD card (the one you want to copy) in a reader and connect to your Raspberry Pi.

2. Boot your Raspberry Pi off a different microSD card.

3. Install gparted on your Raspberry Pi.

sudo apt-get install gparted -y

4.  Launch gparted from within the Raspberry Pi OS GUI. It’s in the System Tools section of the start menu. 

(Image credit: Tom’s Hardware)

5.  Select your external microSD card from the pull down menu in the upper right corner of the gparted window. 

(Image credit: Tom’s Hardware)

6. Unmount the rootfs partition if it is mounted (a key icon is next to it) by right clicking it and selecting Unmount from the menu. If the option is grayed out, it’s not mounted. 

(Image credit: Tom’s Hardware)

7.  Right click rootfs and select Resize / Move. 

(Image credit: Tom’s Hardware)

8.  Set the new size for the partition as the minimum size or slightly larger and click Resize.. Note that gparted may overreport the amount of used space (when we unmounted a partition with 4.3GB used, it changed to say 6GB were in use), but you have to go with at least its minimum. 

(Image credit: Tom’s Hardware)

9.  Click the green check mark in the gparted window and click Apply (when warned) to proceed. 

(Image credit: Tom’s Hardware)

10. Shutdown the Raspberry Pi.

11. Remove the source microSD card from the USB card reader and insert it into the Raspberry Pi to boot from.

12. Follow the instructions in the section above on creating a disk image. Make sure to use the count attribute in step 5.  

 Writing Your Raspberry Pi Disk Image to a Card 

 Once you’re done, you’ll have a file with the extension .img.gz and you can write or “burn” it to a microSD card the same way you would any .img file you download from the web. The easiest way to burn a custom image is to: 

1.  Launch Raspberry Pi Imager on your PC. You can download Raspberry Pi Imager if you don’t have it already. 

(Image credit: Tom’s Hardware)

2.  Select Use custom from the Choose OS menu. 

(Image credit: Tom’s Hardware)

3.  Select your .img.gz file

4.  Select the microSD card you wish to burn it to. 

(Image credit: Tom’s Hardware)

5.  Click Write

(Image credit: Tom’s Hardware)

Get instant access to breaking news, in-depth reviews and helpful tips.

Contact me with news and offers from other Future brandsReceive email from us on behalf of our trusted partners or sponsors

Avram Piltch is Tom’s Hardware’s editor-in-chief. When he’s not playing with the latest gadgets at work or putting on VR helmets at trade shows, you’ll find him rooting his phone, taking apart his PC or coding plugins. With his technical knowledge and passion for testing, Avram developed many real-world benchmarks, including our laptop battery test.


Raspberry Pi

Introducing Raspberry Pi Imager, our new imaging utility

We’ve made a simpler way to image your microSD card with Raspbian, the official Raspberry Pi operating system, and other operating systems. Introducing our new imaging utility, Raspberry Pi Imager.

Simplifying the Raspberry Pi experience

For me, one of the most important aspects of the Raspberry Pi experience is trying to make it as easy as possible to get started.  To this end, since launching the first Raspberry Pi, we’ve added a GUI to our operating system, a wizard to help you set up your Raspberry Pi the first time you boot it, and lots of books and magazines to get people up and running.   We’ve even developed the Raspberry Pi Desktop Kit to put all the things you need (yes, Alex, I know – except for a monitor) into a single box to make it as easy as possible!

SD cards can be a bit tricky

Despite all these moves towards more simplicity, when it comes to microSD cards, programming them with your favourite Raspberry Pi operating system has always been a little bit tricky.

The main problem comes from the differences between the operating systems that people’s main computers are likely to use: Windows, macOS, and Linux all use different methods of accessing the SD card, which doesn’t help matters. And, for some new Raspberry Pi users, understanding where to find the latest up-to-date image and how to get it onto the microSD card can be a bit confusing, unless you’ve had prior experience with image-flashing tools such as Etcher.

For that reason, we’ve always suggested that you should buy a pre-loaded NOOBS SD card from your Raspberry Pi Approved Reseller.

But what if you want to re-image an existing card?

Introducing the new Raspberry Pi Imager

From today, Raspberry Pi users will be able to download and use the new Raspberry Pi Imager, available for Windows, macOS and Ubuntu.

The utility is simple to use and super speedy, thanks to some shortcuts we’ve introduced into the mechanics.

Firstly, Raspberry Pi Imager downloads a .JSON file from our website with a list of all current download options, ensuring you are always installing the most up-to-date version.

Once you’ve selected an operating system from the available options, the utility reads the relevant file directly from our website and writes it straight to the SD card. This speeds up the process quite considerably compared to the standard process of reading it from the website, writing it to a file on your hard drive, and then, as a separate step, reading it back from the hard drive and writing it to the SD card.

During this process, Raspberry Pi Imager also caches the downloaded operating system image – that is to say, it saves a local copy on your computer, so you can program additional SD cards without having to download the file again.

Open source and ready to go!

Download the Raspberry Pi Imager from our downloads page today.

Raspberry Pi Imager is fully open source and was originally written as a modification of the PiBakery tool, later modified and finished by Floris Bos (the original writer of the NOOBS tool and the PiServer tool). You can see Floris’ other software, for data centres, here.

Write Raspberry Pi OS image to microSD card [Amp / Wiki]

The Raspberry Pi requires an operating system, which is stored on a microSD card.

Raspberry Pi OS (formerly called Raspbian) is the official supported operating system for the Raspberry Pi. In addition to Raspberry Pi OS , you can use others such as Ubuntu, RetroPie, RISC OS Pi, LibreELEC and others.

Raspberry Pi Imager

Raspberry Pi Imager is a program with which you can burn the desired system image to a microSD card.

Download and prepare

  1. Download Raspberry Pi Imager and install on your computer with UBUNTU . Type sudo snap install rpi-imager in a terminal window.

  2. Launch Raspberry Pi Imager. Type in terminal rpi-imager ;

  3. Connect the microSD card to the computer;


Format microSD card

  1. Format the microSD card in FAT32 format before writing a new image. To do this, click CHOOSE OS in the Raspberry Pi Imager window;

  2. Select Erase from the dropdown list ;

  3. Press CHOOSE SD CARD ;

  4. Choose your card from the list;

  5. Press WRITE ;Formatting starts. This will take several minutes. nine0003

  6. Raspberry Pi Imager will notify you when formatting is complete by popping up a dialog box. Press CONTINUE ;

Write system image

  1. Now let’s start recording a new image. Open the list of systems;

  2. Select the image of the system you want to write to your card;

  3. Press CHOOSE SD CARD ;

  4. Choose your card from the list;


  5. Press WRITE ;The writing process will start. This will take several minutes.

  6. Raspberry Pi Imager will notify you when recording is finished by popping up a dialog box. Press CONTINUE ;

  7. Now you can get the system image card and use it in your Raspberry Pi.

Writing saved system images

In addition to official systems, you can burn saved ones. For example, an image of Raspberry Pi OS from Amperka, with SSH, VNC, and other additional settings enabled.

  1. Format the microSD card in FAT32 format before writing the image;

  2. In the Raspberry Pi Imager window, open the system list and select Use custom ;

  3. Find the saved image file on your computer, select it and click Open ;

  4. Follow the instructions starting from step #3.


  • Raspberry Pi Imager for Windows;


  • Raspberry Pi Imager for macOS;

  • Raspberry Pi Imager for Ubuntu x86;

  • Raspberry Pi OS image from Amperka.

How to backup a Raspberry Pi

The first thing a novice Raspberry Pi user should master after installing and configuring the Raspbian OS is the ability to make backups.

In the case of the Raspberry Pi, a backup is an image taken from a microSD card with Raspbian OS and a set of applications installed and configured. nine0003

We can say that by making a backup, we create our own version of the Raspbian distribution. Or we make our build from the original Raspbian and the set of third-party applications used in this particular case.


  • 1 What will we need
  • 2 BECAP RASPBERRY PI for Windows
  • 3 RASPBERRY Pi Backup under Linux
  • 4 Backup RASPBERRY PIP under the MacOS
  • 5 Prepare

    1)0002 To implement the steps described in this article, you will need:

    • Raspberry Pi 3 Model B
    • Card Reader or capable of replacing it
    • Computer running Windows, Linux, or macOS

    Raspberry Pi backup under Windows

    To create a Raspberry Pi backup under Windows, you need the free Win32 Disk Imager program, which can be downloaded from its SourceForge page:

    «raspberries» enter the name of the file into which the image will be written, and press the «Read» button:

    The process has begun. The program fully reads the contents of the microSD into an IMG file.

    Therefore, by the way, it is unprofitable to use large memory cards as a Raspberry Pi system drive — they will all be read in their entirety, and keeping backups weighing 32-64GB each on a computer is, to put it mildly, inconvenient.

    The optimal microSD size for Raspberry Pi in my opinion is 8GB. Maximum 16GB. More is already too much, it is better to use USB drives for storing files. nine0003

    Restoring a Raspberry Pi from a backup is done through the same Win32 Disk Imager program. You need to specify the path to the saved image file and click the «Write» button:

    After that, the card will be the data from the image we took:

    You can put it back into the raspberry and use it.

    After restoring the system, the created connections with Bluetooth devices disappear from the backup — you need to re-pair, but all other settings are saved. nine0003

    Raspberry Pi backup under Linux

    On Linux systems, you can backup your Raspberry Pi using the dd system utility.

    To do this, enter the following command in the terminal:

     sudo dd if=/dev/mccblk0 of=/home/Username/Desktop/raspberrypi-backup.img 

    -map, and «of=» contains the path to the image file, in which the contents of this map will fit.

    Respectively, instead of /dev/mccblk0 and /home/Username/Desktop/raspberrypi-backup.img you need to enter your paths.

    The path to the mounted microSD card can be viewed by executing the console command: «if»:

     sudo dd if=/home/Username/Desktop/raspberrypi-backup.img of=/dev/mccblk0 

    Raspberry Pi backup under macOS

    Since macOS is also a *nix system, the process of backing up a Raspberry Pi on this operating system will not be drastically different from the above described backup procedure under Linux.

    Only the path to the mounted microSD card is looked through the Disk Utility program:

    And then the same dd command is executed to write the memory card image to a file:

     dd if=/dev/disk2 of =raspberrypi-backup.