Website Vidya
Linux & ServersStep-by-Step Guide

dd Command in Linux: Disk Cloning, Backup & Wiping Guide

Learn dd command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

RR
Rajesh RayLead Systems Educator
Published:
10 min read
PDF Cheat Sheet
dd Command in Linux: Disk Cloning, Backup & Wiping Guide
AI Executive SummaryWebsiteVidya AI

10 min read

Learn dd command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

Key Highlights
  • What dd Does and When to Use It
  • Availability and Installation Across Linux Distributions
  • Command Syntax, Arguments, and Exit Status Codes
Grounded in full engineering runbookWebsiteVidya AI Engine

For byte-level data replication and bare-metal storage administration, the dd command in linux is one of the most powerful and venerable utilities in the Unix toolchain. Operating below the filesystem layer, dd reads and writes raw data blocks directly across storage devices, partition nodes, regular files, and special character streams.

Whether you are cloning a failing hard drive to a replacement SSD, creating a compressed raw backup image of an operating system volume, writing a bootable Linux distribution ISO to a USB flash drive, or benchmarking raw storage controller throughput, dd delivers direct, deterministic block access. Because it bypasses filesystem abstraction, it handles any partition layout, filesystem type, or bootloader signature identically.

In this comprehensive guide, we dissect the non-standard operand syntax of dd, examine block size selection and caching flags, analyze modern progress reporting features, review essential production examples, and establish rigorous safety checks to prevent catastrophic data destruction.

Advertisement
dd Command in Linux: Disk Cloning, Backup & Wiping Guide — syntax, flags, and practical terminal workflow diagram
dd Command in Linux: Disk Cloning, Backup & Wiping Guide — command syntax, key options, and production workflow reference.

What dd Does and When to Use It

At the architectural level, dd interacts directly with the Linux kernel's Virtual File System (VFS) and block layer using read(2) and write(2) system calls. It allocates a memory buffer matching the specified block size (bs) and streams data sequentially from the input file descriptor (if) to the output file descriptor (of). By default, write calls pass through the kernel page cache; however, passing conversion and synchronization flags like conv=fsync or oflag=direct instructs the kernel to flush dirty pages to physical media or bypass the page cache entirely using Direct I/O (O_DIRECT).

The block size (bs) parameter fundamentally dictates performance. If bs is omitted, dd defaults to a historical 512-byte block size, resulting in millions of context switches between userland and kernel space and severely crippling I/O throughput. Setting bs=4M or bs=1M allows dd to fill storage controller buffers efficiently, maximizing sequential throughput across modern SATA, SAS, and NVMe hardware.

Under the hood, dd gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as if=<file>, of=<file>, bs=<bytes>, count=<n> turns raw process and service tables into actionable diagnostics during incident response.

Availability and Installation Across Linux Distributions

The dd utility is packaged in coreutils across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:

Advertisement

Before running administrative tasks or automation scripts, verify whether dd is installed and inspect which binary path and version your shell resolves:

type -a dd
dd --version 2>/dev/null || man -f dd

# Illustrative output (reviewed against documentation)
dd is /usr/bin/dd
dd (coreutils)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y coreutils

# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y coreutils

# Arch Linux
sudo pacman -S --noconfirm coreutils

# Alpine Linux
sudo apk add --no-cache coreutils

Command Syntax, Arguments, and Exit Status Codes

dd [OPERAND]...

Unlike modern GNU utilities that use hyphenated options (like -f or --file), dd preserves historical JCL-inspired operand syntax consisting of key=value pairs. The input source is specified by if=path (input file), and the target destination is set by of=path (output file). Omitting if reads from standard input (stdin), and omitting of writes to standard output (stdout), enabling seamless integration into shell pipes.

Data volume and positioning are controlled with bs=bytes (block size for both read and write), count=blocks (copy only this many blocks), skip=blocks (skip blocks at the start of input), and seek=blocks (skip blocks at the start of output). Modern GNU coreutils dd introduces status=progress, which displays real-time throughput metrics, elapsed time, and total bytes copied without requiring external kill signals.

  • 0 — Successful completion; all requested blocks were read and written without error.
  • 1 — Operational error during read or write operations (e.g., I/O error or disk full).
  • 2 — Malformed operand or invalid syntax specified on command line.
  • 130 — Process interrupted by user signal (SIGINT, Ctrl+C).

Important Options and Flags Reference

Option / FlagLong Form / ArgumentTechnical Behavior and Purpose
if=<file>--input-file=<file>Specifies the input source file, partition, or block device (defaults to stdin).
of=<file>--output-file=<file>Specifies the destination target file, partition, or block device (defaults to stdout).
bs=<bytes>--block-size=<bytes>Sets both input and output block size (e.g., 512, 64K, 1M, 4M).
count=<n>--count=<n>Copies only <n> input blocks before stopping.
skip=<n>--skip=<n>Skips <n> blocks at the beginning of the input file before starting copy.
seek=<n>--seek=<n>Skips <n> blocks at the beginning of the output file before writing.
status=<mode>--status=<mode>Controls console output; status=progress prints real-time transfer stats.
conv=<flags>--conversion=<flags>Applies data conversions (e.g., fsync, noerror, sync, notrunc).
oflag=<flags>--output-flags=<flags>Sets open flags for output file (e.g., sync, direct, dsync).

When creating bootable USB media or cloning partitions, the flag combination bs=4M status=progress oflag=sync is recommended. The 4MB block size ensures high-speed streaming, status=progress provides visual ETA feedback, and oflag=sync forces every block to be physically written to hardware before dd exits, preventing corrupt drives when unplugged.

Advertisement

When rescuing data from a damaged hard drive with bad sectors, combining conv=noerror,sync is critical. The noerror flag instructs dd to continue reading after encountering I/O errors rather than halting, and sync pads missing data blocks with null bytes to preserve relative sector offsets.

When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.

Practical Basic and Advanced Usage Examples

1. Clone an Entire Physical Disk Directly to Another Disk

Replicate all partitions, bootloaders, and data blocks from a source drive (/dev/sda) to a destination drive (/dev/sdb).

sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress conv=fsync

# Illustrative output (reviewed against documentation)
492830720000 bytes (493 GB, 459 GiB) copied, 320 s, 1.5 GB/s
119232+0 records in
119232+0 records out
500107862016 bytes (500 GB, 466 GiB) copied, 324.52 s, 1.5 GB/s

This command reads 4MB blocks from /dev/sda and writes them sequentially to /dev/sdb, finishing with conv=fsync to flush cache buffers.

2. Create a Compressed Disk Image Backup Piped Through Gzip

Back up a storage partition to a compressed .img.gz file, omitting unused zeroed blocks effectively.

sudo dd if=/dev/nvme0n1p2 bs=64K status=progress | gzip -c > /mnt/backups/root_backup.img.gz

# Illustrative output (reviewed against documentation)
21474836480 bytes (21 GB, 20 GiB) copied, 45 s, 477 MB/s
# Output compressed and written to /mnt/backups/root_backup.img.gz

By piping standard output of dd into gzip, the image is compressed on the fly without storing an intermediate uncompressed image file on disk.

3. Burn a Bootable Linux Installer ISO to a USB Flash Drive

Write an installation ISO directly to a raw USB block device with synchronization flags.

sudo dd if=ubuntu-24.04-live-server.iso of=/dev/sdc bs=4M status=progress oflag=sync

# Illustrative output (reviewed against documentation)
2831155200 bytes (2.8 GB, 2.6 GiB) copied, 38 s, 74.5 MB/s
675+0 records in
675+0 records out
2831155200 bytes (2.8 GB, 2.6 GiB) copied, 38.12 s, 74.3 MB/s

Writing directly to /dev/sdc (the entire drive, not /dev/sdc1) creates the hybrid ISO9660/GPT partition layout required for UEFI booting.

4. Back Up and Restore Master Boot Record (MBR)

Save the first 512 bytes of a disk containing the MBR bootloader and partition table entries.

sudo dd if=/dev/sda of=mbr_backup.bin bs=512 count=1

# Illustrative output (reviewed against documentation)
1+0 records in
1+0 records out
512 bytes copied, 0.00012 s, 4.3 MB/s

Setting bs=512 and count=1 extracts exactly sector zero, preserving partition definitions and bootstrap code for disaster recovery.

5. Securely Wipe a Drive by Overwriting with Zeros

Sanitize a decommissioned storage drive by writing zero bytes across every sector.

sudo dd if=/dev/zero of=/dev/sdd bs=4M status=progress

# Illustrative output (reviewed against documentation)
dd: error writing '/dev/sdd': No space left on device
238475+0 records in
238474+0 records out
1000204886016 bytes (1.0 TB, 931 GiB) copied, 720 s, 1.4 GB/s

Writing /dev/zero until the device is full overwrites all file systems, partition tables, and file fragments with null bytes.

6. Benchmark Sequential Disk Write Speed with Direct I/O

Measure raw storage throughput by writing a 1GB test file while bypassing the OS kernel page cache.

dd if=/dev/zero of=/tmp/benchmark.dat bs=1G count=1 oflag=direct

# Illustrative output (reviewed against documentation)
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.628 s, 1.7 GB/s

The oflag=direct flag bypasses the Linux page cache, giving an accurate measurement of true sequential physical disk write performance.

Real-World Workflows, Pipelines, and Shell Automation

Bare-Metal Disaster Recovery Backup and Restoration Pipeline

Create a verified, checksum-validated compressed disk image and restore it to a replacement drive during hardware recovery.

#!/usr/bin/env bash
set -euo pipefail

SRC_DEV="/dev/sdb"
IMAGE="/mnt/nas/backup_sdb.img.gz"

echo "[BACKUP] Streaming raw blocks from $SRC_DEV to $IMAGE..."
sudo dd if="$SRC_DEV" bs=1M status=progress | gzip -c > "$IMAGE"
echo "[BACKUP] Image created. Verifying integrity..."
gzip -t "$IMAGE"
echo "[SUCCESS] Backup verified successfully."

# Illustrative output (reviewed against documentation)
[BACKUP] Streaming raw blocks from /dev/sdb to /mnt/nas/backup_sdb.img.gz...
1000204886016 bytes (1.0 TB) copied, 650 s, 1.5 GB/s
[BACKUP] Image created. Verifying integrity...
[SUCCESS] Backup verified successfully.

Piping block streams through gzip with immediate gzip -t verification guarantees reliable image archives without uncompressed disk overhead.

Cryptographic Disk Sanitization Workflow Prior to Hardware Decommissioning

Wipe a decommissioned hard drive with pseudo-random bytes from /dev/urandom followed by a zeroing verification pass.

#!/usr/bin/env bash
set -euo pipefail

TARGET="/dev/sdd"
echo "[SECURITY] Overwriting $TARGET with cryptographically secure random bytes..."
sudo dd if=/dev/urandom of="$TARGET" bs=4M status=progress || true

echo "[SECURITY] Overwriting with zeros pass..."
sudo dd if=/dev/zero of="$TARGET" bs=4M status=progress || true
sync
echo "[SUCCESS] Drive $TARGET thoroughly sanitized."

# Illustrative output (reviewed against documentation)
[SECURITY] Overwriting /dev/sdd with cryptographically secure random bytes...
1000204886016 bytes (1.0 TB) copied, 1820 s, 549 MB/s
[SECURITY] Overwriting with zeros pass...
1000204886016 bytes (1.0 TB) copied, 710 s, 1.4 GB/s
[SUCCESS] Drive /dev/sdd thoroughly sanitized.

Writing random bytes scrambles any magnetic remnants, and the final zeroing pass leaves the drive cleanly unallocated.

Pipelines, Redirection, Quoting, and Shell Expansion

When embedding dd inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.

Permissions, Security Implications, and Safe Execution

Because dd accesses raw block devices directly, it completely bypasses Linux filesystem permission checks and Access Control Lists (ACLs). Any user with write permissions to a block device (or root via sudo) can overwrite partition tables, overwrite encrypted LUKS headers, or extract unencrypted file contents directly from raw sectors.

When securely sanitizing hard drives before disposal, a single pass with dd if=/dev/zero of=/dev/sdX bs=4M is legally sufficient for modern high-density magnetic drives according to NIST Special Publication 800-88 guidelines. However, for solid-state drives (SSDs and NVMe), hardware-level ATA Secure Erase or NVMe Format (nvme format) is preferred because flash wear-leveling algorithms prevent dd from reliably overwriting reserved flash cells.

GNU/Linux, BSD, and BusyBox Implementation Differences

The status=progress operand is a GNU coreutils extension. BSD dd (used on macOS and FreeBSD) does not support status=progress; instead, users on BSD systems must press Ctrl+T (which sends SIGINFO) or dispatch kill -USR1 $(pgrep ^dd$) from another terminal to print progress.

On BusyBox systems (embedded devices and Alpine Linux), dd supports basic if, of, bs, count, and conv flags, but omits status=progress and advanced oflag options unless coreutils is installed.

Troubleshooting Common Errors and Diagnostics

dd: failed to open 'of': Permission denied

Root Cause: Targeting raw block device files (like /dev/sdb) requires root privileges, which an unprivileged user cannot write to.

Resolution: Prepend sudo to the dd command, or ensure output redirection happens inside a privileged subshell.

sudo dd if=image.iso of=/dev/sdc bs=4M status=progress

Extremely slow transfer speed during copy

Root Cause: The bs parameter was omitted, causing dd to fall back to the default historical 512-byte block size.

Resolution: Specify a modern block size such as bs=1M or bs=4M to utilize disk controller buffers effectively.

sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress

Target USB drive corrupted or unbootable after dd finishes

Root Cause: The user unplugged the drive while unwritten blocks were still lingering in the Linux kernel page cache.

Resolution: Always pass oflag=sync or run sync immediately after dd completes before removing the physical device.

sudo dd if=ubuntu.iso of=/dev/sdc bs=4M status=progress oflag=sync
sync

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
The command earned this moniker because a simple typo in the output operand (such as typing of=/dev/sda instead of of=/dev/sdb) will immediately and irreversibly overwrite the partition table and filesystems of your primary boot drive without asking for confirmation.
For cloning modern drives, writing ISOs, or wiping disks, bs=4M (4 Megabytes) is standard and optimal. It matches hardware controller buffers, minimizing CPU context switching. For small boot sector operations (like MBR backup), use bs=512.
On older GNU systems or BSD/macOS where status=progress is absent, send a SIGUSR1 (on Linux) or SIGINFO (on BSD) signal to the process: sudo kill -USR1 $(pgrep ^dd$). The dd process will print current statistics to stderr without interrupting the transfer.
The conv=fsync flag forces dd to issue an fsync() system call before exiting, ensuring all cached writes are physically flushed to disk media. This guarantees data integrity before you disconnect or reboot the system.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout