How To: SSD + TRIM + Linux

jedi

*****This is a very dated post.  Most new (if not all)  SSD's come with all of this as a standard feature, or it is otherwise built into the Kernel now.*****

I have edited the posts where I advised using the "discard" option in your fstab to enable TRIM.

First, since 2011 or so, TRIM has been enabled by default in the Linux Kernel but not what you'd call optimally.  I don't know the why of that so don't ask!  I have learned over the last few weeks that enabling TRIM using the "discard" option in /etc/fstab will end up significantly slowing your drive down.  That option will make Linux use TRIM the same way Windows does.  (which can cause your drive to slow down)  TRIM tells the SSD drive to delete the information in the blocks and then write to them.  In reality, there is no need to do this every time you write to the disk in Linux.  (yes I know it is arguable, but this seems to be the consensus of the majority)

The smart thing to do is to create a 'cron' job to deal with TRIM, say, once a day, or once a week.  You can do this with the 'fstrim' command.  To see if your SSD drive even supports TRIM try the following in your terminal;

sudo fstrim -v /

If you see no error, and it tells you "/: 19 GiB (20374241280 bytes) trimmed" you'll know you have a TRIM capable drive!  (obviously your size will differ from mine probably).  The above command is a way for you to manually TRIM your SSD drive whenever you like.  The above command was to TRIM the '/' (or root) partition or your SSD.  Do the same thing for your '/home' partition if you create separate partitions on your SSD when you do an install.  So, for '/home';

sudo fstrim -v /home

The 'cron' job would look just a tiny bit different.  Your not going to use the -v option.  Here is a simple and effective way to create your own 'cron' job to TRIM your SSD drives;

sudo medit /etc/cron.daily/fstrim

and create a file with the following


#!/bin/sh
fstrim / && fstrim /home


That takes care of the '/' (or root) and '/home' partitions.

Do not forget to go into the properties of the files you just created and mark them as 'executable'.

You should now get consistent performance from your SSD, as well as quite possibly extending it's lifetime!
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

VastOne

Nicely done Jedi...

Have added the daily cron task and tested it all ... works as advertised

Thank you!
VSIDO      VSIDO Change Blog    

    I dev VSIDO