Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active November 10, 2017 14:36
Show Gist options
  • Save magnetikonline/8190599 to your computer and use it in GitHub Desktop.
Save magnetikonline/8190599 to your computer and use it in GitHub Desktop.
Enable a daily SSD TRIM operation for Ubuntu 12.04+.

SSD TRIM support for Ubuntu 12.04+

Steps to add a daily SSD TRIM task to your Ubuntu system (tested with 12.04+) which will run via anacron with logging of the trim process to /var/log/fstrimall.log.

Note: if you have previously enabled TRIM support for your mounted drive(s) using the discard option within /etc/fstab you will want to remove this option and re-mount your drives first ($ mount -a).

  • Install scripts

    $ sudo wget \
    	https://gist.github.com/magnetikonline/8190599/raw/fstrimall.sh \
    	-O /etc/cron.daily/fstrimall
    $ sudo chmod a+x /etc/cron.daily/fstrimall
    $ sudo wget \
    	https://gist.github.com/magnetikonline/8190599/raw/fstrimall.logrotate \
    	-O /etc/logrotate.d/fstrimall
  • Optional: Edit SSD_MOUNT_POINTS section of /etc/cron.daily/fstrimall, adding additional mount points for each individual SSD drive space separated - for example:

    SSD_MOUNT_POINTS="/ /myseconddrive /mythirddrive"
  • All done! Shortly after system boot, anacron should fire off the /etc/cron.daily/fstrimall task and TRIM each mounted SSD drive defined in SSD_MOUNT_POINTS. Results will be logged to /var/log/fstrimall. This log will be rotated weekly via the /etc/logrotate.d/fstrimall logrotate task.

/var/log/fstrimall.log {
compress
delaycompress
missingok
notifempty
}
#!/bin/sh
SSD_MOUNT_POINTS="/"
LOG_FILE="/var/log/fstrimall.log"
echo "*** Start: $(date -R) ***" >> $LOG_FILE
for mountPoint in $SSD_MOUNT_POINTS
do
fstrim -v $mountPoint >> $LOG_FILE
done
echo "*** Finish: $(date -R) ***" >> $LOG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment