1 February 2013

cleaning a hard-disk before selling or recycling it

I experienced some drama preparing two old laptops for recycling. If you just want to know my lessons learned about permanent data deletion, skip to the end.

My aim way to remove my data in a permanent way without destroying the value of the hard disks for re-use or re-cycling. Both laptops ran Ubuntu and by a friend I had heard of tools like "shred" and "wipe" which overwrite files before deleting them so that they can't be recovered. Both tools protect against the use of ordinary recovery software as well as advanced forensics. For the former, overwriting once with zeros or anything else is sufficient as anyone with basic knowledge about file-systems knows. For the latter, overwriting many times with zeros, ones, and random patters is considered sufficient according to what the tool makers say.
Since I wanted to delete all data, I started out running "wipe" on the block device (the entire partition underneath the file system) of one data partition of my first laptop. It ran longer than one night (during which I slept with ear plugs, because the old laptop's fan is so loud) and did barely finish the first pass of "wipe". Since I don't really need to protect my data against advanced forensics, I went looking for quicker ways to delete the data. Some sources say that "formatting the drive" is good enough for deleting data, but I personally don't believe so, especially if after formatting, the disk is left blank. (I put "formatting" in quotes because those sources don't distinguish between "formatting a partition" and "repartitioning the disk" which are quite different things to do.)
I don't know of any tool which  easily reverses formatting or repartitioning, but I know how easy it was to recover almost all my data from a broken disk which wouldn't boot the computer any more. Since repartitioning and formatting also usually only changes some sectors of the disk, but leaves most of the disk intact, it is quite similar to a partly broken disk. In practice, installing a fresh OS on the repartitioned disk could disable most of the easy recovery tools, but since I didn't plan on installing anything, I didn't think about how safe this road is.
Thus, I didn't deem it sufficient to just repartition the disk, googled again, and found that the age-old "dd" tool easily does the job. And it's included even in the smallest linux-live-distro. So here's what I did with the first laptop:

  1. Boot from external. Nowadays that's USB or even SD. I still had an old live-CD lying around which also did the job. (Won't be an option for my new computers, though, since neither of them has CD drive and I am going to throw away all my CDs when I next move house.)
  2. If your external drive is slow or the live-distro you're booting has trouble with drivers, don't even bother to boot into graphical mode. Instead find the option to boot into a terminal and use it.
  3. "swapoff -a" just in case your live-distro finds and uses the swap partition of the disk you're going to erase. (Actually happened to me. Could have been a bad surprise.)
  4. run "fdisk -l" to see all the disks. With my oldest laptop, there was only "hda". With the other, it was "sda". Also use "mount" to see which device is your external disk, so you don't erase that. ;-P
  5. (If you have more than one disk and don't want to erase them all, you might need to mount them to be sure which one is which.)
  6. run "dd if=/dev/zero of=/dev/hda conv=noerror" replacing "hda" with your actual device name. I added the "conv=noerror" to ignore write errors so that it continues overwriting everything that still works. It would be too bad if the process stopped because of one bad block in the middle and I had to redo it or --even worse-- wouldn't notice it at all!
  7. As usual in the Unix world, there's no fancy message telling you all's done and well. So you have to know yourself, that this is, in fact, the happy end.
My second laptop made much more trouble, since the live-distro I had would boot fine and then just not recognize the disk drive at all. Then I tried to boot from a USB stick which booted into its boot menu, but just after loading the kernel couldn't find the USB device to mount it, so I was left with a "kernel shell" which only supported lsmod, modprobe and the like, so I abandoned that, too. Finally I tried to boot from an SD card, but this wasn't even recognized by the BIOS. (On my newer laptops this works, though.)

So here's how to do it ff you can't boot from external (or don't want to spend the effort to make it work):
  1. Boot to a root prompt so that /home won't be needed. (On Ubuntu, I don't even know how to to that, so I took care to delete everything, but leave my empty home directory intact.)
  2. Remove all data partitions and the swap partition from /etc/fstab. Run "swapoff -a" and "umount /datapartitions".
  3. run dd as above for all the unmounted partitions
  4. if you still have data and temporary files on the remaining (OS) partition, delete it with "rm". that's the hardest part, because it requires deciding where there could be private data that has to be deleted and where's the OS files that are still required. 
  5. finally, do "dd if=/dev/zero of=/remaining_partition/bigbigfile" for each remaining partition.
  6. Again, no happy end message, but that's it.
I found that dd into a file is actually faster than dd into a partition (just my laptops, YMMV), but I find that overwriting the entire partition is safer, because the file-system-internal areas (directories, journals, whatever modern stuff) also contain some private data. That's why I usually take care to have separate data partitions. Also for backups and stuff.

Lesson learned: The "how to securely remove your data" articles on the internet sound so easy with steps one, two, three, yippie, but in practice things get considerably more complicated. And again, as so many times, I am using a lot of technical knowledge about unix just to accomplish simple things. This just indicates to me that technology still has a long way to go...

0 comments:

Post a Comment