Linux: check and enable SSD TRIM with fstrim
Commands to check TRIM support, run fstrim and enable fstrim.timer.
On an SSD under Linux, the TRIM command tells the drive which blocks are free so it can keep its performance. This memo gathers the commands to check TRIM support, run it manually and automate it.
# Check that the disk supports TRIM
hdparm -I /dev/sda | grep TRIM
lsblk -D
# Run a manual TRIM on the root filesystem (-v: print the amount trimmed)
sudo fstrim -v /
# Enable the automatic weekly TRIM
sudo systemctl enable fstrim.timer
# Review past runs
journalctl -u fstrim
Notes
lsblk -Dshows discard capabilities: non-zeroDISC-GRANandDISC-MAXvalues mean TRIM is supported.fstrim.timeris a systemd unit that periodically triggersfstrim.service. A custom timer unit goes in/etc/systemd/system/(for examplefoo.timer).