Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, say you've completed a full pass of:

dd if=/dev/zero of=/dev/sdX bs=1M

Then, you'd like to make sure the destination has been really zeroed out (ignoring the confirmation messages from dd and not just polling the start or the end of the device). Assuming, that you'd have to read through the whole disk - I'd use this:

dd if=/dev/sdX bs=1M | grep -P '[^\x00]'

However, as this works with piping the stdout eventually this falls out with an error saying that the operation ran out of memory. So, it's of no use.

Of course, creating a whole image of the entire disk and saving it - is not an option. But, perhaps, doing that while somehow being able to skip 0x00 on the fly - that'd be one of the solutions..


share|improve this question
up vote 6 down vote accepted

There is a device, /dev/zero on a linux system that always gives zero when read.

So, how about comparing your hard drive with this device:

cmp /dev/sdX /dev/zero

If all is well with zero-ing out your hard drive it will terminate with:

cmp: EOF on /dev/sdb

telling you that the two files are the same until it got to the end of the hard drive. If there is a non zero bit on the hard drive cmp will tell you where it is in the file.

If you hav the pv package installed then

pv /dev/sdX | cmp /dev/zero

will do the same thing with a progress bar to keep you amused while it ckecks your drive (the EOF will now be on - rather than sdX though).

share|improve this answer
Great suggestion, I will try that out (hopefully without out of memory errors as of this time), thank you! – XXL Jan 7 '12 at 18:23


od will replace runs of the same thing with *, so you can easily use it to scan for nonzero bytes:

$ sudo od /dev/disk2 | head
0000000    000000  000000  000000  000000  000000  000000  000000  000000
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .