Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Debian and need a way to format the entire hdd in order to not leave any trace on it because I want to donate it to a friend. So what will be the best way in order to format it? If I reinstall the OS it will not fully format it. I'm looking for a way to completely format it and make it like when you buy it from the shop, completely new and never stored a thing before.

share|improve this question
I see a lot of answers/comments remarking on the need to overwrite with random data and/or overwrite a disk multiple times. According to the NIST google.com/… (pdf), any hard disk manufactured after 2001 need only be overwritten once with zeros to completely destroy the data such that not even a laboratory can recover it. – Puddingfox Apr 29 '11 at 18:43

Unless your "friend" is the NSA, tools that do lots of random or pattern overwriting (as DBAN which others are recommending does) are overkill - dd if=/dev/zero of=[your disk... make sure you get it right] bs=10M will erase it so that it can't be recovered without taking the disk apart and scanning the platters with special hardware.

If you use /dev/urandom instead as Gilles suggests, make sure to zero out the MBR afterward so that the partition table and boot code is clean to not confuse the BIOS or any partitioning tools: dd if=/dev/zero of=[disk] bs=512 count=1

share|improve this answer
dd if=/dev/urandom of=[your disk... make sure you get it right] bs=10M is not much slower and pretty much guarantees the data will be unreadable through published techniques even with an electronics lab. – Gilles Apr 29 '11 at 17:12
Read the great answer I received here about wiping, how often. – user unknown Apr 29 '11 at 21:58
/dev/zero is way faster on my computer.. – Brendan Long Apr 30 '11 at 1:00
Revisiting this, I think I've found the article I remembered, and I'd be content with overwriting with zeroes myself. See Why is writing zeros (or random data) over a hard drive multiple times better than just doing it once? – Gilles Jan 8 '12 at 16:04

The Electronic Frontier Foundation's Surveillance Self-Defense site recommends Darik's Boot and Nuke. It's a self-contained boot CD, so it works with any OS.

Beware that DBAN will erase every hard drive connected to the computer. If you have other hard drives that you plan to keep, make certain they're unplugged before booting DBAN.

share|improve this answer
Thanks. But it will only delete the files right not damage the disk, right? After using DBAN I will be able to use the HDD again right? – Lispninjutsu Apr 29 '11 at 15:23
@Lispninjutsu, yes, it only deletes the data; it doesn't damage the disk. But you'll need to format it again in order to use it, like you'd just bought it. – cjm Apr 29 '11 at 15:26
@cjm, Thank you very much! – Lispninjutsu Apr 29 '11 at 15:28
DBAN is effective but overkill. A simple overwrite with random data is effective with modern hard disks (I can't find the reference right now, but I remember reading a paper showing a best-case probability of recovery of <55% per bit (independent) with fairly heavy equipment, after a one-pass overwrite). – Gilles Apr 29 '11 at 17:17
@Gilles It doesn't even have to be random -- zero-out the drive is, for all practical purposes, just as effective. Nothing against DBAN (it certainly works) nor against random data (which also works), but it's a very common myth that overwritten data can still be recovered, when the truth is that no such thing has ever been accomplished (with any reasonable probability of success). – Kromey Apr 29 '11 at 18:06

Use shred:

shred -vfz /dev/X
share|improve this answer
Shred is the most promising solution [ answer ] for this Question. – SHW Apr 30 '11 at 10:02
shred comes from GNU coreutils, and the information in its manual is better. – ephemient Apr 8 '12 at 19:49

This really isn't a "Linux and Unix" answer, but I would use the ATA Secure Erase command if it is available for your hardware, which is likely is. You can read about ATA Secure Erase here: https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase.

The following summarizes how to use the command on any system with the hdparm utility (man page). The directions are from the article above. I am assuming the drive is at /dev/X. You want to do this from a Live CD of some sort such that you aren't actually running off the disk you are trying to erase.

  1. hdparm -I /dev/X
    Make sure the device is not frozen by looking for "not frozen" in the command output. If the device is frozen, it is likely you will need to look in your BIOS to see if you can change it.

  2. hdparm --user-master u --security-set-pass mypass /dev/X Set the drive password to "mypass" or something of your choosing. If you don't have a password set, the drive won't accept this command.

  3. hdparm --user-master u --security-erase mypass /dev/X Issue the command.

The directions on the website linked above also have commands to ensure each step worked as desired and some helpful troubleshooting. This method is highly secure and relatively fast.

share|improve this answer


It's super secure albeit slow. So be ready for that.

share|improve this answer

You can use the wipe command which can handle files, directories, partitions and complete hard disk drives. More information you will find in manpage man wipe and here http://linux.die.net/man/1/wipe:

wipe -i /dev/X
share|improve this answer

Run a destructive badblocks-w scan on the partition in question. This overwrites everything with various bit patterns several times.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.