Cloning a microSD Card using UNIX dd Command¶
This guide explains how to clone a microSD card using the dd command on UNIX and UNIX-like systems.
Table of Contents¶
- Cloning a microSD Card using UNIX
ddCommand - Table of Contents
- Identify the microSD Card Device
- Unmount the microSD Card
- Create a Backup Image
- Copy the Backup Image to New microSD Cards
- Expand the Filesystem (Optional)
Identify the microSD Card Device¶
-
First, identify the device name for your microSD card. Use either
lsblkordfto list devices and their mount points.lsblkOr:
df -h -
Look for the device corresponding to your microSD card. It's generally something like
/dev/sdXor/dev/mmcblkX, whereXis a letter.⚠️ Caution: Be very careful to identify the correct device, as choosing the wrong one could result in data loss.
Unmount the microSD Card¶
-
Before copying data, unmount the partitions of the microSD card to ensure that no data is being read or written during the cloning process.
sudo umount /dev/sdX*
Create a Backup Image¶
-
Use the
ddcommand to create an image file of the microSD card.sudo dd if=/dev/sdX of=raspberrypi_backup.img bs=4M status=progressif: Input File — the device you are copying from (your microSD card).of: Output File — the image file you are creating.bs: Block Size — specifies how much data should be read at each iteration.4Mis usually a good size.status=progress: shows the progress during the copy.
Copy the Backup Image to New microSD Cards¶
-
To clone the image onto a new microSD card, insert the new card and identify it just like you did in the first step.
sudo dd if=raspberrypi_backup.img of=/dev/sdY bs=4M status=progressReplace
/dev/sdYwith the device name of your new microSD card.⚠️ Caution: Again, be very careful to identify the correct device to avoid data loss.
Expand the Filesystem (Optional)¶
-
If your new microSD card is larger than the original, you might need to expand the filesystem to use the additional space. You can do this using
raspi-configon the Raspberry Pi.sudo raspi-configNavigate to
Advanced Options>Expand Filesystem.
After following these steps, you should have successfully cloned your Raspberry Pi's microSD card.
Note: The dd command can be very dangerous if misused. Always double-check your device names and ensure you understand the commands you're running.