Graham Knap(deleted)
|
Re: How to zero-fill a block device
|
Graham Knap(deleted)
04/18/2011 11:28 AM
post85094
|
Re: How to zero-fill a block device
> # echo -n '\00' > zero
> # cat zero >> zero
If I'm not mistaken, this would create a file full of zeroes, filling all free space in a filesystem. It is really,
really painfully slow, and I'm not sure that it would work for completely clearing a block device -- but it is
interesting nonetheless.
Here's one crazy-looking method that I came up with. This seems to work, and it's what I'm using for now. It's simple
but certainly not very efficient.
# tr -r /dev/hdX "[\000-\377]" "\000"
Here's another interesting item that I stumbled upon. Executing "wc -c" on a block device returns the size of the device
, in blocks. (I have no idea why; maybe someone can explain this.) Anyway, if you start with a 512-byte file full of
zeroes:
# rm /tmp/zero
# i=0; while [ $i -lt 32 ]; do
> echo -n '\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00' >> /tmp/zero
> let i=$i+1
> done
or maybe
# dd if=/dev/hdX count=1 | tr "[\000-\377]" "\000" > /tmp/zero
then I think it should be possible to zero-fill a block device as follows:
# blocks=`wc -c /dev/hdX`
# i=0; while [ $i -lt $blocks ]; do
> dd if=/tmp/zero of=/dev/hdX seek=$i 2>/dev/null
> let i=$i+1
> done
I don't see a "quiet" option for "dd", hence the redirection of its stderr.
I'm still open to better ideas if anyone has them.
|
|
|