dd is a command-line utility on Unix-like systems for low-level copying and conversion of data. It is commonly used for disk cloning, creating bootable USB drives, wiping data, and backing up partitions or entire disks.

Key Functions
| Function | Description |
|---|
| Disk/Partition Clone | Copies entire disk or partition to another disk or file. |
| Create Bootable USB | Writes ISO image directly to USB device. |
| Backup to Image File | Saves disk or partition content to a raw image file. |
| Restore from Image | Writes image file back to disk or partition. |
| Wipe/Zero-fill | Overwrites disk with zeros or random data. |
| Convert Case | Changes text case (ASCII only) during copy. |
Common dd Commands
| Command | Description |
|---|
dd if=/dev/sda of=/dev/sdb | Clones entire disk sda to sdb (sector-by-sector). |
dd if=/dev/sda1 of=/backup/sda1.img | Backs up partition sda1 to an image file. |
dd if=/backup/sda1.img of=/dev/sdb1 | Restores image file to partition sdb1. |
dd if=ubuntu.iso of=/dev/sdc bs=4M status=progress | Creates bootable USB from ISO (sdc is the USB device). |
dd if=/dev/zero of=/dev/sda bs=1M | Wipes disk by writing zeros (destroys all data). |
dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync | Clones with error handling: skips bad sectors and pads with zeros. |
Common Options (Flags)
| Option | Description |
|---|
if= | Input file (source) โ can be a device or regular file. |
of= | Output file (destination) โ device or file. |
bs= | Block size (e.g., bs=4M for faster copying). |
count= | Number of blocks to copy (limits size). |
skip= | Skip blocks from the beginning of input. |
seek= | Skip blocks from the beginning of output. |
conv=noerror | Continue on read errors. |
conv=sync | Pad short reads with zeros. |
status=progress | Show progress during copy (Linux). |
iflag=direct | Bypass cache for direct I/O (useful for USB). |
How to Use dd
Clone a Disk or Partition
- Identify source and destination:
lsblk or diskutil list (macOS) to list disks. - Unmount any mounted partitions:
umount /dev/sda1 (Linux) or diskutil unmount /dev/disk2s1 (macOS). - Run dd:
sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress. - Wait for completion (no progress bar by default; use
status=progress or send SIGUSR1 to see status).
Create a Bootable USB
- Insert USB drive and identify it (e.g.,
/dev/sdc). Warning: Ensure you have the correct device; you can overwrite your hard drive. - Unmount USB:
umount /dev/sdc1. - Write ISO:
sudo dd if=/path/to/image.iso of=/dev/sdc bs=4M status=progress && sync. - Remove USB safely after
sync completes.
Wipe a Disk
sudo dd if=/dev/zero of=/dev/sda bs=1M status=progress (writes zeros).- For secure wipe (random data):
sudo dd if=/dev/urandom of=/dev/sda bs=1M (much slower).
Important Notes
- Destructive: dd overwrites the destination completely without confirmation. Double-check
if and of before pressing Enter. - No progress bar by default: Use
status=progress (Linux) or send SIGUSR1 to the dd process (macOS/BSD) to view progress. - Block size: Larger
bs speeds up copying; common values: 1M, 4M, 64M. Tune for your hardware. - Error handling: If reading from a failing drive, use
conv=noerror,sync to skip bad sectors and continue. - Sync: Always run
sync after dd to flush write caches, especially for USB devices. - Device names: Linux uses
/dev/sda, /dev/nvme0n1; macOS uses /dev/disk0; be careful with naming. - Image files: dd creates raw byte-for-byte images; they are not compressed unless piped through gzip:
dd if=/dev/sda | gzip > sda.img.gz. - Restore compressed image:
gunzip -c sda.img.gz | dd of=/dev/sdb.