DD comand examples
THE DD COMMANDThe dd command copies an amount of data block by block. The most basic syntax is:
Format
# dd if=xxxxx of=yyyyy bs=zzzzzz
( Where if=xxxxx is the source, of=yyyyy is the target and bs= both read and write zzzzz bytes at a time )
Examples:
Copy a hard disk partition to another hard disk:
# dd if=/dev/hda2 of=/dev/hdb2 bs=4096 conv=notrunc,noerror
Cloning an entire hard disk:
# dd if=/dev/hda of=/dev/hdb conv=notrunc,noerror
Copy a disk partition to a file on a different partition. ( Do not copy a partition to the same partition ! ):
# dd if=/dev/hdb2 of=/home/test/partition.image bs=4096 conv=notrunc,noerror
Restore a disk partition from an image file:
# dd if=/home/test/partition.image of=/dev/hdb2 bs=4096 conv=notrunc,noerror
Mount a existing dd image:
# mount -o loop /path/your-dd-image /mnt/test
Copy MBR only of a hard drive:
# dd if=/dev/hda of=/home/test/MBR.image bs=446 count=1
Reverse:
# dd if=/home/test/MBR.image of=/dev/hda bs=446 count=1
Wipe a hard drive of all data ( you would want to boot from a cd to do this ):
# dd if=/dev/zero of=/dev/hda conv=notrunc
Make an iso image of a CD:
# dd if=/dev/hdc of=/home/test/TEST.iso bs=2048 conv=notrunc
( CD sectors are 2048 bytes, so this copies sector for sector. )
Copy a floppy disk:
# dd if=/dev/fd0 of=/home/test/floppy.image conv=notrunc
You can back up your MBR ( including partition table ):
# dd if=/dev/hda of=mbr.bin count=1
Put this on a floppy you make with:
# dd if=boot.img of=/dev/fd0
Boot from the floppy and restore the MBR:
# dd if=mbr.bin of=/dev/hda count=1
How to check dd progress
=================
By the way, if you need to restore a large image file and want to see what the progress is, you can use the following command from a new terminal session:
kill -USR1 $pid
You can find dd command’s pid by using ps and grep commands like:
ps -A | grep dd
If you want to check an automatic progress, use “watch” command:
watch kill -USR1 $pid