How to Clone Raspberry Pi SD Card on Windows, Linux and macOS

The Raspberry Pi is the ideal toy for hackers. The majority of its users love to explore and, in the process, destroy functional installations. Everyone enjoys having a functional baseline setup that they can go back to after the experiment, despite how much fun it is.

Another typical case is when you have recently learned about a fantastic new Linux distribution or Raspberry Pi-based project and are itching to give it a try. You only have one micro SD card, but it already has a functioning installation on it that you do not want to lose. This is the problem.

It is advantageous to have a complete, identical backup of your operational Raspberry Pi installation in both of the aforementioned cases. In order to restore the image after our experiments are complete, we will learn how to clone or backup the Raspberry Pi micro SD card to an image file today. Windows, Linux, and macOS will all be covered in detail.

Recall that using this technique will result in an image file exactly the size of the SD card’s complete storage space. No of how much space your installation actually uses, if you have a 16 GB SD card, the resultant image file will also be 16 GB. There is a way to reduce the image size, but it only functions on Linux. We will go over this method later in the course.

Windows Instructions

Backup Raspberry Pi SD Card

1. Use a USB port or the PC’s built-in card reader to insert the micro SD card you want to copy into the device.

2. Run Win32DiskImager after downloading and installing it. You’ll see a display similar to this:

3. Select the drive for your SD card under the Device section in the top right corner. It is in my situation. Now select a location and a filename for the picture file to be saved by clicking on the folder icon to the left of the image. Raspbian backup 19 oct.img was my choice. Although you can use any filename, it is advised to use the.imgextension. Once finished, press the Read button.

4.The SD card will be copied in the place you chose. It will take some time for the copying to finish, so avoid turning off or sleeping your computer during this time. You will receive a Read Successful notification after it is finished.

You can now mess around or instal a fresh distribution on your Raspberry Pi by re-inserting the card. If you want to restore the backed-up image once you’ve finished playing, follow the instructions in the following section.

Restore Raspberry Pi SD Card

Open Win32DiskImager and insert the micro SD card into your computer.

Choose the proper drive in the Device section and the image file you already prepared. Click the Write button now. The image will be preserved on the SD card in exactly the same form as when it was duplicated.

Linux Instructions

Backup Raspberry Pi SD Card

Again, depending on the size of the SD card, this procedure will take some time. You can take the card out of your PC and put it back in the Raspberry Pi after the restore is finished.

1.Use a USB port or the PC’s built-in card reader to insert the SD card. Currently, open a Terminal window and type the instructions sudo fdisk -l. This will provide a list of every filesystem on your system.

2. Attempt to identify the name of the SD card’s device. I have a 16GB SD card, thus it is quickly recognised as the 14.9GB device/dev/sdb. This is due to the fact that a device’s actual storage is almost never as large as what is claimed. Record the name of this gadget.

3. To write the image to your hard drive, use the ddcommand. For instance:

/raspbian backup.img sudo dd if=/dev/sdb

The file to copy is specified in this case by theifparameter (input file). In my situation, the device name for my SD card is /dev/sdb. Change it to the name of your device. The name of the file to write to is specified by the ofparameter (output file). Raspbian backup.img is what I put in my home directory.

Note:Be careful and confirm the parameters before running theddcommand because entering the incorrect values here could potentially wipe out the data on your discs.

Depending on the size of your SD card, it can take some time before you get any output from the command. You won’t see anything until the cloning is finished. You will see the following output when it is finished.

Restore Raspberry Pi SD Card

The SD card can now be taken out and used in your Pi. When you’re prepared to restore the backed-up image, adhere to the steps listed below:

1. Put the SD card into your computer. It is crucial to confirm that the SD card’s partitions are unmounted before we restore the image. Open the Terminal and type the commands sudo mount | grep sdb to confirm this. Here, swap out db for the device name of your SD card.

sudo umount /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4

There is nothing you need to do if the output is blank. Unmount the partitions indicated if you do notice any mounted partitions. For instance:

sudo dd if=~/raspbian_backup.img of=/dev/sdb

2. To write the image file to the SD card, use theddcommand:

Similar to the command we used to create a copy, but in reverse This time, the backup image is the input file and the SD card device is the output file.

Verify the parameters once more, and then double-check them, as submitting the incorrect command here can result in permanent data loss.

macOS Instructions

Backup Raspberry Pi SD Card

When the write is finished, dd will confirm it to you. The card can then be taken out of your computer and put back into the Raspberry Pi.

1.Use a USB port or the built-in card reader on your Mac to insert the SD card. Now launch a Terminal window and type diskutil list into it. Try to locate the SD card’s device ID. For instance, /dev/disk3 is how mine appears.

diskutil unmountDisk /dev/disk3

2. Remove the SD card:

Replace disk3 with the name of your SD card from step 1, replacing it here.

3. To write the image to your hard drive, use the ddcommand. For instance:

/raspbian backup.img sudo dd if=/dev/disk3

The file to copy is specified in this case by theifparameter (input file). In my case, the device name for my SD card is /dev/disk3. Change it to the name of your device. The name of the file to write to is specified by the ofparameter (output file). Raspbian backup.img is what I put in my home directory.

Note: Before running theddcommand, be careful and double check the settings because entering the incorrect values here could potentially wipe out the data on your discs.

Restore Raspberry Pi SD Card

Depending on the size of your SD card, it can take some time before you get any output from the command. You won’t see anything until the cloning is finished. The SD card can then be taken out and used in your Pi. When you’re prepared to restore the backed-up image, adhere to the steps listed below:

diskutil unmountDisk /dev/disk3

1. Insert your Mac’s SD card. Open a Terminal window, then use the unmount command as follows:

Put the name of your SD, which you determined in step 1 of the previous section, in place of disk3 here.

sudo dd if=~/raspbian_backup.img of=/dev/disk3

2. To write the image file to the SD card, use theddcommand:

Similar to the command we used to create a copy, but in reverse This time, the backup image is the input file and the SD card device is the output file.

Verify the parameters once more, and then double-check them, as submitting the incorrect command here can result in permanent data loss.

How to Shrink the Cloned Raspberry Pi Image (Linux-only)

When the write is finished, dd will confirm it to you. The card can then be taken out of your Mac and put back into the Raspberry Pi.

These techniques produce an image file that is equal to the SD card’s whole storage capacity, as was stated at the beginning of the article. For instance, even if only 5 GB of a 32 GB SD card is really in use, cloning it will still produce a 32 GB picture file. This is acceptable if you just have one or two of these photographs; but, if you have more (especially if you use an SSD), you will run out of space.

We will use PiShrink, a script that automatically shrinks a Pi image and then automatically resizes to the maximum size of the SD card upon boot, to get around this restriction. Additionally, this speeds up the process of copying the image back onto the SD card.

Sadly, Linux is the only operating system that supports this tool. If you don’t already have Linux installed, you can execute this script in a virtual machine that has the most recent versions of Ubuntu or Linux Mint loaded on it. Use it as follows:

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh

chmod +x ./pishrink.sh

1. After downloading, make the PiShrink script executable. Enter the following two commands in aTerminal:

sudo ./pishrink.sh ./raspbian_backup.img

2. Execute the script after naming the image you want to reduce in size.

sudo dd if=~/raspbian_backup.img of=/dev/sdb

The image will then be reduced in size. Once finished, follow the instructions in the ways above to write the reduced image file to the SD card. For instance, under Linux:

Clone Raspberry Pi SD Card for Easy Restore

SEE ALSO: Raspberry Pi Commands Executed Via Email

That concludes our discussion of cloning, often known as backing up and restoring existing Raspberry Pi setups. Never again will you need to reinstall Raspbian OS on a Raspberry Pi in order to test a different distribution or a fun project. Simply create a backup of your installation, play around, and then restore the image when finished. It doesn’t get any easier than that.