Linux for Radio Astronomy

How to clone a bootable SD card to a USB flash drive without corrupting either device in Linux Ubuntu using dd command in terminal

Good question — this is a classic use for dd on Linux.
Here’s a safe, step-by-step method to clone a bootable SD card to a USB flash drive without corrupting either device.


🧰 What you’ll need

  • A Linux machine (with root privileges)
  • A bootable SD card (source)
  • A USB pendrive (target)
  • Terminal access

1. Identify the devices

Plug in both the SD card and the USB stick, then run:

lsblk

This will list all block devices.
Typical names:

  • SD card: /dev/mmcblk0 or /dev/sdX
  • USB pendrive: /dev/sdY

⚠️ Double-check which is which — overwriting the wrong device will destroy data.
Do not use the partition numbers like /dev/sdX1; use the whole device like /dev/sdX.

Example output:

NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0 232G  0 disk
└─sda1        8:1    0 232G  0 part /
mmcblk0     179:0    0  32G  0 disk
└─mmcblk0p1 179:1    0  32G  0 part
sdb           8:16   1  32G  0 disk

Here:

  • /dev/mmcblk0 = SD card
  • /dev/sdb = USB pendrive

2. Unmount partitions

Unmount any automatically mounted partitions from both devices:

sudo umount /dev/mmcblk0*
sudo umount /dev/sdb*

(Adjust device names if needed.)


3. Copy the SD card to USB stick with dd

Basic syntax:

sudo dd if=/dev/mmcblk0 of=/dev/sdb bs=4M status=progress conv=fsync
  • if= = input file (SD card)
  • of= = output file (USB stick)
  • bs=4M = copy in 4 MB blocks (faster than default)
  • status=progress = show live progress
  • conv=fsync = flush writes to disk properly

👉 If the USB stick is smaller than the SD, the copy will fail. The target must be the same size or larger.


4. Sync and eject

After dd finishes, run:

sync

This ensures all writes are flushed to the USB.
Then remove the USB stick safely.


5. (Optional) Expand filesystem on USB

If the USB drive is larger than the SD card, you may want to grow the root partition to fill the extra space.
For example:

sudo gparted /dev/sdb

or using growpart and resize2fs:

sudo growpart /dev/sdb 2
sudo resize2fs /dev/sdb2

(Replace 2 with the partition number containing the root filesystem.)


6. Test the USB boot

You can now plug the USB into the target system and boot from it.


Summary:

  • Identify devices with lsblk
  • Unmount both
  • Clone: dd if=/dev/source of=/dev/target bs=4M status=progress conv=fsync
  • Sync and resize if needed

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.