16

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.

  • 3
    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. – jamesbtate Apr 29 '11 at 18:43
  • If I reinstall the OS it will not fully format it. Fun fact: if, during the installation of Debian, you decide to partition with LVM + LUKS, your HDD will be formatted with randomized data. See debian.org/releases/stable/amd64/ch06s03.html.en#di-partition – espectalll Jun 14 '17 at 10:27
23

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

8

Use shred:

shred -vfz /dev/X
  • Shred is the most promising solution [ answer ] for this Question. – SHW Apr 30 '11 at 10:02
  • 1
    shred comes from GNU coreutils, and the information in its manual is better. – ephemient Apr 8 '12 at 19:49
  • As a side note, the -z parameter means that the device will be filled with zeros, which may not be found satisfactory. For a pseudorandom-based overwrite, just use no additional arguments, as it is the default. For a more randomized data origin, there's --random-source=/dev/urandom. And finally, by default 3 iterations are done, but you can set a custom number of times with -n/--iterations. – espectalll Jun 14 '17 at 10:20
7

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.

  • 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
  • 3
    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
  • @Kromey: The article I remember (but can't find now) mentioned a worrying-if-you're-paranoid recovery rate for a simple zeroing, if the attacker has expensive equipment. If you can find a reference, please share! – Gilles Apr 29 '11 at 18:16
7

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.

  • When the Power-Up in Standby (PUIS) feature is set, it is not enough to manually issue a drive start/spinup command (sg_sat_set_features —feature=7 /dev/X). Despite that the hdd drive state is now active/idle the "Security" section still lists the drive as "frozen" instead of "not frozen". Disable PUIS (hdparm -s0 /dev/X) then unplug and plug the drive made our SATA drive security change from "frozen" to "not frozen". This exception is not listed at ata.wiki.kernel.org. – Pro Backup Sep 6 '17 at 19:28
2

Use DBAN

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

0

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
0

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

0

Maybe you can install "disks" https://askubuntu.com/questions/249310/how-can-i-launch-disk-utility-after-installing-it , https://help.gnome.org/users/palimpsest/, it reads your partitions and you can use the gear to format completely if they are primary.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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