52

I am planning on selling my laptop. So I formatted my disk using the Disk Utility and chose to overwrite the disk with zeroes.

Two questions:

Is this the same as overwriting the disk using dd?

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

And is this method secure enough so that buyers can't easily recover the previous data? Or should I take additional measures (like encrypting the disk, destroying the headers, etc.)?

David Foerster
  • 36,264
  • 56
  • 94
  • 147

4 Answers4

45

Yes, the disk utility uses a method similar to the one with dd you describe, or a faster and more secure one more like:

dd if=/dev/urandom of=/dev/sda bs=1M

This introduces a lot more fuzz to the overwriting pattern than zeros only, which should be more difficult to restore but not noticeably slower to perform.

Some people claim, this is not enough and one should overwrite hard disks multiple times and with more elaborate patterns (scrub(1) can do both of that as per the other answer), but most will say once is enough, if an attacker wants to restore more than a few bits with a significant chance.

Edit: Apparently /dev/urandom peaks at ~13 MiB/s on at least two systems including mine. Therefore simonp suggested a different approach using openssl(1):

head -c 32 /dev/urandom | sudo openssl enc -rc4 -nosalt -pass stdin -in /dev/zero -out /dev/sda
David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • 2
    There are so many methods, I was just wondering if the Disk Utility is safe enough. I don't want to drag this thing out, just want to make it clean enough for a sale, and make sure no-one can easily to my data. Thanks for answering. – Stefan van den Akker Oct 15 '13 at 20:15
  • If you want to be sure, you need to either read the documentation or even the code of the disk utility (though I don't know why they would do something stupid over something so trivial), or do it yourself with dd or scrub. – David Foerster Oct 15 '13 at 20:20
  • Yeah, or check if you can recover something yourself after the wipe is done. I think I'm going to trust the program. – Stefan van den Akker Oct 15 '13 at 20:24
  • 1
    Even if you simply overwrite the drive with zeros once, you wouldn't be able to recover any data with software or home tools alone. – David Foerster Oct 15 '13 at 20:25
  • 2
    Using /dev/urandom is much slower than /dev/zero (reaches a peak of 13MB/s vs ~0.5GB/s on my laptop). For a faster way of generating random numbers in Linux, see http://serverfault.com/a/415962. E.g. openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero | pv -pterb -s $(sudo blockdev --getsize64 /dev/sdb) | sudo dd of=/dev/sdb bs=1M – simonp Dec 21 '14 at 07:50
  • @simonp: Same for me. Strange… I could swear this was different 2 years ago. Maybe something changed in the kernel. urandom isn't supposed to block, yet the bottle neck seems to be the reading process maxing out the core it's running on. – David Foerster Dec 21 '14 at 09:34
  • The problem with using these commands is that it will only erase blocks seen by the OS. Any spare blocks (especially reserved cells on SSDs) will not be erased. – NGRhodes Mar 28 '16 at 09:09
  • @NGRhodes: AFAIK you cannot access spare blocks directly in any fashion unless you rewrite the drive firmware. – David Foerster Mar 28 '16 at 12:26
  • some of the discussion here seems to be missing the forest for the trees . . . i'm not an expert on any of this . . . is the TLDR that using the disk utility is OK? – abcd Aug 31 '17 at 19:11
  • @dbliss: Read the very first sentence of my answer post. It's a direct answer to the first question in the question post. The remainder of my answer addresses the other questions. – David Foerster Aug 31 '17 at 23:17
  • Current OUTput of the second (head -c ...) command: WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. – nyxee Apr 27 '20 at 03:02
  • @nyxee: I think we can ignore that since the key in question is a random byte sequence (from /dev/urandom). There’s no use in scrambling it with a key derivation function. – David Foerster Apr 27 '20 at 03:21
  • @simonp Is there any way to get progress on the openssl command? it would be nice to know if this is going to take 10min or 10 days to complete. – J'e Jan 23 '23 at 22:54
  • 1
    @J'e You can pipe the output through pv(1): head -c 32 < /dev/urandom | openssl enc -rc4 -nosalt -pass stdin -in /dev/zero | pv [options...] > /dev/sdX. The manual claims that pv will use the size of the output block device if the input has no size (like a pipe/FIFO) to calculate the relative progress. – David Foerster Jan 25 '23 at 00:32
18

The "bootom line" AFIK is that the data has to be over written or it can be retrieved. There are many tools / methods to do this.

The consensus is that you only have to make one pass, so additional passes take additional time and put excessive wear and tear on the hard drive.

While there are many solutions, I prefer scrub.

scrub /dev/sda

Or if you prefer

scrub -p dod /dev/sda

See also

Pablo Bianchi
  • 15,657
Panther
  • 102,067
  • 1
    Like I said in the comment on my question, I prefer using a GUI if there is one readily available, like in the Disk Utility. (I don't really like staring at my Terminal, wondering if it's doing something. I know there are ways to show progress with dd, but still.) Besides for me it's important that the process takes hours, not days, so overwriting everything with zeroes seems like my best bet? – Stefan van den Akker Oct 15 '13 at 20:22
  • 1
    Actually, one of the best ways to forever lose contents doesn't involve overwriting the data at all. Essentially, use "Full-Disk Encryption" from day 1, then when you want to wipe it, lose the original encryption key. Much faster than overwriting, AND it also makes unreachable copies of data (remapped sectors, etc) undecodable. – Ben Voigt Jan 22 '16 at 16:13
  • I'm not sure there are any complete wipes at all, given enough time and resource that is. I guess the take away here is, if the data is more valuable than the cost to recover it. If you believe that it is or may be, destroy the drive. why even take the risk. – CodingInTheUK Mar 22 '17 at 06:44
  • 1
    @Chris - http://www.nber.org/sys-admin/overwritten-data-gutmann.html The Gutmann theory has been debunked and a single pass of zeros is sufficient, let alone scrub. Please do not spread FUD or present clear data to support you FUD. – Panther Mar 23 '17 at 15:57
  • I wrestled with this. Drop Ubuntu live for this purpose. Get DBAN (http://dban.org), a linux bootable that has single purpose program--to erase hard disks. Has choice of 5 algorithms. I tried many of the tools in Ubuntu live this weekend and on Dell workstations that were 3 years old, the drives would not allow hdparm to do the work. The drives were reported as "frozen" and none of the many cures worked. OTOH, DBAN success first time. – pauljohn32 Mar 04 '18 at 20:24
17

Another option for reference is to use the ATA Secure Erase method using hdparm.

The problem with using OS level commands such sa DD is that they will only erase blocks seen by the OS. Any spare blocks (especially reserved cells on SSDs) will not be erased.

https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase


To reiterate: (2017-Jul)

The ONLY plausible method (for HDD, SSHD and SSD) is to use the ATA 'Enhanced Secure Erase' (ESE) command to 'remove' all stored and residual data.

If this command can NOT be used, the media needs to be 'destructed' (converted to <2mm size fragments, or melted in a furnace).

Notes:

  • This advice ignores older magnetic-media (from pre-2001 and/or less then 15GB in capacity).
  • Some PC BIOS (or OS) block the ATA command(s) from being run, and some (much older) brand/models (of drive) are problematic, due to poor implementation of ESE.
  • The lesser ATA 'Secure Erase' command is faster but only overwrites with 'zeros', rather than a random pattern.
  • The only truly better method than using ESE is NOT having data on the drive in the first place. This can be achieved by using full-disk encryption (FDE) or self-encrypting drives (SED).
david6
  • 14,499
NGRhodes
  • 9,490
2

Nwipe, it's a fork of DBAN but unlike DBAN is actively in development. It can run as a command line tool or it's default mode is ncurses GUI. It's in the debian, ubuntu, Fedora repositories. Or if you want to run from a USB stick shredOS, which uses nwipe.

https://github.com/nadenislamarre/shredos/pull/2#event-2855392401

https://github.com/martijnvanbrummelen/nwipeenter image description here