Linux for Radio Astronomy

Copying disc image from bootable SD card when you have booted from that card

Since you’ve booted from the SD card, that means the system is running on the same device you want to copy.

👉 This is important: you can’t safely use dd to clone the card while it’s actively mounted and in use as the root filesystem — you’d end up copying a live, changing system and likely create a corrupted image.

But there are safe workarounds to create a bootable USB clone:


🧭 Option 1 — Create an image of the SD card, then write it to USB (best method)

1. Find your SD card device name

Since you booted from it, your SD card is usually /dev/mmcblk0 or /dev/sda.

Run:

lsblk

You should see something like:

mmcblk0    29.7G
├─mmcblk0p1  256M  (boot)
└─mmcblk0p2  29.4G (root)

✅ Note the device name (e.g., /dev/mmcblk0).


2. Mount an external USB stick or external HDD/SSD temporarily to store the image

(⚠️ Not the USB stick you want to turn into a boot drive — this is just temporary storage if needed.)

If you have enough space on your target USB drive, you can write directly to it instead of using a temporary image.


3. Use dd to make a disk image file

sudo dd if=/dev/mmcblk0 of=~/sdcard.img bs=4M status=progress conv=fsync

This creates sdcard.img in your home directory.
(You can also put it on another mounted drive with more space.)


4. Plug in the target USB pendrive and identify it

lsblk

e.g. /dev/sdb


5. Write the image to the USB stick

sudo dd if=~/sdcard.img of=/dev/sdb bs=4M status=progress conv=fsync

⚠️ Be sure of= points to the entire USB device, not a partition like /dev/sdb1.


6. Flush the write

sync

7. (Optional) Expand the root filesystem on the USB stick

If your USB is larger than the SD card:

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

🧰 Option 2 — Clone directly from SD card to USB (no intermediate file)

If the USB stick is plugged in and your SD card is /dev/mmcblk0, and USB is /dev/sdb, you can clone directly:

sudo dd if=/dev/mmcblk0 of=/dev/sdb bs=4M status=progress conv=fsync

Then sync and resize as above.

⚠️ However, since your root filesystem is live, this can still cause inconsistencies unless it’s mostly static. It’s safer to use Option 1 with a temporary image — or better yet, boot from another medium.


🩹 Option 3 — Use rsync (alternative method)

If you prefer not to copy the raw disk, you can:

  1. Plug in USB stick.
  2. Create matching partitions on USB (boot + root).
  3. Mount USB partitions.
  4. Use:
sudo rsync -aAXHv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt/usb-root
  1. Install bootloader (e.g. grub-install or raspi-config for Raspberry Pi).

This method is a bit more advanced but results in a clean copy.


Best for most cases:

  • Boot from SD card
  • Create image with dd
  • Write image to USB
  • Resize filesystem 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.