Operations 15 min read

Mastering Linux dd: Powerful Data Copy, Backup, and Disk Operations

Learn how to use the Linux dd command for low‑level I/O tasks, including copying, converting, creating backups, generating files, testing disk speed, creating swap space, making bootable USB drives, and handling MBR, with detailed parameter explanations and practical examples.

Linux Cloud Computing Practice
Linux Cloud Computing Practice
Linux Cloud Computing Practice
Mastering Linux dd: Powerful Data Copy, Backup, and Disk Operations

dd is a Linux/Unix utility for low‑level I/O, allowing block‑size‑specified copying and conversion of files.

Parameters

if=FILE      # input file, default stdin
of=FILE      # output file, default stdout
ibs=SIZE     # input block size (default 512)
obs=SIZE     # output block size (default 512)
bs=SIZE      # both input and output block size (overrides ibs/obs)
count=N      # copy only N input blocks
status=LEVEL # progress display level (none, noxfer, progress)
iflag=FLAGS  # input flags (append, direct, etc.)
oflag=FLAGS  # output flags
conv=OPTIONS # conversion options (ascii, ebcdic, lcase, ucase, sync, …)

Common Examples

# Backup partition /dev/vdb1 to /dev/vdb2
dd if=/dev/vdb1 of=/dev/vdb2 status=progress

# Backup to a file
dd if=/dev/vdb1 of=/opt/backupsFile.back status=progress

# Restore from backup file
dd if=/opt/backupsFile.back of=/dev/vdb1 status=progress

# Create a 1 GB file (e.g., swap file)
dd if=/dev/zero of=/tmp/swapFile bs=1M count=1024 status=progress

# Compress a partition backup
dd if=/dev/vdb1 status=progress | gzip > /opt/backups.gz

# Decompress and restore
gzip -dc /opt/backups.gz | dd of=/dev/vdb2 status=progress

# Generate a 10 M test file
dd if=/dev/zero of=/tmp/testFile bs=1M count=10

# Test disk write speed
timeout 120 dd if=/dev/zero of=/tmp/speed.dat bs=2M count=1000 oflag=direct

# Test disk read speed
timeout 120 dd if=/tmp/speed.dat of=/dev/null bs=2M count=1000 status=progress

# Create a bootable USB from an ISO
sudo dd if=ubuntu-23.10.1-desktop-amd64.iso of=/dev/sdb status=progress

# Backup MBR (first 512 bytes)
dd if=/dev/vda of=/opt/mbr.bak bs=512 count=1

# Restore MBR
dd if=/opt/mbr.bak of=/dev/vda bs=512 count=1

Additional Notes

Use conv=lcase or conv=ucase to change character case, conv=sync to pad blocks, and conv=sparse to create sparse files. /dev/zero provides an endless stream of zero bytes, while /dev/null discards all output.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Data Conversiondisk backupdd command
Linux Cloud Computing Practice
Written by

Linux Cloud Computing Practice

Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.