dd
The dd command in Linux is a powerful utility for low-level data copying and conversion, primarily used for disk cloning, creating disk images, partition backups, and writing ISO files to USB drives. Mastering the dd command is essential for Linux system administrators, as it enables precise control over data manipulation, backup processes, and disk recovery.
| Option | Description | Example |
|---|---|---|
| if= | Input file or device (e.g., disk or ISO) | if=/dev/sda |
| of= | Output file or device (e.g., target disk or image file) | of=/dev/sdb |
| bs= | Block size for input/output operations | bs=4M |
| status= | Display the status of the operation | status=progress |
| conv= | Conversion options (e.g., noerror, sync) | conv=noerror,sync |
| seek= | Skip blocks in the output file | seek=1 |
| count= | Limit the number of blocks to copy | count=100 |
Speedtest a harddrive
dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct status=progress
Copy a drive to another (works for uefi)
dd if=/dev/sda of=/dev/sdb bs=32M status=progress
Create a 500mb file
dd if=/dev/zero of=fil_500mb.bin bs=1M count=500
Output your microphone to a remote computer's speaker
This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
Processor / memory bandwidthd in GB/s
Read 32GB zero's and throw them away. How fast is your system?
dd if=/dev/zero of=/dev/null bs=1M count=32768
Create an emergency swapfile when the existing swap space is getting tight
dd if=/dev/zero of=/swapfile bs=1024 count=1024000
mkswap /swapfile
swapon /swapfile
Efficient remote forensic disk acquisition gpg-crypted for multiple recipients
dd if=/dev/sdb | pigz | gpg -r <recipient1> -r <recipient2> -e --homedir /home/to/.gnupg | nc remote_machine 1337
Wipe a failed disk - If you can't use shred or ddrescue, this is a very slow but portable alternative
i=0
while true ; do
echo "Writing block $i"
dd if=/dev/zero of=/dev/sda count=1 bs=1 seek="$i"
let i=i+1
done
Wipe first and last 1G of a hard disk
dd bs=4096 if=/dev/zero of=/dev/sdx count=256 seek=$(( $(blockdev --getsz /dev/sdx) - 256))
uuid generator
dd if=/dev/urandom bs=16 count=1 2>/dev/null \
| tr -dc '0-9a-f' </dev/urandom | head -c 32 \
| fold -w 4 \
| paste -sd '' - \
| sed 's/^\(........\)\(....\)\(....\)\(....\)\(............\)$/\1-\2-\3-\4-\5/'
Resource(s)