Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've just received my new SSD since the old one died. This Intel 320 SSD supports TRIM. For testing purposes, my dealer put malware, err, Windows on it. I want to get rid of it and install Kubuntu on it.

It does not have to be a "secure wipe", I just need the empty the disk in the mosy healthy way. I believe that dd if=/dev/zero of=/dev/sda just fills the blocks with zeroes and thereby taking another write (correct me if I'm wrong).

I've seen the answer How to enable TRIM, but it looks like it's suited for clearing empty blocks, not wiping the disk.

hdparm seems to be the program to do it, but I'm not sure if it clears the disk OR cleans empty blocks. From its manual page:

  --trim-sector-ranges
          For  Solid State Drives (SSDs).  EXCEPTIONALLY DANGEROUS. DO NOT
          USE THIS OPTION!!  Tells the drive firmware to discard  unneeded
          data  sectors,  destroying  any  data that may have been present
          within them.  This makes those sectors available  for  immediate
          use  by  the firmware's garbage collection mechanism, to improve
          scheduling for wear-leveling of the flash  media.   This  option
          expects  one  or  more  sector range pairs immediately after the
          option: an LBA starting address, a colon, and  a  sector  count,
          with no intervening spaces.  EXCEPTIONALLY DANGEROUS. DO NOT USE
          THIS OPTION!!
          E.g.  hdparm --trim-sector-ranges 1000:4 7894:16 /dev/sdz

How can I make all blocks appear as empty using TRIM?

share|improve this question
    
Good question, maybe it's enough to just delete the NTFS filesystem? –  htorque May 12 '11 at 14:11
    
@htorque: "maybe" is still not confirming, any useful sources would be welcome. –  Lekensteyn May 12 '11 at 14:19
1  
Hence it's just a comment. ;) However, you could first check some sectors on that partition sudo dd if=/dev/sda iflag=direct bs=512 skip=<some_sectors> count=32 | hexdump -C, then delete the NTFS partition using a recent Gparted version and re-check with the same command - if the data got wiped, you'd just see zeroes. –  htorque May 12 '11 at 14:38
1  
@htorque: I've just tested it but it's not working, I've used hexdump -C /sda1 and hexdump -C /sda1 to determine the starting block. Nice idea though. –  Lekensteyn May 12 '11 at 15:04
    
Would have been too easy, wouldn't it? :) Anyways, thanks for trying! –  htorque May 12 '11 at 15:06
show 5 more comments

4 Answers 4

up vote 18 down vote accepted

ATA Secure Erase

You should use the drive's security erase feature.

  1. Make sure the drive Security is not frozen. If it is, it may help to suspend and resume the computer.

    # hdparm -I /dev/sdaX
    
    [...]
    
    Security: 
           Master password revision code = 65534
                   supported
           not     enabled
           not     locked
           not     frozen <-------------------- This drive is not frozen, continue.
           not     expired: security count
                   supported: enhanced erase
           2min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.
    
  2. Set a User Password (this password is cleared too, the exact choice does not matter).

    hdparm --user-master u --security-set-pass Eins /dev/sdX
    
  3. Issue the ATA Secure Erase command

    hdparm --user-master u --security-erase Eins /dev/sdX
    

Note:

  • /dev/sdX is the SSD as a block device that you want to erase.
  • Eins is the password chosen in this example.

See the link above for complete instructions including troubleshooting.

share|improve this answer
    
Thanks for the link, it looks good for those who have a BIOS that supports it, but mine does not appear to support it. (frozen) –  Lekensteyn May 12 '11 at 15:42
    
Hurrah! After reading the article again, I read "Placing my system into "sleep" (Clevo M865TU notebook) worked too---and this may reset other drives to "not frozen" as well." and tried it since mine is originally from Clevo as well (but BTO build it). It works, I see "not frozen" now. ... but step 3 failed with "ERASE_PREPARE: Bad address" because I replaced sudo by time instead of prepending to the command! –  Lekensteyn May 12 '11 at 15:58
1  
OMG it worked and only took 19 seconds! Thanks a bunch! I wish I could upvote you ten times :D –  Lekensteyn May 12 '11 at 15:59
    
I just wanted to report that the accepted answer above has a broken link. It's pretty useless without said link, anyone care to post a summary of what that link said? –  Ashimema Sep 25 '11 at 10:21
    
@Ashimema: The link is currently broken because kernel.org had been hacked and therefore down for maintenance. Google Cache is empty, but this blog copied it: peter.membrey.hk/2011/09/11/… –  Lekensteyn Sep 25 '11 at 10:27
show 1 more comment

If you don't need a secure wipe, why don't you just install kubuntu using the options to 'use entire disk' and the equivalent of 'quick format' (can't remember the exact terminology right now)

That way you ditch the file allocation table and the drive is effectively emptied for overwriting. You don't actually need to empty it.

share|improve this answer
1  
See anandtech.com/show/2865/2. Deleting the block is not the same as erasing it and marking it as empty. –  Lekensteyn May 12 '11 at 15:48
    
@Lekensteyn Deleting doesn't mean anything for a block device. The installer will call mkfs.ext4 and discard the entire device; this is as secure as a "secure erase", in the sense that in both cases you are trusting the SSD firmware. –  Tobu Sep 30 '13 at 11:36
    
@Tobu Right, that has changed at some point. mkfs.ext4(8) says: discard - Attempt to discard blocks at mkfs time (discarding blocks initially is useful on solid state devices and sparse / thin-provisioned storage). When the device advertises that discard also zeroes data (any subsequent read after the discard and before write returns zero), then mark all not-yet-zeroed inode tables as zeroed. This significantly speeds up filesystem initialization. This is set as default. –  Lekensteyn Sep 30 '13 at 15:32
    
@Tobu For my use case, "Secure erase" did not have to really wipe the data from its flash chips, it should just ensure that there are no negative performance effects resulting from having some blocks in use. –  Lekensteyn Sep 30 '13 at 15:33
add comment

util-linux 2.23 offers blkdiscard which is exactly for this purpose. An excerpt from the manual page of blkdiscard(8):

NAME

blkdiscard - discard sectors on a device

SYNOPSIS

blkdiscard [-o offset] [-l length] [-s] [-v] device

DESCRIPTION

blkdiscard is used to discard device sectors. This is useful for solid-state drivers (SSDs) and thinly-provisioned storage. Unlike fstrim(8) this command is used directly on the block device.

By default, blkdiscard will discard all blocks on the device. Options may be used to modify this behavior based on range or size, as explained below.

The device argument is the pathname of the block device.

WARNING: All data in the discarded region on the device will be lost!

You'll have to compile it from source, or wait till util-linux 2.23 goes into Ubuntu, which should be done in 2014 or 2015. OpenSUSE has it in 13.1, earlier than most other distributions.

share|improve this answer
    
thx for adding information to this outdated post and welcome to askubuntu. –  mondjunge Sep 30 '13 at 10:03
    
Arch Linux already has this package as util-linux 2.23 was released on 25 April 2013. –  Lekensteyn Sep 30 '13 at 15:26
1  
Thanks for the welcome. Outdated post? Old, but not outdated, as long as it pops up in 1st page of Google search result, there are always new guys looking for the same answer coming here. To me it is outdated only when better pages push it out of 1st google result page. –  Zhang Weiwu Dec 19 '13 at 4:07
add comment

Just remove the partition, you do not have to clear the whole disk, old data will be overwritten when the storage is needed for something else.

To enable TRIM:

gksudo gedit /etc/fstab

Change "ext4 errors=remount-ro 0" into "ext4 discard,errors=remount-ro 0". (Add discard)

Save and reboot, TRIM should now be enabled.

Check if TRIM is enabled:

sudo -i
dd if=/dev/urandom of=tempfile count=100 bs=512k oflag=direct
hdparm --fibmap tempfile

Use the first begin_LBA address.

hdparm --read-sector [begin_LBA] /dev/sda

Now it should return numbers and characters. Remove the file and sync.

rm tempfile
sync

Now, run the following command again. If it returns zeros TRIM is enabled.

hdparm --read-sector [begin_LBA] /dev/sda
share|improve this answer
    
You do NOT want to fill an SSD with zeros as it will write to every erase block, causing more wear and tear, and leaving every erase block full. Also many drives do NOT immediately zero trimmed sectors. –  psusi May 12 '11 at 15:06
    
Sure, it requires many writes, but it does not damage the disk. I have used an Corsair F120 for 10-11 months now and have frequently filled it with zeros. (Doing it before every benchmark) So, after 30-35 times the performance is still the same.(~285MB read, 275MB/write) SMART says: The disk is healthy –  Alex May 12 '11 at 15:26
5  
Alex, every single write to an SSD damages it slightly. Writing to every single erase block causes them all to be marked in use, which will prevent the drive's GC from functioning properly and performance will suffer. You can think of it as a whole drive unTRIM. –  psusi May 12 '11 at 18:52
add comment

Your Answer

 
discard

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.