How to Clone a Bootable SD Card on Linux & macOS for Backup 🖥️💾
Back up your Raspberry Pi or embedded system by cloning a bootable SD card using simple terminal commands on Linux or macOS.
Ever needed to back up a bootable SD card for your Raspberry Pi or embedded system? Whether you're safeguarding your work or preparing for disaster recovery, cloning your SD card is a smart move.
Here’s how to do it quickly and cleanly using just your terminal. 🚀
🔹 Step 1: Identify Your SD Card
Insert the SD card and find its disk identifier:
✅ For Linux:
lsblk
✅ For macOS:
diskutil list
Look for something like /dev/sdX
(Linux) or /dev/disk2
(macOS).
🔹 Step 2: Create a Backup Image
Run this command to clone the SD card into an image file:
✅ For Linux:
sudo dd if=/dev/sdX of=~/sdcard_backup.img bs=4M status=progress
✅ For macOS:
sudo dd if=/dev/disk2 of=/Users/YOUR_USERNAME/sdcard_backup.img bs=4m status=progress
This createssdcard_backup.img
in your home directory. ReplaceYOUR_USERNAME
with your actual home folder name.
🕒 Time Check:
This took about 50 minutes on a 2018 Mac mini i7 (32GB RAM) for a 32GB SD card running Raspberry Pi OS Lite with Pi-hole and Unbound.
🔹 Step 3: Verify the Backup Image
Check if the backup file exists and is the correct size:
ls -lh ~/sdcard_backup.img
(Optional) Mount the image to verify its contents:
✅ macOS:
hdiutil attach ~/sdcard_backup.img
🔹 Step 4: Restore the Image to a New SD Card
1️⃣ Insert the new SD card and identify it:
✅ For Linux:
lsblk
✅ For macOS:
diskutil list
2️⃣ Unmount the SD card(s) before writing:
✅ For Linux:
sudo umount /dev/sdX*
Use *
if the disk has multiple partitions.
✅ For macOS:
diskutil unmountDisk /dev/disk2
3️⃣ Write the backup image to the new SD card:
✅ For Linux:
sudo dd if=~/sdcard_backup.img of=/dev/sdY bs=4M status=progress
Replace /dev/sdY
with the correct device name of the new SD card.
✅ For macOS:
sudo dd if=/Users/YOUR_USERNAME/sdcard_backup.img of=/dev/disk2 bs=4M status=progress
🕒 Another 50 minutes later... and now you’ve got two identical bootable SD cards! ✅
💡 Why Should You Back Up Your SD Card?
✔️ Prevent data loss
✔️ Easily restore your system
✔️ Save time in case of failure
Backing up your bootable SD card gives you peace of mind when working with Raspberry Pi, embedded systems, or custom Linux builds. 🔥