How to Enable TRIM on SSD in Ubuntu Linux

Last updated: April 17, 2014

enable TRIM on SSD

Trim command (TRIM) helps keep your solid-state drive (SSD) at its full speed. If you find your SSD slowed down after a while of using, TRIM may help you make SSD always fast.

Because low-level operation of SSDs differs significantly from hard drives, the typical way in which operating systems handle operations like deletes and formats resulted in unanticipated progressive performance degradation of write operations on SSDs. Trimming enables the SSD to handle garbage collection overhead, which would otherwise significantly slow down future write operations to the involved blocks, in advance.

See more about TRIM on the Wiki page

UPDATE: Ubuntu 14.04 Trusty will have TRIM enabled by default.

To get started, press Ctrl+Alt+T on keyboard to open terminal. When it opens, follow steps below:

1. Check out if you have an SSD:

cat /sys/block/sda/queue/rotational

If you got 0 it’s a SSD. If the output was 1 it’s a HDD.

2. Even if you have an SSD not all of them support TRIM. To find out if yours does run:

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

If what you get back is this:

Data Set Management TRIM supported

Then you are all good to go. If there’s no output, your SSD doesn’t support TRIM.

3. Next run:

sudo fstrim -v /

You should see an output that looks something like this:

/: 87781376 bytes were trimmed

4. If everything went OK it’s time to make a CRON job so fstrim run’s once a day.

To do this run:

gksudo gedit /etc/cron.daily/trim

Copy and paste below lines and save it.

#!/bin/sh
LOG=/var/log/trim.log
echo “*** $(date -R) ***” >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG

Finally make it executable:

sudo chmod +x /etc/cron.daily/trim

That’s it. You now have TRIM enabled.

via: pinguyos forum

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

6 responses to How to Enable TRIM on SSD in Ubuntu Linux

  1. If I were you, I woudn’t do the trim command once a day because it spents write cycles unnecessarily. For a normal use, once a week is quite enough, because the SSD takes long time to decrease its performance because of the lack of memory pages.

    The other way is putting the argument “discard” in the SSD line at /etc/fstab and leave it to the SSD native controller.

  2. I wrote another cron job solution called SSDcronTRIM. My idea was to write a script which automatically recognized based on the used disk space, how often the disk has to be trimmed (monthly, weekly, daily, hourly). In my opinion this is the best balance between an “only trim when it is necessary” and an “fire and forget” solution like discard in fstab. You can find the script and instructions on github: http://chmatse.github.io/SSDcronTRIM/

  3. Whats the code to make it every 2, or 3 days instead of one?