Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to zero-fill a block device: (3 Items)
   
How to zero-fill a block device  
How can I zero-fill a block device on QNX 4?

On some other Unix-like systems, I would probably do something like "dd if=/dev/zero of=/dev/hdX" but there's no such 
thing as "/dev/zero" on QNX 4.

I have a couple of ideas that are rather ugly. Does anyone know of a straightforward method?
Re: How to zero-fill a block device  
On Fri, Apr 15, 2011 at 03:02:46PM -0400, Graham Knap wrote:
> How can I zero-fill a block device on QNX 4?
> 
> On some other Unix-like systems, I would probably do something like "dd
> if=/dev/zero of=/dev/hdX" but there's no such thing as "/dev/zero" on
> QNX 4.
> 
> I have a couple of ideas that are rather ugly. Does anyone know of a
> straightforward method?
> 

I think this should work.

# echo -n '\00' > zero
# cat zero >> zero

-seanb
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.