Bulut & Sanallaştırma
100%

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.

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: The dd command leaves no room for error. If you enter an incorrect disk path in the of= parameter, all data on that disk will be permanently deleted. Be sure to verify the target with lsblk or sudo fdisk -l before proceeding.

Scenario 1: Burning ISO File to USB

To install a Linux distribution via USB, follow these steps:

  1. Specify the path to your USB device: lsblk
  2. Remove the USB drive from the connection: sudo umount /dev/sdX1
  3. Burn the ISO file:
sudo dd if=file.iso of=/dev/sdX bs=4M status=progress oflag=sync

Scenario 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=progress
  • conv=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.gz

Scenario 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=direct

Tips and Commons Problems

  • Progress Bar: If you started the command without the status=progress parameter, you can see the current status by running the sudo 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 blkdiscard or firmware instead of dd; Full disk wipes performed with dd may unnecessarily consume SSD life.

Related Articles

View All