dd Command in Linux: Guide to Disk Cloning, Backup and ISO Burning
Learn how to clone disk, burn ISO, backup and perform performance testing with the dd command in Linux. Step by step technical guide.
Contents
Introduction
In Linux operating systems, the cp command makes file-level copying, The dd command copies block by block at the raw data level. This feature makes it indispensable for critical tasks such as disk cloning, bootable USB preparation, and partition backup.
Basic Syntax
dd if=INPUT of=OUTPUT [OPTIONS]WARNING: Theddcommand leaves no room for error. If you enter an incorrect disk path in theof=parameter, all data on that disk will be permanently deleted. Be sure to verify the target withlsblkorsudo fdisk -lbefore proceeding.
Scenario 1: Burning ISO File to USB
To install a Linux distribution via USB, follow these steps:
- Specify the path to your USB device:
lsblk - Remove the USB drive from the connection:
sudo umount /dev/sdX1 - Burn the ISO file:
sudo dd if=file.iso of=/dev/sdX bs=4M status=progress oflag=syncScenario 2: Cloning the Entire Disk
To copy a disk exactly to another disk:
sudo dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync status=progressconv=noerror: Does not stop the process in case of read error.conv=sync: Maintains alignment by filling read errors with zeros.
Scenario 3: Partition Backup and Compression
Backup a partition and save space use piping with gzip:
sudo dd if=/dev/sda1 bs=4M status=progress | gzip -c > /backup/sda1.img.gzScenario 4: Disk Performance Test (Benchmark)
Create a 1 GB test file to measure disk write speed:
dd if=/dev/zero of=testfile bs=1M count=1024 oflag=directTips and Commons Problems
- Progress Bar: If you started the command without the
status=progressparameter, you can see the current status by running thesudo kill -USR1 $(pidof dd)command from another terminal. - Performance: The default block size is 512 bytes. You can significantly shorten the processing time by using
bs=4M. - SSD Warning: To erase SSD disks, use
blkdiscardor firmware instead ofdd; Full disk wipes performed withddmay unnecessarily consume SSD life.