Tell me more ×
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

3 Answers

up vote 14 down vote accepted

Use the drive's security erase feature: https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase

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

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

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

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.