Aug 27 2008

How To: Erase A Linux Hard Drive

Last week I talked about repartitioning a linux hard drive.  That method was fine for repairing a damaged partition but did nothing to delete data that could possibly be recovered.  Although there may be no definitive way to delete data and prevent it from ever being recovered, there are definitely some ways to make it very hard.  In this article I’m going to be using some common linux tools, dd and shred, to overwrite data on an existing hard drive.  This method is great if you want to reformat a secondary hard drive or partition.  If you want to reformat you primary partition where your os is located you can use this method with the knoppix portable cd distribution.

In the last how to I discussed how to find the partition or drive that you want to reformat.  I’m going to use same drive I repartitioned last week.

To rewrite the drive with dd, enter the following command at the terminal prompt to fill the drive with random data:

sudo dd if=/dev/urandom of=/dev/sda

if is the input file option

the input file option is set to /dev/urandom which is random number generator implemented using secure hashes.

of is the output file option

the output file option is set the /dev/sda or whatever hard drive or hard drive partition that needs to be erased.

This is a slow process and can take hours depending on drive size and the terminal doesn’t display any information on the process until it is completed.  I left mine running overnight.

Once the process is complete, the terminal will give the following information confirming that the process is complete:

I only ran dd once because I wasn’t concerned about data left on the drive.  However you can run multiple passes of dd with different parameters.  Here are some additional options:

Rewrite the drive with ASCII null characters

sudo dd if=/dev/zero of=/dev/sda

You can use the yes command to repeatedly output a custom message and pipe the input to dd.  The following command rewrites the drive with the phrase “gone”.

sudo yes “gone” | dd of=/dev/sda

Using Shred

Finally you can use shred to make one last pass on the drive.  Shred is also a tool for destroying data on hard drives but it does not destroy data completely when used on a journalled filesystem such as ext3.  That is why I would use this tool after rewriting the drive with dd.  The dd command destroys the filesystem essentially.  But like anything else, there is always a chance of something being recovered although it is less likely if you use dd then shred.

You can use the following shred command which will rewrite the drive 25 times:

sudo shred /dev/sda

or

To alter the number of passes that shred makes to 10 or some other number:

sudo shred -n 10 /dev/sda

Mounting A Drive And Installing A Filesystem:

In ubuntu most drives are in the /media directory so that is were I am going to mount this one also.  I am going to mount mine with the name hivemind so the command looks like this:

sudo mount /dev/sda /media/hivemind

After all the data on the drive has been rewritten, the filesystem on the drive has essentially been destroyed.  So you need to create a filesystem on the drive so that it is usable again.

sudo mkfs.ext3 /dev/sda

After the drive is mounted and has a filesystem installed, you may still need to change the drive permissions so that you have permission to read and write files.

Now the drive should be ready to use.

KJ

Related Articles

Subscribe To HighTechSister.com

1 Comments on this post

Trackbacks

  1. How To: Partitioning A Linux Hard Drive | HighTechSister | High Tech Sister wrote:

    [...] (*Note this does not detail how to rewrite over a drive.  That requires tools such as dd and shred which will be the subject of another how to.) [...]

    August 27th, 2008 at 7:07 am

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog