Linux: Using dd to erase a hard drive (using pv to view progress)

I occasionally need to wipe a hard drive and give it to someone else.  When I do, I’m always careful to make sure that I have wiped it clean.  Of course, wiping a hard drive clean is a bit more complicated than just deleting everything or even reformatting it. If you really want to make sure your hard drive is wiped clean, you need to over write it with random data, multiple times.

On Linux, there is a built in program that provides this service – dd.  It’s done from the command line, so it requires using a terminal.  But it’s a fast, effective, useful utility.

First step, make sure you have two additional pieces of software installed (in addition to dd that is): pv and dialog. So, from the terminal (I’m using Kubuntu; adjust accordingly), type:

sudo apt-get install pv dialog

Once those two pieces of software are installed, make sure you have your drive connected to your computer.  You’ll then need to find out what designator your system has assigned to your hard drive.  This can also be done quickly from the command line.  Simply type:

fdisk -l

This will tell you what disks are connected to your computer and provide a bunch of information about those disks.  Based on that information, you should be able to determine what designator your target hard drive is (e.g., dev/sda, dev/sdb, dev/sdc, etc.).  Once you figure it out, you’re now ready to run dd on it.  But make sure you know precisely which drive it is as you really don’t want to wipe a drive unless it’s the correct one.

In order to wipe the drive by overwriting random data, you would type the following at the terminal:

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

where X is the letter of the target drive.  This is the basic dd command.  But to speed things along, you’ll want to add bs=1M at the end, as this will write in larger sectors.  And if you want to see the progress of the write, you need to add “| pv |” in between the input and output operations.  So, the faster command with a completion bar would be:

sudo dd if=/dev/urandom | pv | sudo of=/dev/sdX bs=1M

Again, where X is the letter of the target drive.  The inclusion of “pv” is basically like a “verbose” command, allowing you to see the progress of dd as it writes random data over your drive.

I used information from these sources for this post:

source 1

source 2

An alternative program you can use is “scrub.” Install it with:

sudo apt-get install scrub

To run it is even easier than dd. Once you know your drive’s identifier, it’s just the command followed by the drive:

sudo scrub /dev/sdX

You can learn about additional options here.

Loading


Posted

in

by

Comments

One response to “Linux: Using dd to erase a hard drive (using pv to view progress)”

  1. BReda Avatar
    BReda

    This post is old, but came across it and noticed this error in the last command, the command should be:

    `sudo dd if=/dev/urandom | pv | sudo dd of=/dev/sdX bs=1M`

Leave a Reply

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