Enable TRIM for SSDs on Linux

Most Linux distributions do not enable TRIM by default for a variety of reasons. To get the best long-term performance from your SSDs you’ll want to enable it manually. The easiest way to do this is to enable systemd’s fstrim timer which will trim your SSDs weekly:

sudo systemctl enable fstrim.timer

Alternatively, you can setup a cronjob to occasionally run fstrim on your SSD’s mount points and log the results.

Create a cron script that will run once a week:

sudo touch /etc/cron.weekly/fstrim

Add the following to /etc/cron.weekly/fstrim. In this example I have two mount points that I want to TRIM on my SSD, / and /home:

echo [ $(date) ] $(/sbin/fstrim -v / 2>&1) >> $LOG
echo [ $(date) ] $(/sbin/fstrim -v /home 2>&1) >> $LOG

Save the file and then make it executable:

sudo chmod +x /etc/cron.weekly/fstrim

It will run once a week and log to /var/log/fstrim.log:

[ Sat Oct 18 08:42:50 MDT 2014 ] /: 42.7 GiB (45856079872 bytes) trimmed
[ Sat Oct 18 08:42:51 MDT 2014 ] /home: 101.5 GiB (108950966272 bytes) trimmed

If you’re using LVM or disk encryption the instructions will be different. In that case I recommend you read through the relevant sections in the Arch wiki page for solid state drives.

Leave a Reply

Your email address will not be published. Required fields are marked *