dd — Copy, Clone and Wipe Drives Block by Block
Practical guide to dd — create disk images, clone drives, write ISOs to USB, wipe disks and copy raw block data, with the safety notes this tool demands.
dd copies data block by block straight at the device level — perfect for disk images, cloning whole drives, building bootable USB sticks or securely wiping disks. That same power makes it dangerous: dd has earned the nickname "disk destroyer" for good reason. Swap if= and of=, or point of=/dev/sdX at the wrong disk, and you overwrite an entire drive instantly and irreversibly — no prompt, no trash can, no undo. Always confirm the target device with lsblk before you press Enter.
Basic Usage
dd if=<input> of=<output> — Copy data from input file to output file.
dd if=/dev/sda of=/dev/sdbdd if=<input> of=<output> bs=<size> — Copy with a specific block size (affects speed).
dd if=/dev/sda of=disk.img bs=4Mdd if=<input> of=<output> bs=<size> count=<n> — Copy only N blocks of the specified size.
dd if=/dev/zero of=testfile bs=1M count=100dd if=<input> of=<output> status=progress — Show transfer progress during copy.
dd if=/dev/sda of=backup.img bs=4M status=progressdd if=<input> of=<output> conv=<flags> — Apply conversion options during copy.
dd if=data.txt of=upper.txt conv=ucaseDisk Images & Cloning
dd if=<device> of=<image> bs=4M status=progress — Create a raw disk image from a device.
dd if=/dev/sda of=disk-backup.img bs=4M status=progressdd if=<image> of=<device> bs=4M status=progress — Restore a disk image to a device.
dd if=disk-backup.img of=/dev/sda bs=4M status=progressdd if=<device> bs=4M status=progress | gzip > <image>.gz — Create a compressed disk image.
dd if=/dev/sda bs=4M status=progress | gzip > disk-backup.img.gzgunzip -c <image>.gz | dd of=<device> bs=4M status=progress — Restore a compressed disk image.
gunzip -c disk-backup.img.gz | dd of=/dev/sda bs=4M status=progressdd if=<device1> of=<device2> bs=4M conv=noerror,sync status=progress — Clone a disk (skip errors, pad with zeros).
dd if=/dev/sda of=/dev/sdb bs=4M conv=noerror,sync status=progressBootable USB & ISO
dd if=<iso> of=<device> bs=4M status=progress oflag=sync — Write an ISO image to a USB drive.
dd if=ubuntu-24.04-desktop-amd64.iso of=/dev/sdb bs=4M status=progress oflag=syncdd if=<device> of=<iso> bs=4M status=progress — Create an ISO from a CD/DVD drive.
dd if=/dev/cdrom of=disc.iso bs=4M status=progressdd if=/dev/zero of=<device> bs=512 count=1 — Wipe the MBR (first 512 bytes) of a disk.
dd if=/dev/zero of=/dev/sdb bs=512 count=1Generate Test Files
dd if=/dev/zero of=<file> bs=1M count=<n> — Create a file filled with zeros of a specific size.
dd if=/dev/zero of=100mb.bin bs=1M count=100dd if=/dev/urandom of=<file> bs=1M count=<n> — Create a file filled with random data.
dd if=/dev/urandom of=random.bin bs=1M count=50dd if=/dev/zero of=<file> bs=1 count=0 seek=<size> — Create a sparse file (allocates space without writing).
dd if=/dev/zero of=sparse.img bs=1 count=0 seek=10GWipe & Secure Erase
dd if=/dev/zero of=<device> bs=4M status=progress — Wipe a disk with zeros.
dd if=/dev/zero of=/dev/sdb bs=4M status=progressdd if=/dev/urandom of=<device> bs=4M status=progress — Overwrite a disk with random data (more secure).
dd if=/dev/urandom of=/dev/sdb bs=4M status=progressdd if=/dev/zero of=<file> bs=4M; rm <file> — Overwrite a file before deleting it.
dd if=/dev/zero of=secret.txt bs=4M; rm secret.txtBenchmark & Performance
dd if=/dev/zero of=<file> bs=1G count=1 oflag=dsync — Benchmark write speed (sync after each block).
dd if=/dev/zero of=/tmp/testfile bs=1G count=1 oflag=dsyncdd if=<file> of=/dev/null bs=1M — Benchmark read speed (discard output).
dd if=/tmp/testfile of=/dev/null bs=1Mdd if=/dev/zero of=<file> bs=<size> count=<n> oflag=direct — Test direct I/O write speed (bypass cache).
dd if=/dev/zero of=/tmp/testfile bs=4M count=256 oflag=directOptions & Flags
bs=<size> — Block size for read and write (K, M, G suffixes). Larger = faster.
bs=4M (common for disk operations)count=<n> — Copy only N input blocks.
count=100 (with bs=1M = 100 MB)skip=<n> — Skip N blocks at the start of input.
skip=1 bs=512 (skip MBR)seek=<n> — Skip N blocks at the start of output.
seek=1 bs=512 (write after MBR)conv=noerror,sync — Continue on read errors and pad with zeros (for damaged disks).
dd if=/dev/sda of=rescue.img conv=noerror,sync bs=4Koflag=sync — Synchronize output after each write (ensures data is flushed).
dd if=image.iso of=/dev/sdb bs=4M oflag=synciflag=fullblock — Accumulate full input blocks (prevents short reads from pipes).
dd if=/dev/stdin of=output.bin bs=1M iflag=fullblock Conclusion
dd is one of the most powerful — and most dangerous — tools in the Unix world: it writes blindly to exactly where you tell it, with no confirmation and no undo. A wrong of=/dev/sdX destroys an entire disk in seconds. So always verify the target device first with lsblk or fdisk -l, never swap if= and of=, and unmount the device before writing. Use status=progress for visible progress, a sensible bs= (usually 4M) for throughput, and conv=fsync or oflag=sync so all data actually lands on the medium instead of sitting in the cache. On macOS, address the raw device /dev/rdiskN (much faster) and unmount it first with diskutil unmountDisk. When in doubt, check one more time rather than overwriting a disk you can never get back.
Further Reading
- Arch Wiki: dd – thorough reference covering disk images, cloning and secure erasing
- Wikipedia: dd (Unix) – background, options and common usage patterns