dd Command: Disk Imaging and Safe Usage
What You'll Learn
- How to clone a disk or partition into an image file with
dd - How to write a downloaded ISO to a USB stick to make boot media
- How to avoid wiping the wrong device with a mistaken
of=
Most Important Warning
dd overwrites whatever you point of= (the output) at without confirmation. There is no undo and no trash bin. A single wrong character in the device name (/dev/sda etc.) can destroy your running system disk. Always verify the target with lsblk before you run it.
Quick Summary (the safe workflow)
- Identify the target device with
lsblk(match by size and mount state) sudo dd if=<input> of=<output> bs=4M status=progress conv=fsync- Run
syncafterward to flush write buffers
Assumptions (environment)
- OS: Ubuntu / any common Linux distribution
ddships with GNU coreutils. No extra install needed- Device operations require
sudo(root)
What Is the Basic Syntax of dd?
Conclusion: The base form is
dd if=input of=output bs=blocksize. Arguments usekey=valueform, not hyphenated flags like most commands.
dd simply reads from an input (if) and writes to an output (of). Every argument is written as key=value.
$ dd if=input.img of=/dev/sdb bs=4M status=progress
Key operands:
if=(input file): source. Defaults to standard inputof=(output file): destination. Defaults to standard outputbs=(block size): bytes read/written at once (e.g.4M= 4 MiB)count=: number of blocks to copy (to clone only the start)status=progress: live transfer amount and speedconv=fsync: guarantee data is written to the physical media on finish
bs directly affects speed. The default 512 bytes is slow. For disks or USB media, bs=4M is a safe choice.
How Do You Identify the Right Drive? (Most Important)
Conclusion: Use
lsblkto match capacity and mount point, then confirm the target device name. Always note the difference between/dev/sda(the whole disk) and/dev/sda1(a partition).
Most dd disasters come from picking the wrong device name. Always check first.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 238.5G 0 disk ├─sda1 8:1 0 512M 0 part /boot/efi └─sda2 8:2 0 238G 0 part / sdb 8:16 1 28.7G 0 disk └─sdb1 8:17 1 28.7G 0 part /media/user/USB
How to read it:
sda: 238.5G, mounted at/-> system disk. Never write to itsdb: 28.7G withRM(removable) set to1-> the USB stick you insertedsdbwith no trailing number is the whole disk;sdb1is a partition inside it
Run lsblk once before and once after inserting the USB, then target the newly appeared device. Cross-check the SIZE column too.
For ISO writing, point of= at the whole disk (sdb), not a partition (sdb1). Writing to a partition will not produce bootable media.
How Do You Write an ISO Image to a USB?
Conclusion: Unmount the target USB, then run
sudo dd if=xxx.iso of=/dev/sdX bs=4M status=progress. Pointof=at the whole disk with no partition number.
The standard way to make a bootable USB for Ubuntu and similar.
1. Unmount it
A mounted target during writing causes failures or corruption.
$ sudo umount /dev/sdb1
2. Write with dd
$ sudo dd if=ubuntu-24.04.iso of=/dev/sdb bs=4M status=progress conv=fsync
1538000000 bytes (1.5 GB, 1.4 GiB) copied, 142 s, 10.8 MB/s 367+1 records in 367+1 records out
3. Sync before removing
The kernel may still hold buffered data after dd returns. Flush it with sync.
$ sync
conv=fsync and a trailing sync overlap in purpose, but using both prevents the "command finished but the write is still in flight" failure.
How Do You Clone a Whole Disk to an Image File?
Conclusion: Put the device in
if=and an image file inof=to back up the whole thing. Pipe throughgzipto shrink mostly-empty disks.
Back up a disk or partition into a single file.
$ sudo dd if=/dev/sdb of=usb-backup.img bs=4M status=progress
Compress while saving (useful when much of the disk is empty):
$ sudo dd if=/dev/sdb bs=4M status=progress | gzip > usb-backup.img.gz
An image file consumes the same capacity as the source device (a 28 GB USB -> a 28 GB file). Check the destination free space with df -h first.
How Do You Restore an Image Back to a Disk?
Conclusion: Just swap
if=andof=. Pipe compressed images throughgunzipwhile restoring. Double-check the destination once more.
# Uncompressed image $ sudo dd if=usb-backup.img of=/dev/sdb bs=4M status=progress conv=fsync # Compressed image $ gunzip -c usb-backup.img.gz | sudo dd of=/dev/sdb bs=4M status=progress conv=fsync
A restore is the reverse direction of a clone. Confirm with lsblk that of= is the same device you used as if= during backup before running it.
How Do You Speed It Up or Watch Progress?
Conclusion: A larger
bs(4Mto64M) is faster. Watch progress withstatus=progress; on older systems that lack it, sendkill -USR1from another terminal.
Tuning the block size
$ sudo dd if=/dev/sdb of=backup.img bs=64M status=progress
A small bs means more system calls and slower transfers. Too large just wastes memory, so 4M to 64M is the practical range.
Checking progress without status=progress
Send a signal to a running dd from another terminal to print the current transfer amount.
$ sudo kill -USR1 $(pgrep -x dd)
GNU coreutils 8.24 and later support status=progress. Prefer it, and treat kill -USR1 as the fallback for older environments.
What Are the Common dd Disasters?
Conclusion: Nearly every accident reduces to a wrong
of=, swappedif/of, or writing to a mounted device. A pre-run check prevents all three.
| Disaster | Cause | Prevention |
|---|---|---|
| Destroyed the system disk | Wrong of= device name |
Match size and mount with lsblk first |
| Backup comes out empty | Swapped if= and of= |
Say out loud "read = if, write = of" |
| Wrote it but it won't boot | Wrote to a partition (sdb1) |
Write ISO to the whole disk (sdb) |
| Content corrupt after finishing | Pulled USB before buffers flushed | Always use conv=fsync + sync |
Things you must not do
- Run
of=/dev/sdXwithout checkinglsblk - Write with
ddwhile the target is still mounted - Pull the USB right after
ddwithoutsync
Copy-paste safe template
# 1. Check devices (always first) lsblk # 2. Write ISO to USB (assumes it is unmounted) sudo dd if=image.iso of=/dev/sdX bs=4M status=progress conv=fsync # 3. Sync after finishing sync
Replace /dev/sdX with the actual device name you confirmed in lsblk.