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 2010 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;
$|=1;

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

usage: $0 <device>
USAGE

my ($dev, $bdev, $dd, $zero, $t_size, $b_size, $s_size);

$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($t_size = qx($bdev --getsize $dev));

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

chomp($b_size = qx($bdev --getbsz $dev));

$t_size /= ($b_size / $s_size);

my $cmd = "$dd if=$zero of=$dev bs=$b_size count=$t_size";

print "Wiping $dev out : $cmd : \n";

print "No error reported.\n" unless (system ($cmd));