Chapter 11 - Backup and restore the microSD card¶
In this chapter, you will learn how to clone and replicate the microSD card to be able to deploy multiple Raspberry Pi.
The first step is to backup the microSD card. This will create an exact copy of the microSD card on your disk.
The second step is to shrink the the microSD card image to the minimum size possible. This will allow to write the image to a smaller microSD card in a faster manner.
The third step is to write the newly shirked image to a new microSD card. This will create a new microSD card that you can use to deploy a new Raspberry Pi.
Steps¶
Backup the microSD card¶
Raspberry Pi Imager cannot backup a USB drive to an image. You will have to use another software to backup the microSD card. The backup might take a while depending on the size of the microSD card.
If not already done, shutdown the Raspberry Pi and unplug the microSD card.
Plug the microSD card into your computer.
Download and run USBImager for your platform.
In USBImager, select a path to save the image. For the next steps, we will assume that the image is named rpi-clone.img
.
Select the microSD card from the list.
Press "Read" to start the backup.
For the next steps, we will assume that the image is named rpi-clone.img
.
If not already done, shutdown the Raspberry Pi and unplug the microSD card.
Plug the microSD card into your computer.
Open a terminal.
On Linux: identify the microSD card device with the following command: fdisk -l
. For the next steps, we will assume that the device is named /dev/mmcblk0
.
On macOS: identify the microSD card device with the following command: diskutil list
. For the next steps, we will assume that the device is named /dev/disk2
.
Backup the microSD card to an image with the following command. Replace <device>
with the device name from the previous command and <image>
with the path to the image file. For the next steps, we will assume that the image is named rpi-clone.img
.
In a terminal, execute the following command(s). | |
---|---|
The output of the command should look similar to this.
Optional: Shrink the microSD card image¶
Shrinking the microSD card image will allow to write the image to a smaller microSD card.
If you do not shrink the image, you will have to use a microSD card of the same size or bigger than the original one.
Shrink the image with PiShrink with Docker. This will take a while depending on the size of the microSD card.
In a terminal, execute the following command(s). | |
---|---|
The output of the command should look similar to this.
You now have a shirked image that you can use to deploy a new Raspberry Pi.
Restore the microSD card image to a new microSD card¶
Follow the instructions from Chapter 2 - Write the image(s) on a microSD card to write the backup image to a new microSD card. Instead of the official Raspberry Pi OS image, you will have to select the backup image.
Check the results¶
Follow the instructions from Chapter 4 - Start and log in on the Raspberry Pi to start and log in on the Raspberry Pi.
If you have restored the shrunk version of the image, the Raspberry Pi should reboot once to resize the partition to its maximum size.
Everything should work as expected from the previous chapters.
Summary¶
Congrats! You have cloned and replicated the microSD card to be able to deploy multiple Raspberry Pi. The backup image can be used to deploy a new Raspberry Pi in case of a failure.