I work in a school district, and we recently removed most of our windows PC from the classroom in favor of Chromebooks for students. This was the overwhelming outcome of COVID for most school districts. This surplus of computers is destined for the recycling pile. However, They could contain precious user/student data and therefore need to be eradicated before we send it off to the recycler.
There are many solutions to this problem, many products, and much hardware. But I don’t have a budget for any of it. So let’s write a program. You can skip ahead and read through the code if you a fluent in python, though I’m not sure what I have done qualifies as python. It is also on my GitHub.
Don’t run this code anywhere near data you want to keep. It will erase it with DoD-level destruction, and I will not be responsible.
There isn’t a lot of logic here:
- Find block devices
- Is it an SSD or HDD
- SSDs are erased with blkdiscard
- HDDs are erased with Shred
- Loopback and find more devices.
The only “safety” I programmed in is that it won’t do anything to sda. You should be able to see the problem here. sda should be the boot drive, but it might not be. You could save time, run sudo rm -rf /, and inadvertently have the same result as formatting your main mount “/.” Look, it’s not a great solution. But, if you need to eradicate a couple of hundred HDDs and SSD in a short period, this will get the job done.
#!/bin/python3 python3 import os import stat import string import subprocess import time drives = ; letters = list(string.ascii_lowercase) letters.extend([i+b for i in letters for b in letters]) for letter in letters: if letter != 'a': drives.append([letter,"/dev/sd"+letter,0,1]) #print(drives) def isblockdevice(path): return os.path.exists(path) and stat.S_ISBLK(os.stat(path).st_mode) while True: for x in drives: BlkDev = isblockdevice(x) if BlkDev == False: x = 0 if BlkDev == True and x == 0: x = 1 Spinner = subprocess.getoutput('cat /sys/block/sd'+x+'/queue/rotational') x = Spinner if Spinner == '0': print('Got SSD '+x+", You have been granted summary distruction, thank you for your service.") subprocess.run(["umount", x+'?*']) subprocess.Popen(['blkdiscard', '-z', '-f', x]) else: print('Got Spinner '+x+", You have been granted summary distruction, thank you for your service.") subprocess.run(["umount", x+'?*']) subprocess.Popen(['shred', '-v', '-n7', '-z', x]) #print("Waiting for devices") time.sleep(1)