3

I have an SSD that I want to TRIM before installing Ubuntu on it. It has been suggested to me, that I leave some unpartitioned space, such that the wear leveling will have free blocks to work with. However I understand that because the drive has previously had some software installed, just repartitioning it with some space left unpartitioned is insufficient. And mkfs won't TRIM the unpartitioned area.

In reading the hdparm man page, I came across --trim-sector-ranges, which sounds exactly what I need to use. It also has a warning which says: EXCEPTIONALLY DANGEROUS. DO NOT USE THIS OPTION!! twice.

I have seen a recomendation suggesting to use the ATA secure erase command instead. But I also read that secure erase has the risk of bricking the device.

What is it that --trim-sector-ranges does that makes it so dangerous that it is better to run the risk of bricking the device?

  • @mchid I suppose there is a reason for hdparm having features that are only for use with SSD. – kasperd Oct 12 '15 at 10:06
  • @mchid There is no sdparm command in the Ubuntu 14.04.3 install image. And according to your link it doesn't support the necessary commands anyway. Finally, it wouldn't even explain the reason for the warnings, when the recommended alternative is to invoke hdparm with different arguments. Moreover at least one of the recommended alternatives is a script which allegedly uses --trim-sector-ranges internally. – kasperd Oct 12 '15 at 10:35
  • @mchid How would installing a program without support for issuing a TRIM command explain what is dangerous about using an already installed program for doing the same? – kasperd Oct 12 '15 at 10:47
3

Trimming sectors basically says to the SSD that the sectors do no longer contain useful data, and can be garbage collected (i.e. erased) so that they can be re-used for future write operations. This can improve write performance when the disk is getting full, since the firmware translation layer of the SSD controller has more "leeway" to play with physical blocks/pages.

In hdparm, sectors to be trimmed are provided as LBA (logical blocks). If your SSD has been formatted with a filesystem, trimming LBA will certainly corrupt the filesystem and make it unusable (since a user has no knowledge of the underlying filesystem-to-LBA mapping). For SSD formatted with a filesystem, trimming should be done at a higher level, with tools such as fstrim.

When supported, the "ATA secure erase" command should erase all the physical blocks of the SSD. It could be roughly equivalent to trimming all the sectors of the SSD, but probably in a more optimized and secure way.

The referenced link indicates that the "secure erase" command failed when used with an USB-to-SATA adapter. This could be due to a poor or buggy implementation of the USB-to-SATA controller, or an implementation which does not comply with recent SATA specifications.

To wipeout the contents of a SSD, the SATA secure erase command is the preferred way to go. The --trim-sector-ranges option of a hdparm is for experimental and benchmark purpose. Only for very specific applications (some database systems) that addresses SSD at the LBA level can trimming sectors with hdparm make sense.

To finish, the recommendation of leaving some unpartioned space (called over-provisioning) for wear-levelling is interesting, provided this space has been trimmed in some way before (an "ATA secure erase" will also do for this purpose). If it's not the case, and if previous data were to exist in the LBA range of the unpartioned space, the SSD controller will assume it is still valid data and strive to keep it "alive", by possibly moving the associated blocks and pages (thus increasing overall wear!)

| improve this answer | |
  • FWIW, not all disks support secure erase. – Smar Jun 18 '19 at 10:10

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.