The dd (Data Duplicator) command is one of the most powerful utilities in Unix and Linux operating systems. It is used for low-level data copying, disk cloning, and file conversion. Because it interacts directly with raw storage volumes, it is highly efficient but also carries risks—a single typo can overwrite an entire hard drive.
This DDQuickReference provides the essential syntax, core parameters, and practical examples needed to use the dd utility safely. Core Syntax and Parameters
The basic structure of a dd command relies on keyword arguments rather than standard dash flags. dd if=[source] of=[destination] [arguments] Use code with caution. if=: Input file or device path (the data source). of=: Output file or device path (the destination).
bs=: Block size for reading and writing data (e.g., 4M for 4 Megabytes). count=: The specific number of blocks to copy.
status=progress: Displays a real-time transfer speed and progress indicator.
conv=: Conversions to apply to the data stream (e.g., fsync to flush data to disk). Essential Examples 1. Creating a Bootable USB Drive
To write a downloaded Linux installation image to a physical USB flash drive:
sudo dd if=ubuntu-desktop.iso of=/dev/sdX bs=4M status=progress conv=fdatasync Use code with caution.
(Replace /dev/sdX with the precise identifier of your USB drive. Selecting the wrong drive will erase data.) 2. Cloning an Entire Hard Drive
To make an exact bit-for-bit duplicate of one physical hard drive onto another storage device: sudo dd if=/dev/sda of=/dev/sdb bs=64K status=progress Use code with caution. 3. Backing Up a Drive to a Compressed Image File
To save a complete backup of a drive partition as a compressed file to save space:
sudo dd if=/dev/sda1 bs=4M | gzip > /path/to/backup/image.gz Use code with caution. 4. Creating a Blank File (For Swap Space or Virtual Disks)
To generate an empty, fixed-size file filled entirely with zeros: dd if=/dev/zero of=swapfile bs=1M count=1024 Use code with caution.
(This example creates a 1 Gigabyte file by writing 1024 blocks of 1 Megabyte each.) 5. Securely Wiping a Drive
To overwrite an entire storage drive with random data, making data recovery extremely difficult: sudo dd if=/dev/urandom of=/dev/sdX bs=4M status=progress Use code with caution. Key Precautions
Verify Device Names: Always run lsblk or sudo fdisk -l to check your drive partitions before executing a command.
Unmount Devices: Ensure target partitions are unmounted (sudo umount /dev/sdX) before writing data to prevent filesystem corruption.
Root Privileges: Most hardware-level dd operations require prefixing the command with sudo. If you need to tailor this reference, let me know:
What specific operating system or distribution you are targeting.
The storage media you are working with (e.g., NVMe, SD cards, virtual disks).
If you need to see advanced data recovery flags like noerror and sync. ‘dd’ Command in Linux: Explained – GeeksforGeeks
Leave a Reply