Last Updated: February 25, 2016
· deiu

Improve SSD performance with fstrim under Linux

Before proceeding further, you should check that your system supports TRIM by running this command (replace /dev/sda with your SSD):

:~$ sudo hdparm -I /dev/sda | grep "TRIM supported"

If everything is ok, you should receive the following response:

* Data Set Management TRIM supported (limit 8 blocks)

Next, create a new file that will hold the script for the cron job:

:~$ gksu gedit /etc/cron.daily/trim

And then paste the following lines:

echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG

Finally, you can now make the script executable by running this command:

:~$ sudo chmod +x /etc/cron.daily/trim

To test that it is running, you can use this command:

:~$ sudo /etc/cron.daily/trim && cat /var/log/trim.log

*** Thu, 12 Sep 2013 16:42:39 +0200 ***
/: 814514176 bytes were trimmed