Useful DD Commands

Published 11-15-2018 20:29:22

Duplicate several drives concurrently

dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc

If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel.

To improve efficiency, specify a larger block size in dd:

dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64k

To image more drives, insert them as additional arguments to tee:

dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde

Create an emergency swapfile when the existing swap space is getting tight

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile

Create a temporary file that acts as swap space. In this example it’s a 1GB file at the root of the file system. This additional capacity is added to the existing swap space.

Backup your hard drive with dd

sudo dd if=/dev/sda of=/media/disk/backup/sda.backup

This will create an exact duplicate image of your hard drive that you can then restore by simply reversing the “if” & “of” locations.

sudo dd if=/media/disk/backup/sda.backup of=/dev/sda

Alternatively, you can use an SSH connection to do your backups:

dd if=/dev/sda | ssh dd of=~/backup/sda.backup

Convert a Nero Image File to ISO

dd bs=1k if=image.nrg of=image.iso skip=300

This line removes the 300k header from a Nero image file converting it to ISO format

Send DD a signal to print its progress

while :;do killall -USR1 dd;sleep 1;done

every 1sec sends DD the USR1 signal which causes DD to print its progress.

Show dd progress part 2

killall -USR1 dd

if you need see progress of long dd command, enter subj on other console

How to copy CD/DVD into hard disk (.iso)

dd if=/dev/cdrom of=whatever.iso

Watch the progress of ‘dd’

dd if=/dev/zero | pv | dd of=/dev/null

need pv (pipe view)

Clone IDE Hard Disk

sudo dd if=/dev/hda1 of=/dev/hdb2

This command clone the first partition of the primary master IDE drive to the second partition of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)

Test network speed without wasting disk

dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'

The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space. Of course, change the byte size and count as necessary.

This command also doesn’t rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems.

Clone a hard drive to a remote directory via ssh tunnel, and compressing the image

dd if=/dev/sda | gzip -c | ssh user@ip 'dd of=/mnt/backups/sda.dd'