Note: There are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See Wikipedia:TRIM#ATA for more information.

Periodic TRIM

The util-linux package provides fstrim.service and fstrim.timersystemd unit files. Enabling the timer will activate the service weekly. The service executes fstrim(8) on all mounted filesystems on devices that support the discard operation.

The timer relies on the timestamp of /var/lib/systemd/timers/stamp-fstrim.timer (which it will create upon first invocation) to know whether a week has elapsed since it last ran. Therefore there is no need to worry about too frequent invocations, in an anacron-like fashion.

To query the units activity and status, see journalctl. To change the periodicity of the timer or the command run, edit the provided unit files.

Continuous TRIM

Note: There is no need to enable continuous TRIM if you run fstrim periodically.

The main benefit of continuous TRIM is speed; an SSD can perform more efficient garbage collection. However, results vary and particularly earlier SSD generations may also show just the opposite effect. Also for this reason, some distributions decided against using it (e.g. Ubuntu [5][6]).

Using the discard option for a mount in /etc/fstab enables continuous TRIM in device operations:

/dev/sda1 / ext4 defaults,discard 0 1

Note: Specifying the discard mount option in /etc/fstab does not work on XFS on / because it gets remounted on boot. According to this thread it has to be set using the rootflags=discardkernel parameter.

Using the default mount options instead of an entry in /etc/fstab is useful for external drives, because such partition will be mounted with the default options also on other machines. There is no need to edit /etc/fstab on every machine.

Note: The default mount options are not listed in /proc/mounts.

Trim an entire device

If you want to trim your entire SSD at once, e.g. for a new install, or you want to sell your SSD, you can use the blkdiscard command, which will instantly discard all blocks on a device.

Warning: all data on the device will be lost!

# blkdiscard /dev/sdX

LVM

Change the value of issue_discards option from 0 to 1 in /etc/lvm/lvm.conf.

Note: Enabling this option will "issue discards to a logical volumes's underlying physical volume(s) when the logical volume is no longer using the physical volumes' space (e.g. lvremove, lvreduce, etc)" (see lvm.conf(5) and/or inline comments in /etc/lvm/lvm.conf). As such it does not seem to be required for "regular" TRIM requests (file deletions inside a filesystem) to be functional.

Maximizing performance

Security

Hdparm shows "frozen" state

Some motherboard BIOS' issue a "security freeze" command to attached storage devices on initialization. Likewise some SSD (and HDD) BIOS' are set to "security freeze" in the factory already. Both result in the device's password security settings to be set to frozen, as shown in below output:

Operations like formatting the device or installing operating systems are not affected by the "security freeze".

The above output shows the device is not locked by a HDD-password on boot and the frozen state safeguards the device against malwares which may try to lock it by setting a password to it at runtime.

If you intend to set a password to a "frozen" device yourself, a motherboard BIOS with support for it is required. A lot of notebooks have support, because it is required for hardware encryption, but support may not be trivial for a desktop/server board. For the Intel DH67CL/BL motherboard, for example, the motherboard has to be set to "maintenance mode" by a physical jumper to access the settings (see [7], [8]).

Warning: Do not try to change the above lock security settings with hdparm unless you know exactly what you are doing.

SSD memory cell clearing

On occasion, users may wish to completely reset an SSD's cells to the same virgin state they were at the time the device was installed thus restoring it to its factory default write performance. Write performance is known to degrade over time even on SSDs with native TRIM support. TRIM only safeguards against file deletes, not replacements such as an incremental save.

The reset is easily accomplished in a three step procedure denoted on the SSD memory cell clearing wiki article. If the reason for the reset is to wipe data, you may not want to rely on the SSD bios to perform it securely. See Securely wipe disk#Flash memory for further information and examples to perform a wipe.

Hardware encryption

As noted in #Hdparm shows "frozen" state setting a password for a storage device (SSD/HDD) in the BIOS may also initialize the hardware encryption of devices supporting it. If the device also conforms to the OPAL standard, this may also be achieved without a respective BIOS feature to set the passphrase, see Self-Encrypting Drives.

Troubleshooting

It is possible that the issue you are encountering is a firmware bug which is not Linux specific, so before trying to troubleshoot an issue affecting the SSD device, you should first check if updates are available for:

To disable NCQ on boot, add libata.force=noncq to the kernel command line in the bootloader configuration. To disable NCQ only for disk 0 on port 9 use: libata.force=9.00:noncq

Alternatively, you may disable NCQ for a specific drive without rebooting via sysfs:

# echo 1 > /sys/block/sdX/device/queue_depth

If this (and also updating the firmware) does not resolves the problem or cause other issues, then file a bug report.

Resolving SATA power management related errors

Some SSDs (e.g. Transcend MTS400) are failing when SATA Active Link Power Management, ALPM, is enabled.
ALPM is disabled by default and enabled by a power saving daemon (e.g. TLP, Laptop Mode Tools).

If you are starting to encounter SATA related errors when using such a daemon, you should try to disable ALPM by setting its state to max_performance for both battery and AC powered profiles.

Firmware

ADATA

ADATA has a utility available for Linux (i686) on their support page. The link to latest firmware will appear after selecting the model. The latest Linux update utility is packed with firmware and needs to be run as root. One may need to set correct permissions for binary file first.

Crucial

Crucial provides an option for updating the firmware with an ISO image. These images can be found after selecting the product on their SSD support page and downloading the "Manual Boot File."

Note: ISO images provided by Crucial does not seem to be hybrid. If you will use just the dd command to copy the image to some device, the MBR won't be present, making such device unbootable.

Owners of an M4 Crucial model, may check if a firmware upgrade is needed with smartctl.

OCZ

Samsung

Samsung notes that update methods other than using their Magician Software are "not supported," but it is possible. The Magician Software can be used to make a USB drive bootable with the firmware update. Samsung provides pre-made bootable ISO images that can be used to update the firmware. Another option is to use Samsung's samsung_magicianAUR[broken link: package not found], which is available in the AUR. Magician only supports Samsung-branded SSDs; those manufactured by Samsung for OEMs (e.g., Lenovo) are not supported.

Note: Samsung does not make it obvious at all that they actually provide these. They seem to have 4 different firmware update pages, and each references different ways of doing things.

Users preferring to run the firmware update from a live USB created under Linux (without using Samsung's "Magician" software under Microsoft Windows) can refer to this post for reference.

Native upgrade

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Alternatively, the firmware can be upgraded natively, without making a bootable USB stick, as shown below.

First visit the Samsung downloads page and download the latest firmware for Windows, which is available as a disk image. In the following, Samsung_SSD_840_EVO_EXT0DB6Q.iso is used as an example file name, adjust it accordingly.

Setup the disk image:

$ udisksctl loop-setup -r -f Samsung_SSD_840_EVO_EXT0DB6Q.iso

This will make the ISO available as a loop device, and display the device path. Assuming it was /dev/loop0:

SanDisk

SanDisk makes ISO firmware images to allow SSD firmware update on operating systems that are unsupported by their SanDisk SSD Toolkit. One must choose the firmware for the right SSD model, as well as for the capacity that it has (e.g. 60GB, or 256GB). After burning the adequate ISO firmware image, simply restart the PC to boot with the newly created CD/DVD boot disk (may work from a USB stick).

The iso images just contain a linux kernel and an initrd. Extract them to /boot partition and boot them with GRUB or Syslinux to update the firmware.