The Linux dd command is a powerful utility for copying and converting data at the block level, commonly used to create disk images, clone drives, or wipe storage devices. It works directly with raw data, making it fast but dangerous if misused — a single typo can overwrite your entire system. Always verify device paths and back up critical data before using dd.
What You'll Need
- A Linux system (any distribution: Ubuntu, Fedora, Debian, etc.)
- Terminal access with sudo or root privileges
- At least one external storage device (USB drive, SD card, or secondary hard drive)
- Knowledge of your device names (use
lsblkorfdisk -lto identify them)
Step-by-Step
- Open a terminal and list all connected storage devices by typing
lsblk. Look for entries likesda,sdb, ornvme0n1. Note the device name and size of the source and target drives. - Ensure the target drive is unmounted. If copying to a USB drive, unmount it with
sudo umount /dev/sdX1(replacesdX1with the correct partition). Do not unmount the source drive if it's your system disk. - To create a full disk image of a drive, use:
sudo dd if=/dev/sdX of=~/disk_image.img bs=4M status=progress. ReplacesdXwith your source device (e.g.,sdb). This creates a file nameddisk_image.imgin your home directory. - To restore a disk image to a physical drive, use:
sudo dd if=~/disk_image.img of=/dev/sdY bs=4M status=progress. ReplacesdYwith the target drive. This overwrites everything on that drive — double-check the device name. - To clone one drive directly to another (e.g., SSD to SSD), use:
sudo dd if=/dev/sdX of=/dev/sdY bs=4M status=progress. Both drives must be the same size or larger on the target. The process copies every byte, including partitions and boot sectors. - To wipe a drive securely by overwriting with zeros:
sudo dd if=/dev/zero of=/dev/sdZ bs=4M status=progress. ReplacesdZwith the target device. This erases all data irreversibly. - To wipe a drive with random data (more secure), use:
sudo dd if=/dev/urandom of=/dev/sdZ bs=4M status=progress. This is slower but harder to recover data from. - To monitor progress without interrupting, run the command in one terminal and in another, run
kill -USR1 $(pgrep dd)to see current progress stats. - After any operation, run
syncto ensure all data is written to disk before removing the device.
Common Mistakes
- Swapping
if=(input file) andof=(output file) — reversing them can overwrite your system drive. - Using partition names like
sda1when you meant the whole drivesda, resulting in incomplete images. - Forgetting to unmount the target drive before writing, causing corruption or I/O errors.
- Using too small a block size (
bs=512) which slows the process dramatically; always usebs=4Morbs=1Mfor speed. - Assuming dd will prompt for confirmation — it won’t. Once you press Enter, it starts immediately.
Tips
- Always use
lsblkorsudo fdisk -lto verify device names before running dd — a wrong letter can erase your OS. - Use
status=progressto see real-time transfer stats (available in modern dd versions). - For large images, compress them on the fly:
sudo dd if=/dev/sdX bs=4M | gzip > ~/disk_image.img.gzto save space. - To verify data integrity after copying, calculate checksums:
md5sum /dev/sdXand compare withmd5sum ~/disk_image.img. - When cloning drives, ensure the target is equal to or larger than the source. dd won’t resize partitions — it copies byte-for-byte.
- Use
ddrescueinstead of dd for damaged drives — it’s designed to skip bad sectors and retry later.
Troubleshooting
- Permission denied: Run the command with
sudo. If sudo isn’t working, log in as root or check your user’s sudoers permissions. - Input/output error: The source drive may be failing. Try using
ddrescue, or check the drive withsmartctl -a /dev/sdX. - Target device is full: The output drive is smaller than the source. Ensure the target has equal or greater capacity.
- Command hangs with no progress: Check if the device is physically connected and powered. Use
lsblkto confirm the device is still listed. Try restarting the command withbs=1Mif4Mfails. - Image won’t boot after restore: You likely copied a partition instead of the whole drive. Always use
/dev/sdX(whole drive), not/dev/sdX1(partition), when cloning boot drives. - dd reports 0 bytes copied: You may have mistyped the device name. Double-check with
lsblk. Also, ensure the source drive isn’t empty or corrupted.
Frequently Asked Questions
Can dd be used to clone a running system drive?
Yes, but it’s risky. The system files may change during the copy, resulting in an inconsistent image. It’s safer to boot from a live USB and clone the drive from there.Does dd compress files automatically?
No, dd copies data exactly as-is. To compress, pipe the output togzip, bzip2, or xz as shown in the tips section.
How long does dd take to complete?
It depends on drive speed and size. A 1TB drive over USB 3.0 typically takes 1–3 hours. SSDs are faster; old HDDs are slower. Usestatus=progress to monitor.
Is dd the only way to clone a drive in Linux?
No. Tools likersync, clonezilla, or gparted are safer for file-level copying or resizing partitions, but dd is the only tool that clones at the raw sector level.
Can I use dd to create a bootable USB stick?
Yes. Download an ISO (like Ubuntu) and runsudo dd if=~/ubuntu.iso of=/dev/sdX bs=4M status=progress, then sync. This writes the ISO directly to the USB, making it bootable.
What happens if I interrupt dd with Ctrl+C?
The copy stops immediately. The output file or drive may be corrupted or incomplete. Never interrupt unless absolutely necessary — usekill -USR1 to check progress instead.