Tips Linux Explorers   All Things Linux Forum   Great Linux Links   LinuxClues.com   Hometown   Email 



THE DD COMMAND


This is one of the more complex Linux commands and actually not really suited for new Linux users. But still I would like to give you a little taste of it.

The dd command copies an amount of data block by block. The most basic syntax is:

CODE
# 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 )
But as you might have guessed, the dd command it is much more than that, it can optionally convert data ( ASCII to EBCDIC ), skip blocks, continue after read errors, change uppercase letters to lowercase, etc, etc. ( type "info dd" in a terminal to get the full list of options )

I will now give you a few examples of what dd can do, but I do urge you to have a look at the links posted below to get more detailed information before you really start experimenting with the dd command.




Copy a hard disk partition to another hard disk:

CODE
# dd if=/dev/hda2 of=/dev/hdb2 bs=4096 conv=notrunc,noerror




Cloning an entire hard disk:

CODE
# 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 ! ):

CODE
# dd if=/dev/hdb2 of=/home/bruno/partition.image bs=4096 conv=notrunc,noerror

Restore a disk partition from an image file:

CODE
# dd if=/home/bruno/partition.image of=/dev/hdb2 bs=4096 conv=notrunc,noerror




Copy MBR only of a hard drive:

CODE
# dd if=/dev/hda of=/home/bruno/MBR.image bs=446 count=1

Reverse:

CODE
# dd if=/home/bruno/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 ):

CODE
# dd if=/dev/zero of=/dev/hda conv=notrunc




Make an iso image of a CD:

CODE
# dd if=/dev/hdc of=/home/bruno/TEST.iso bs=2048 conv=notrunc

( CD sectors are 2048 bytes, so this copies sector for sector. )




Copy a floppy disk:

CODE
# dd if=/dev/fd0 of=/home/bruno/floppy.image conv=notrunc




You can back up your MBR ( including partition table ):

CODE
# dd if=/dev/hda of=mbr.bin count=1

Put this on a floppy you make with:

CODE
# dd if=boot.img of=/dev/fd0

Boot from the floppy and restore the MBR:

CODE
# dd if=mbr.bin of=/dev/hda count=1




Again, I urge you to be very careful with the DD command . . . switching if= with of= can have catastrophic results.



An extensive how-to of the dd command can be found here: Learn The DD Command   Please read it before you start typing "dd" !!
Maybe also read: Codecoffee



Bruno



-- Apr 22 2007 --


Tips Linux Explorers   All Things Linux Forum   Great Linux Links   LinuxClues.com   Hometown   Email