10

I want to sell my old SSD on EBay. How do I prepare the hard drive to protect my personal data and get the hard drive in a good shape using an Ubuntu live cd?

Jackspace
  • 133

3 Answers3

12

The best way to wipe a SSD is to issue an ATA SECURE_ERASE command rather than using low-level utilities such as dd, because it's faster and more reliable, due to a number of reasons.

  1. Run lsblk and determine to which block device the drive is currently mapped (if you have only that drive attached it will likely be mapped to /dev/sda)
  2. Run sudo hdparm -I /dev/sda and determine whether the drive is currently frozen or not:

    Security: 
        Master password revision code = 65534
            supported
        not enabled
        not locked
            **frozen**
        not expired: security count
            supported: enhanced erase
        2min for SECURITY ERASE UNIT. 8min for ENHANCED SECURITY ERASE UNIT.
    

    If it is, suspend the system and resume:

    Security: 
        Master password revision code = 65534
            supported
        not enabled
        not locked
        not frozen
        not expired: security count
            supported: enhanced erase
        2min for SECURITY ERASE UNIT. 8min for ENHANCED SECURITY ERASE UNIT.
    
  3. Run sudo hdparm --user-master u --security-set-pass password /dev/sda to set a security password (this is mandatory in order to securely erase the drive)

  4. Run sudo hdparm --user-master u --security-erase password /dev/sda to securely erase the drive

As pointed out by Takkat, mind that this won't catch reallocated bad sectors.

To catch those as well, if you have any and if supported by the drive, you can issue an enhanced ATA SECURE_ERASE command, that writes manufacturer-predefined patterns multiple times and catches reallocated bad sectors as well:

  1. Run sudo hdparm --user-master u --security-erase-enhanced password /dev/sda to securely erase the drive
Pablo Bianchi
  • 15,657
kos
  • 35,891
  • 3
    This is the recommended way to wipe SSDs but we should point out that on some drives it still may leave recoverable data remnants (which would not be a big issue for the usual private data but it may be for highly sensitive data). – Takkat Jul 24 '15 at 08:35
  • @Takkat That's true, I've added a second method to take care of possible reallocated bad sectors and even of possible laboratory recovery attempts, now it should be fine. – kos Jul 24 '15 at 08:53
  • @Takkat - Is there any value in using security erase on non-SSD devices e.g. rotational disks. Please see my post at (https://security.stackexchange.com/questions/200332/should-a-secure-ata-erase-be-performed-on-a-non-ssd-drive) – Motivated Dec 25 '18 at 03:03
  • @Motivated you have quite a good answer there :) – Takkat Dec 25 '18 at 08:19
3

Use lsblk to list all the drives and find yours /dev/sdx.

Run the following:

# dd if=/dev/urandom of=/dev/sdx bs=8M && sync

Replace x with the drive you want to wipe. Run it multiple times if you're paranoid (eject and reinsert the drive each time to ensure that the data gets flushed).

This will erase everything, so be careful. I mean it. It's not possible to recover data by any means after this.

EDIT: based on further reading, it's quite likely that with the above method the drive will be securely erased, but some pieces may be recoverable (very little chance). With this warning in mind, I am not deleting this answer as this offers a very simple method to wipe data, and the recovery technique requires physically bypassing the ssd controller, which in most cases will damage the drive itself.

xyz
  • 1,786
  • 1
  • 12
  • 22
  • 1
  • Some claim to do that 2 times. - Might be prudent to make a backup of all personal data prior to doing this. Disaster is 1 digit away :D
  • – Rinzwind Jul 24 '15 at 08:21
  • Data could still be restored after the drive has been zero-ed – leorize Jul 24 '15 at 08:26
  • This method will not securely wipe data on a SSD - it should only be done on conventional hard drives. – Takkat Jul 24 '15 at 08:28
  • This doesn't erase data in a way that it can't be easily and fully recovered in a laboratory. The old patterns written to a magnetic disk are still visible several overwrites (the signal just gets a bit weaker every time). If you want data to be totally 100% unrecoverable you need to overwrite every part of the disk 20 times with well chosen patterns - overwriting it a single time with zeroes will stop nobody except a normal person who uses nothing but the harddisk itself to see what data is on it. – Carlo Wood May 04 '17 at 17:08
  • @CarloWood when you overwrite any disk multiple times (full capacity), it will wipe the old data. And this method writes random numbers, not zeros, increasing the chances of corruption of old data.

    For SSDs secure erase is a faster method, but doing this multiple times does the trick as well!

    – xyz May 05 '17 at 06:11