How to Use the ‘dd’ Command for Low-Level Disk Cloning and Data Wiping

The “Disk Destroyer”

When you use the cp command to copy a file, Linux interacts with the file system (like ext4 or NTFS) to read the data and write it somewhere else. But what if you want to copy an entire hard drive, including the master boot record, the partition tables, and the hidden recovery sectors? Standard copy commands cannot do this because they operate at the file level.

To interact directly with the raw, physical blocks of a storage device, Linux administrators use the dd (Data Definition) command. dd is a bit-stream copier. It ignores files and folders; it simply reads raw ones and zeros from an input device and writes them directly to an output device.

CRITICAL WARNING: dd is famously nicknamed “Disk Destroyer.” If you accidentally reverse the input and output targets, you will instantly and irretrievably overwrite your entire operating system. You must use extreme caution.

The Basic Syntax

The syntax of dd is archaic and uses an unusual if= (input file) and of= (output file) structure.

sudo dd if=[source] of=[destination] bs=[block_size] status=progress
  • if=: Where the data is coming from.
  • of=: Where the data is going.
  • bs=: The block size (how much data to read/write at a time, usually 4M for modern drives).
  • status=progress: dd is totally silent by default. This flag forces it to show a progress bar.

1. Cloning a Hard Drive (1:1 Copy)

Assume you have an old 500GB hard drive (/dev/sda) and you want to clone it perfectly to a new 1TB hard drive (/dev/sdb).

First, use lsblk to absolutely confirm which drive is which. Then, run the clone:

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

This will create a perfect, bootable clone. The new drive will be identical down to the microscopic partition boundaries.

2. Creating a Bootable USB Drive

If you download an Ubuntu .iso file and drag it onto a USB flash drive, it will not boot. You must write the raw ISO image directly to the boot sector of the USB drive.

Assuming your USB drive is /dev/sdc:

sudo dd if=/home/user/Downloads/ubuntu.iso of=/dev/sdc bs=4M status=progress

This destroys whatever was on the USB drive and transforms it into a bootable Linux installation disk.

3. Securely Wiping a Drive

Before throwing away or selling an old hard drive, you must destroy the data. You can use dd to overwrite the entire drive with zeros.

Linux has a special virtual file called /dev/zero that simply outputs an infinite stream of zeros.

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

If you are paranoid about forensic recovery and zeros aren’t enough, you can overwrite the drive with completely randomized cryptographic noise using /dev/urandom:

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

(Note: Writing random data takes significantly longer than writing zeros because the CPU has to generate the math for the random numbers).

4. Creating a Raw Backup Image

Instead of cloning directly from drive to drive, you can tell dd to copy the entire drive into a single, massive file (an image) that you can store on a backup server.

sudo dd if=/dev/sda of=/mnt/backupserver/server_backup.img bs=4M status=progress

You can later use dd to restore that image back onto a fresh hard drive by simply reversing the if= and of= paths.

Conclusion

The dd command is the ultimate, brute-force utility for storage management. It does not care about file systems, permissions, or formatting; it simply moves blocks of data with absolute precision. While dangerous in the hands of a novice, it is an indispensable tool for forensic imaging, system cloning, and secure data destruction.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.