3 stacks of Hard drives waiting for destruction

Dangerous Dan, let’s destroy something!

Background

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.

Solutions

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:

  1. Find block devices
  2. Is it an SSD or HDD
    • SSDs are erased with blkdiscard
    • HDDs are erased with Shred
  3. Loopback and find more devices.

Be Safe

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[1])
      if BlkDev == False:
        x[2] = 0
      if BlkDev == True and x[2] == 0:
        x[2] = 1
        Spinner = subprocess.getoutput('cat /sys/block/sd'+x[0]+'/queue/rotational')
        x[3] = Spinner
        if Spinner == '0':
          print('Got SSD '+x[1]+", You have been granted summary distruction, thank you for your service.")
          subprocess.run(["umount", x[1]+'?*'])
          subprocess.Popen(['blkdiscard', '-z', '-f',  x[1]])
        else:
          print('Got Spinner '+x[1]+", You have been granted summary distruction, thank you for your service.")
          subprocess.run(["umount", x[1]+'?*'])
          subprocess.Popen(['shred', '-v', '-n7', '-z', x[1]])
      #print("Waiting for devices")
  time.sleep(1)

Leave a Reply

Your email address will not be published. Required fields are marked *