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?
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 asfstrim
.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 withhdparm
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!)