The DistRogue

Sunday, November 11, 2007

dd: The Great Destroyer and Creator

Buried deep in the Linux man pages is a command called dd. You know how short commands like cat, ps, grep, rm or mv are really powerful? dd owns all of them. It copies data between block files- image files or device files. It's simple enough- to use it, just run
dd if=[input] of=[output]

But there are a lot of things you can put in [input] and [output], and some of the could be dangerous. Here are some of the things you can do with it:
-Write a disk image onto a CD, DVD, or USB key:
dd if=[file] of=/dev/sdb1 (as an example)

-Make a compressed backup of a USB key:
dd if=/dev/sdb1 | bzip2 > backup.img.bz2

-Erase your entire hard drive:
dd if=/dev/zero of=/dev/sda

-Securely erase your hard drive:
dd if=/dev/urandom of=/dev/sda
dd if=/dev/zero of=/dev/sda

-Make an ext3 filesystem and mount it at /media/fs:
mkdir /media/fs
dd if=/dev/zero of=fs.ext3 bs=512k count=
mke3fs fs.ext3
mount fs.ext3 /media/fs

-Add a gigabyte-size swap file without rebooting or making any new partitions:
dd if=/dev/zero of=swap bs=1M count=1024
mkdwap swap
swapon swap

Don't try any of these at home unless you're sure what you're doing. dd is a very powerful and useful command, but don't use it unless you need to.
As for reviews: I'm trying to get Sabayon3.4 Mini to run off of my USB key, but if I can't, on to Fedora 8.
From gOS 1.0,
The DistRogue.
UPDATE: I used angle brackets <> for the examples, but I had to change them to square brackets because [input] (with <> instead of []) is a valid HTML tag. 0.o... Learn from me.

Labels: ,

0 Comments:

Post a Comment

<< Home