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

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

Raspberry Pi is the ultimate mechanic toy. Most of its users like to try and crack running installations in the process. However, as fun as it is, everyone likes to have a working base configuration that they can go back to after the experiment is over.

Another common scenario, let’s say you’ve learned about a new Raspberry Pi-based project or Linux distribution, and you’re dying to give it a try. The problem is that you only have one micro SD card and you already have a working installation on it that you don’t want to lose.

In both of the above scenarios, it’s helpful to have a full, bit-by-bit identical backup of your working Raspberry Pi installation. So today we will learn how to clone or backup Convert the Raspberry Pi micro SD card to an image file and restore The image after finishing the experiment. We will explain how to do it on Windows, Linux and finally macOS.

note: This method will create an image file exactly the size of the total capacity of the SD card. For example, if you have a 16GB SD card, the resulting image file will also be 16GB, no matter how much space your installation actually uses. There is a method to reduce the image size, but it only works on Linuxand we will explain this later in the tutorial.

Windows Instructions

Backup Raspberry Pi SD Card

one. Plug the micro SD card you want to clone into your PC using a USB or built-in card reader.

2. download and install and run Win32DiskImager. You will see a screen like this:

3. Under Device section in the upper right corner, Choose your SD card drive. This D: in my case. Now click on the folder icon to its left and choose a location and filename where to save the image file. i chose the filename raspbian_backup_19_oct.img. You can choose the filename you want, but a filename is preferred. .img addition. When done, click on To read button.

imager_read

4. This will create a clone of the SD card in the location you specified. copying It will take some time Do not turn off your computer or put it to sleep during this time to complete it. Once complete, you will receive a “Successful Read” message.

imager_success

You are now free to plug the card back into your Raspberry Pi and break things or install a new distro. When you finish playing and want to restore the backed up image, follow the steps in the next section.

Restore Raspberry Pi SD Card

Insert the micro SD card into your PC and open Win32DiskImager. Select the image file previously created and appropriate to spread inside Device episode. Now, click To write button. The image is saved on the SD card exactly as it was when you copied it.

imager_write

Again, this process will take some time depending on the size of the SD card. When the restore is complete, you can remove the card from your computer and insert it back into the Raspberry Pi.

Linux Instructions

Backup Raspberry Pi SD Card

one. Plug the SD card into your PC using USB or the built-in card reader. open one now terminal open the window and enter the command sudo fdisk -l. This will list all the file systems present on your system.

2. try to find device name I have a 16GB SD card of your SD card so it can be easily identified as a device /dev/sdb It is 14.9 GB in size. This is because the actual storage on a device is always slightly lower than advertised. Note this device name.

fdisk

3. Use dd command to write the image to your hard disk. For example:

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

Here, if parameter (input file) specifies the file to be cloned. in my case, /dev/sdbis the device name of my SD card. Replace with your device name. this of the parameter (output file) specifies the file name to be written. I chose raspbian_backup.img in my home directory.

note: Be careful and double check the parameters before running. dd command, entering the wrong parameters here can potentially destroy data on your drives.

You will not see any output from the command until the cloning is complete and this may take some time depending on the size of your SD card. Once complete, you will see an output like the one below.

dd-success

You can now remove the SD card and use it on your Pi. When you’re ready to restore the backed up image, follow the instructions below:

Restore Raspberry Pi SD Card

one. Insert the SD card into your PC. Before restoring the image, it is important to make sure that the partitions of the SD card are correct. not mounted. To confirm this, terminaland execute the command sudo mount | grep sdb. Here, change sdb With the device name of your SD card.

If you see a blank output, you don’t need to do anything. If you see some mounted partitions, disconnect those listed. For example:

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

2. Use dd command to write image file to SD card:

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

This is similar to the command we use to clone, but reversed. This time, input file if backup image, output file of It is an SD card device.

Again, verify and verify the parameters here twiceEntering the wrong command here will cause permanent data loss.

When the write is complete, you will see a confirmation from dd. You can then remove the card from your computer and insert it back into the Raspberry Pi.

macOS Instructions

Backup Raspberry Pi SD Card

one. Insert the SD card into your Mac using a USB or built-in card reader. open one now terminal open the window and enter the command diskutil list. Try to determine the device ID of your SD card. For example mine looks like this: /dev/disk3.

mac-diskutil

2. Unmount your SD card:

diskutil unmountDisk /dev/disk3

Here, change disk3 With the name of your SD card you defined in step 1.

3. Use dd command to write the image to your hard disk. For example:

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

Here, if parameter (input file) specifies the file to be cloned. in my case, /dev/disk3is the device name of my SD card. Replace with your device name. this of parameter (output file) specifies the file name to be written. I chose raspbian_backup.img in my home directory.

note: Be careful and double check the parameters before operating. dd command, entering the wrong parameters here can potentially destroy data on your drives.

You will not see any output from the command until the cloning is complete and this may take some time depending on the size of your SD card. You can then remove the SD card and use it on your Pi. When you’re ready to restore the backed up image, follow the instructions below:

Restore Raspberry Pi SD Card

one. Insert the SD card into your Mac. a hungry terminal window and disconnect using the following command:

diskutil unmountDisk /dev/disk3

Here, change disk3 with the name of your SD that you defined in step 1 of the previous section.

2. Use dd command to write image file to SD card:

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

This is similar to the command we use to clone, but reversed. This time, input file if backup image, output file of It is an SD card device.

Again, verify and verify the parameters here twiceEntering the wrong command here will cause permanent data loss.

When the write is complete, you will see a confirmation from dd. You can then remove the card from your Mac and plug it back into the Raspberry Pi.

How to Shrink a Cloned Raspberry Pi Image (Linux only)

As mentioned at the beginning of the article, these methods create an image file equal to the total capacity of the SD card. For example, cloning a 32GB SD card will create a 32GB image file even though the card actually has only 5GB in use. That’s fine if you only have one or two such images, but more than that (especially if you’re using an SSD) will run out of space.

To work around this limitation we will use PiShrinka script automatically shrinks a Pi image this will then automatically resize to the maximum size of the SD card on boot. This also makes copying the image back to the SD card much faster.

Unfortunately, this tool is only available on Linux. If you don’t have Linux installed, you can install the latest version of Ubuntu or Linux Mint in a virtual machine and run this script there. Here’s how to use it:

one. Download PiShrink scriptand make it executable. Inside terminalenter the following two commands:

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

chmod +x ./pishrink.sh

2. Run the scriptnext the name of the picture You want to shrink.

sudo ./pishrink.sh ./raspbian_backup.img

piss

3. The image is then scaled down. Once done, you can write the reduced image file to the SD card as outlined in the methods listed above. For example, on Linux:

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

SEE ALSO: How to Run Commands via Email on Raspberry Pi

Clone Raspberry Pi SD Card for Easy Restore

So this is all about cloning, i.e. backing up and restoring existing Raspberry Pi installations. You’ll never have to lose a perfectly working Raspbian OS install on Raspberry Pi just to try a new distro or a great project. Just backup your installation, tamper with and restore the image when you’re done. It doesn’t get any simpler than this.

How did you find this method of backing up your Raspberry Pi installations? Is there a better way? Questions? Comments? Let us know in the comments section below.

Support our work ❤️

If you enjoyed this article, consider leaving a tip to help us keep publishing great content.

Secure payment on PayPal
Moyens I/O Staff is a team of expert writers passionate about technology, innovation, and digital trends. With strong expertise in AI, mobile apps, gaming, and digital culture, we produce accurate, verified, and valuable content. Our mission: to provide reliable and clear information to help you navigate the ever-evolving digital world. Discover what our readers say on Trustpilot.