wipe_hard_drive.pl



NAME

wipe_hard_drive.pl <device>


DESCRIPTION

BEWARE : THIS SCRIPT WILL PERFORM A LOW LEVEL FORMAT ON <device>.

ALL DATA ON <device> WILL BE LOST, USE AT YOUR OWN RISK.

Note: you need to install 'dd' and 'blockdev' before using this script.


COPYRIGHT

Copyright 2000-2007 Etienne LEMEE <coding AT etilem DOT net>

This piece of code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


#!/usr/bin/perl -w

use strict;
use warnings;
$|=1;

@ARGV > 0 or die << "USAGE";

usage: $0 <device>
USAGE

my ($dev, $bdev, $dd, $zero, $size, $bsize);

$dev = shift;
die "Cannot write to $dev : $!" unless (-w $dev);

chomp($bdev = qx(which blockdev));
die "Cannot use blockdev : $!" unless(-x $bdev);

chomp($dd = qx(which dd));
die "Cannot use dd : $!" unless(-x $dd);

$zero = "/dev/zero";
die "Cannot read from $zero : $!" unless(-r $zero);

chomp($size = qx($bdev --getsize $dev));

chomp($bsize = qx($bdev --getss $dev));

while(!($size % 2)) {
    $size /= 2;
    $bsize *= 2;
}

my $cmd = "$dd if=$zero of=$dev bs=$bsize count=$size";

print "Wipping out $dev : $cmd : ";
if(system("$cmd 2>/dev/null")) {
    print "FAILED\n";
}
else {
    print "OK\n";
}