Checking if any data exists on a presumably empty storage device

4

1

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

Ideas?

XXL

Posted 2012-01-07T16:09:39.953

Reputation: 1 359

Answers

9

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

Neal

Posted 2012-01-07T16:09:39.953

Reputation: 8 447

Great suggestion, I will try that out (hopefully without out of memory errors as of this time), thank you! – XXL – 2012-01-07T18:23:24.947

1

From https://superuser.com/a/559855/236344:

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
*
234250000

Skylar Ittner

Posted 2012-01-07T16:09:39.953

Reputation: 285