Quick Disk Overwrite Script
by Rob
If you're anything like me, you have old hard disks lying around from old computers.
You don't want to throw them out - they work, so they can be used. Maybe you want to sell them or give them away. But what about your precious personal data on them?
You don't want a new user of the disk to get your data and use it in an identity theft scenario against you. The answer is, of course, to overwrite a disk with garbage that has no use to a would-be identity thief.
You can buy software that does that but, as a hacker, of course you want to do it yourself.
Here's what I've done - maybe it could help you too.
Step 1: Reformat the Disk
I reformat my old disks, setting up a full disk EXT4 partition. There are many ways to do this in Linux.
Reformatting a Windows NTFS/FAT disk to EXT4 loses the old partition table, making it hard to recover files, but probably not impossible.
Step 2: Write to the Disk Until It Is Full
Reformatting is good, but for further data security you need to overwrite the full disk.
I wrote the following simple Bash script to do it.
First, mount the newly formatted disk, e.g. to: /home/myuser/mount/disk
Then run this script:
#!/bin/bash # # use whatever meaningless text you like here: text="thequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydog" # try and write 10000 files, adjust this if required i=1 while [ $i -le 10000 ] do # generate a unique filename using the date command filename="file-`date +%s.%N`" # display progress echo "$i $filename" # write 1,000,000 lines to each file j=1 while [ $j -le 1000000 ] do #echo $text >> ~/mount/disk/$filename echo $text >> /tmp/fart ((j++)) done ((i++)) done exitDepending on the size of your disk, this script may not get to the maximum 10,000 files.
In my case, I was writing to a 40 gigabyte disk, and my text was 1440 characters long, and writing 30 files filled the disk.
After that, the attempt to write more results in the error message write error: No space left on device, so just Ctrl+C out of the script.
Step 3: Just Delete All Those Files, and Sell or Give the Disk to Someone Who Needs It
I hope this is useful.
I like this because it can extend the lifetime of old hardware with some sense of data security.
Code: overwrite.sh