dd (Data(set) Definition) is a Shell command for reading, writing and converting file data. Originally developed for Unix, it has been implemented on many other Operating Systems.

Copying a drive

List drives:

# List disks on Linux
lsblk
# List disks on macos
diskutil list

Unmount disk:

# Unmount disk on Linux
 sudo umount /dev/sdb<id>
# Unmount disk on macos
diskutil unmountDisk /dev/disk2

Copy disk (update <disk_path>)

sudo dd if=<disk_path> of=usb-backup.img bs=4M conv=noerror,sync status=progress    # clone entire USB, continue past read errors, preserve offsets

Notes:

  • noerror keeps copying after read failures
  • sync pads unreadable blocks so data offsets remain correct
  • rdiskX exists only on macOS and is significantly faster

Attach the Image Safely (Read-Only)

# linux
sudo losetup --find --read-only --show usb-backup.img
# macos
hdiutil attach -nomount usb-backup.img

Create image checksum

# linux
sha256sum usb-backup.img > usb-backup.img.sha256
# macos
shasum -a 256 usb-backup.img > usb-backup.img.sha256

This allows later verification that the image has not changed.

Aftercare and Escalation

  • Store the original USB drive safely and do not reuse it
  • Perform filesystem checks and recovery only on the image
  • If the copy was extremely slow or unstable, escalate to ddrescue for smarter retries and multi-pass recovery