dilbert

Fiepke.nl

nixcraft

Slashdot

The Daily WTF

XKCD

Toothpaste for Dinner

Ars Tech

Google News

PBFComics

linux voice

SMBC

coindesk

MAGPIE php feed reader

dd examples

The unix dd page on wikipedia removed the abundant examples at some point in time. (It's an encyclopedia, not a howto, so it makes sense.) Anyways, I copied the example part from the history, and pasted it here to keep the reference. There were some non-absolute links that got copied along, I'll clean those up when I feel like it.

Examples

Note: Read the man page for your dd command before trying examples as your system may be different. These examples are for Linux: on other platforms the device names may be different and have different semantics. You must still adjust the commands to your platform. Make sure the if (source) and of (target) is specified correctly, or you may lose data.

  • To create an ISO image file named image.iso of a CD. Insert the source CD and unmount it first if auto CD mount is enabled, this is to improve performance by preventing random access to the mounted filesystem.
dd if=/dev/cdrom of=image.iso bs=2k
  • To create an image file named floppy.img of a floppy disk:
dd if=/dev/fd0 of=floppy.img
  • To copy the image file back to a floppy:
dd if=floppy.img of=/dev/fd0 bs=18k
  • To create a file of the size 1 GB with the name reallylargefile, filled with random data:
dd if=/dev/random of=reallylargefile count=2M
  • As above but faster and cryptographicly less secure
dd if=/dev/urandom of=reallylargefile count=2M
  • As above but faster by increasing block size:
dd if=/dev/urandom of=reallylargefile count=256k obs=4096
  • To create a file of the size 10 GB with the name virtualpartition, filled with zeros, and make it available as a ext2 virtual partition:
dd if=/dev/zero of=virtualpartition bs=1M count=10k
mke2fs virtualpartition (reply yes when it says it's not a block device)
mkdir /mnt/virtual
mount -o loop virtualpartition /mnt/virtual/
  • To create a 10GB sparse file which doesn't allocate any actual space (if the filesystem supports this feature):
dd if=/dev/zero of=sparsefile.img bs=1 seek=10G count=0
  • To copy the first partition of the first hard disk to the file partitionone.
dd if=/dev/hda1 of=partitionone
  • To copy the first IDE-harddisk (master) to the second IDE-hard disk (slave), i.e. clone the drive including file systems, partition tables and the master boot record.
dd if=/dev/hda of=/dev/hdb

For many more examples of the Linux dd command, which is the same as the UNIX version, go here: http://www.linuxquestions.org/questions/showthread.php?t=362506

Under Windows (GNU Unix Utils)

dd is available with the GNU Unix Utils.

Windows devices are named like \.\PhysicalDrive0 or \.\CDROM0.

To turn a CD into an ISO image:

dd if=\.\CDROM0 of=cdimage.iso obs=2048

Under Windows (Cygwin)

dd is also available within Cygwin (www.cygwin.com)

The CD-Rom is typically available as /dev/scd0 (first SCSI-device).

To turn a CD into an ISO image do

dd if=/dev/scd0 of=cdimage.iso obs=2048

To turn a 3½" floppy into an image file do

Mount the floppy

mount -f -b //./a: /dev/fd0

Create the image

dd if=/dev/fd0 of=fdimage.img count=1 bs=1440k

Unmount the floppy

umount /dev/fd0

Anti-examples

Warning WARNING: Do NOT try these examples; they will cause data loss!

The following examples are provided to warn about the dangers of dd, if used incorrectly. Trying any of these commands with the proper privileges will almost certainly result in major data loss, and may make the system unusable. In order to prevent accidental copying and pasting, "dd" has been replaced with "[dd]" here.

This overwrites the complete first hard disk with null bytes, erasing it (though not in a manner that is as secure as overwriting with random data):

[dd] if=/dev/zero of=/dev/hda

This overwrites the first few blocks of the first hard disk with the file, resulting in a loss of the partition table:

[dd] if=funnysong.mp3 of=/dev/hda

This will completely corrupt an entire hard disk (/dev/dsp is the sound player/recorder):

[dd] if=/dev/dsp of=/dev/hda

This will overwrite an entire disk with pseudorandom data, making its initial contents unrecoverable outside a clean room in a hard drive forensics laboratory, and probably unrecoverable there as well.

[dd] if=/dev/urandom of=/dev/hda

The examples above presume device names (valid on some Linux systems) that may be different on other platforms. Here are some common variations.

Mac OS X:

[dd] if=/dev/zero of=/dev/disk0

Minix:

[dd] if=/dev/zero of=/dev/c0d0p0

NetBSD/OpenBSD (does not work if securelevel > 1):

[dd] if=/dev/zero of=/dev/rwd0