Debian and ssd optimize (trim)

We will place “trim” scripts in four places:

/etc/rc.local = This will run at every boot  no matter what.
/etc/rc0.d/ = This will run at shutdown only.
/etc/rc6.d/ = This will run on restart only.
/etc/cron.hourly/ = This will run every hour the system is running.

rc.local
vim /etc/rc.local and add several lines before “exit 0”

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#Run "ssdstrim" at boot
LOG=/var/log/ssdtrim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >>$LOG 

exit 0

cron.houtly, rc0.d and rc6.d
Create a file named: “/etc/init.d/ssdtrim.sh” and add this:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          fstrim
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:      
# Short-Description: execute trim for ssd
# Description:
### END INIT INFO
#Run “fstrim” command
LOG=/var/log/ssdtrim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >>$LOG 

exit 0

Next, change the permissions on the file with the following command:

sudo chmod 755 /etc/init.d/ssdtrim.sh

Next, we make the three symbolic links and will be finished.

sudo ln -s /etc/init.d/ssdtrim.sh /etc/rc0.d/K30ssdtrim
sudo ln -s /etc/init.d/ssdtrim.sh /etc/rc6.d/K30ssdtrim
sudo ln -s /etc/init.d/ssdtrim.sh /etc/cron.hourly/ssdtrim

source: http://joao.machado-family.com/2014/04/01/linux-ssd-trim-setup/

Leave a Reply

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

*