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 listUnmount disk:
# Unmount disk on Linux
sudo umount /dev/sdb<id>
# Unmount disk on macos
diskutil unmountDisk /dev/disk2Copy 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 offsetsNotes:
noerrorkeeps copying after read failuressyncpads unreadable blocks so data offsets remain correctrdiskXexists 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.imgCreate image checksum
# linux
sha256sum usb-backup.img > usb-backup.img.sha256
# macos
shasum -a 256 usb-backup.img > usb-backup.img.sha256This 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
ddrescuefor smarter retries and multi-pass recovery