ssd-img

SSD TRIM in Linux Lite 3.x Series – The missing option

Linux Lite, a delightful, tasteful distro that makes Linux feel like a breath of fresh air, is a well suited Operating System for novices and most importantly, it is rock solid! The community maintains its comprehensive help manual to provide new users with a trouble-free transition [ howdy Windows users :) ] – but even then, at times it falls short when it comes to documentation for inexperienced users.

Let’s get right to the point… contributions are certainly appreciated and always welcome but the K.I.S.S philosophy of Linux Lite must be kept across the entire manual… and it needs maintainers. I was going over the documentation last night to see what’s there related to SSDs and TRIM and what I found isn’t exactly what I would recommend new users to do nor they may feel comfortable doing it:

CAUTION: You MUST edit the following file with great care, a misplaced comma, a gap that shouldn’t be there or a missing line will cause you computer to not boot.

I don’t exactly know how others may feel about the previous quote but for me it is a red flag when a misplaced comma (,) can render a machine unbootable and asking new users to edit /etc/fstab is not something that should be recommended in a manual that is mostly oriented towards new users. It isn’t even questionable whether mounting options with noatime is a necessity for TRIM because it isn’t.

  • Linux Lite 3.x is based on Ubuntu 16.04. SSD TRIM is already enabled by default in Ubuntu 16.04 on a weekly schedule. Unfortunately it doesn’t fit everyone’s needs and in some cases it never runs because it is scheduled to run at 6:47 am. Hence, making changes to the defaults makes sense after all.
  • noatime is not a TRIM necessity so why add it in such section anyways? Besides, Linux kernel 2.6.30 and newer mount all filesystems with relatime by default, so again, why bother? Some applications and backup programs even care about atime, in which cases nodiratime is preferred over noatime. These technicalities should be left alone and not be included in a manual that targets new users. Enough they have having to care about TRIM in their Linux installations – something that is taken care by default in Windows.
  • The /etc/rc.local solution: Before Ubuntu 16.04, this was a fair approach that hardly slowed things down during boot ups, however for systemd (Ubuntu 16.04 onwards) it causes a significant boot delay (minutes at times) when the fstrim command is added to /etc/rc.local. So, I don’t think rc.local is the right way to go in Linux Lite 3.x.
  • Why not document a completely different scenario instead? For example, users who do not reboot the computer often will not get their SSDs trimmed by following the information currently provided in the manual, which hints users into editing /etc/rc.local so that TRIM is executed on each boot.

linux-lite-uptime-desktop

Just in case you ask what are the chances this would be a scenario worth documenting – no, you don’t need to be a geek – anyone who uses Linux Lite to host shares on the network via Samba, for example… or a user who simply wants to sit in front of the computer and get things done without waiting for it to boot each day ( aka my own father ).

Enable Daily SSD TRIM in Linux Lite 3.x – Boot independent

If you want to do SSD trimming in Linux Lite without depending on boot ups, here is a different yet simple approach: (For GUI options, see Scheduled Tasks for Linux Lite 3.x)

1- We are going to create a daily cron job to schedule trimming under /etc/cron.daily/ and disable the default fstrim file under /etc/cron.weekly/:

In Terminal:

sudo touch /etc/cron.daily/fstrim
sudo chmod +x /etc/cron.daily/fstrim
sudo mv /etc/cron.weekly/fstrim /

2- Now let’s add the fstrim command to the file we just created for our boot, root and home mount points plus some logging. You’ll notice that I’m using ionice to make fstrim yield to IO operations from other programs – we don’t want fstrim execution to clog our SSD I/O operations at any time.

In Terminal:

gksu leafpad /etc/cron.daily/fstrim

Copy and save the text below into that file:

#!/bin/sh
# Daily Trim
# log file
_LOG_="/var/log/trim.log"
# add date to logs e.g.: *** Mon, 24 Apr 2017 15:18:17 -0400 ***
echo "*** $(date -R) ***" >> "$_LOG_"
# By default it is assumed only / is on an SSD.
# You can add more SSD mount points, separated by spaces.
# Make sure all mount points are mentioned within the quotes. For example:
# SSD_MOUNT_POINTS="/ /boot /home /media/my_other_ssd"
SSD_MOUNT_POINTS="/ /boot /home"
for mount_point in $SSD_MOUNT_POINTS
do
  ionice -c2 -n7 nice -n 19 fstrim -v "$mount_point" >> "$_LOG_"
done
# add an empty line as separator between logs
echo '\n' >> "$_LOG_"

Linux Lite will now trim your SSD /, /boot and /home mounts daily at 6:25 am, which is defined in /etc/crontab (system-wide crontab). If you wish to change the time (system-wide) for daily cron jobs execution, that’s the file you should look into in Linux Lite.

~$ cat /etc/crontab | grep 'daily'

grep-crontab1

Related Post

Yad 3.9.1-0 package in Linux Lite breaks few thing... If you have installed some of the extra apps I've made available for Linux Lite in my repo, you'll notice that after updating Linux Lite home-brew ver...
Dnsmasq for easy LAN DNS services Dnsmasq is a lightweight DNS, DNS caching, DHCP and TFTP server. It is intended to provide reliable services in small networks. Dnsmasq accepts DNS q...
DNS Security with dnscrypt-proxy for your home net... DNSCrypt to the rescue! DNS is one of the fundamental building blocks of the Internet. It’s used any time you visit a website, send an email, have an ...

Leave a Reply