Wiping a hard drive

Aug 3, 2011·
Julio Batista Silva
Julio Batista Silva
· 3 min read
blog Hardware

I have just sold my oldest laptop on Mercado Livre (it is incredible how it lost value, from R$ 2700.00 to R$ 700.00 in only 3 years).

Something I consider important before selling a laptop is erasing every personal file, confidential file, saved password and any other information that could hurt you if it fell into the wrong hands. Formatting the disk would be a good solution, right? Wrong.

Unless the disk is encrypted, formatting is not enough. After an ordinary format, the blocks that held content are simply marked as available in the address table — which means the data stays on the disk and can be recovered with a specific tool, such as the extundelete I wrote about in another article.

The most effective way to wipe the disk completely and make the data unrecoverable without damaging the disk is the technique known as disk wiping, using disk scrubbing, which basically overwrites the whole disk with zeros and/or ones.

The most traditional and simplest way to do disk scrubbing on Unix systems is to use dd or cat.

  1. Boot from a live disk

  2. Optionally delete every partition with gparted or fdisk

  3. Check for badblocks with badblocks or fsck:

    badblocks -wvs /dev/sda
    fsck -f /dev/sda
    

    I believe using -w with badblocks is already enough to prevent data recovery from the disk, since it writes several times to every block on the disk. To make the program repeat the check several times, use the -p option. The process takes a few hours; one way to speed it up is to raise the number of blocks tested at a time with the -c option.

  4. Use one of the following methods, repeating it as many times as you think necessary

    2 times should be enough, unless the disk is going to be analyzed by very determined specialists.

    • Method 1

      Write zeros across the whole disk: dd if=/dev/zero of=/dev/sda

    • Method 2

      Write zeros and ones at random (recommended): dd if=/dev/urandom of=/dev/sda

    • Method 3

      The same function as the previous commands, but using cat. It writes random bits twice and zeros on the third pass.

      cat /dev/urandom > /dev/sda;
      cat /dev/urandom > /dev/sda;
      cat /dev/zero > /dev/sda
      

      On a 250GB drive I ran it with a few messages to get a sense of the timing, but even after 10h the first pass had not finished:

      echo "Started at `date`";
      
      cat /dev/urandom > /dev/sda;
      echo "Write #1 finished at `date`";
      
      cat /dev/urandom > /dev/sda;
      echo "Write #2 finished at `date`";
      
      cat /dev/zero > /dev/sda;
      echo "Write #3 finished at `date`"
      

      So I think it is better to use a program that shows the progress

    • Method 4

      Shred: Already installed on several distributions. Example usage: shred -n 3 -z -v /dev/sda.

    • Method 5

      Download some other program. There are several free programs made specifically for this purpose that write zeros and ones across the whole disk and automatically repeat the process several times.

      In a quick search I found the following programs: Dban, Autoclave, Wipe, KillDisk.

      Apparently the most widely used for this is DBAN, an 11MB boot disk that can be downloaded at http://www.dban.org/.

      The process takes a while and depends on the drive; on average it should take around 2 minutes per GB.


Julio Batista Silva
Authors
Senior Cloud Developer

I’m a Brazilian computer engineer based in Germany, passionate about tech, science, photography, and languages.

I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.

I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, mentoring, and contributing with code and translations.

On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.

Browse my gallery for some of my photography.

Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.

Always happy to connect! 🙂

comments powered by Disqus