How to Zero a Hard Drive in Linux Using Shred

At my company I needed to zero my hard drives at work. “Zeroing” a hard drive means writing physical zeros to the disk so no savvy computer user can recover your files.

Usually you zero a hard drive when you are throwing out a company PC.  I’m under the impression that you can pay a ton of money to buy a program that does this for you on Windows, but today I’ll be using shred on Ubuntu (but any Linux distribution can use shed).

All of the below steps use the command line, so if you have something against command line you can stop reading now.

The application we will be using is called shred.  Shred writes random bits to your hard drive before it writes a zero.  This makes it harder for even very expensive hardware probing to recover the data(basically no US government agency will be able to recover your data).

Step 1: Installing Shred

This is pretty easy with Ubuntu as it is already in the repositories:

sudo apt-get install shred

Also newer versions of Ubuntu come with shred pre-installed so you don’t have to do anything. 

man shred

will give you more detail

Step 2: Connect the Hard Drive you Want to Zero

df -h

will list all of your connected devices find the device you want to zero and remember the path. In this example I’ll be using /dev/sdb as my example. (make sure you choose the device sdb not the partition sdb1)

Step 3: Run Shred

sudo shred -n1 -z -v /dev/sdb

-n is the number of iterations you want to write zeros to the hard drive.  My data is not very sensitve so I only do two passes.  The US military does seven.

-v means verbose, which is nice if your bored and want to see how far along the zero is.

-z actually writes a zero to hide the shreding.

Alternative method

Maybe you don’t have time to wait for the shred to write zeros to your hard drive, there is always the more fun option of melting your hard drive by burning it in thermite.

2 Responses

Ed
09.02.22

What repositories do I need on tap to install shred? Apt-get can’t seem to find it. Please email myfastraxpc@gmail.com if you have a suggestion.

CraZy675
09.02.22

I’ve updated the article to reflect that Ubuntu now has shred installed by default.

An easy way to check is to type
man shred

lol

Leave Your Response