[svlug] Detecting 'virgin' disks ?

Rick Moen rick at linuxmafia.com
Tue Jul 26 16:39:35 PDT 2005

Quoting Steve (steve at itsage.com):

> Anyone know a 'safe' method for detecting 'virgin' disks (disks that 
> have never been formatted...)
> I'm doing an installer, which will have to run MBR on these disks in 
> addition to partitioning them.
> With a brand new disk, is the entire disk zeroed out ? (ie can I just dd 
> the MBR and compare it to all zero's or all ones ?

How difficult this problem is may depend on how literally you intend
that question.  For example, there's an option ("-V") you can feed to
/sbin/sfdisk to test whether the disk has a _valid_ (and
standard-format) partition table, and you could script for the return
value.  But that wouldn't, in itself, prevent your installer from
deciding to overwrite a disk with a messed-up partition table, or one
with a Sun or BSD disklabel.

If you more-literally want to test for a "brand new disk", then I
suspect you have a more-difficult problem, since it's doubtful that
manufacturers literally zero them.  More likely, they'll have close to
random magnetisation.

More information about the svlug mailing list