Re: DD vs normal writing question



gordon@xxxxxxxxxx (Gordon Henderson) writes:

In article <jg34i4-ti9.ln1@xxxxxxxxxxxxxxxxxx>,
Martin Gregorie <martin@xxxxxxxxxxxxxxxxxxx> wrote:
I recently found a couple of scripts that wipe free space on partitions
and swap space. The guts of both is the line:

dd if=/dev/urandom of=_freespace_

which runs until the partition fills up. Then the script executes fsync
twice and deletes _freespace_. The swap space wiper disables swapping,
wipes the partition and then turns swapping back on.

Only problem is that its pretty slow, so I wrote a bit of C that does
the same thing, but with the loop:

errno=0;
while (errno == 0)
{
rnd = rand();
fwrite(&rnd, 1, sizeof(rnd), w);
}

This runs about 8x faster with its output redirected to disk. I've tried
it as a single line replacement for dd in an otherwise unchanged copy of
the free space wiping script with apparently good results.

The question is what, if anything, does dd do that my code doesn't?
Should my code clear the swap partition or is there something in swap
partition format that means only dd can write to it?

dd is reading from /dev/urandom - that's pretty random, not quite as random
as /dev/random, but that will be slower still.

That would be completely and utterly silly. /dev/random blocks. It would
take you maybe a year, maybe 100 years to wipe your disk if you used
/dev/random.
(Unless dd bails out on block and simply uses zeros to pad the block)


As there are those who say that data can be recovered, even after
several passes with this, if all you're doing is something "quick
and dirty" just use /dev/zero rather than /dev/random.

Not sure who says that anymore.



And have a look at the manual page for "shred" ..

Gordon
.