Sunday, 8 November 2020

Set the automatic TRIM job to daily

 

Set the automatic TRIM job to daily

6. The cleaning action TRIM is recommended for the good performance of your SSD in the long run. Otherwise it might become slow after some time.

That's even true for new SSD's: although new SSD's nowadays usually have some form of garbage collection integrated into their firmware, it's always better to execute a regular TRIM as well.

Note: very old SSD's from before 2010 usually don't support TRIM.

In Linux Mint and Ubuntu automatic TRIM is enabled by default, when you install them on an SSD. Namely by a weekly "job". But in many (most?) cases, once a week isn't frequent enough: waiting an entire week before recoverable disk space becomes usable again, is simply too long.

You can switch your system to automatic daily trimming as follows:

a. Copy/paste the following command line into the terminal, in order to create a new folder:

sudo mkdir -v /etc/systemd/system/fstrim.timer.d

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.

b. Copy/paste the following command line into the terminal, in order to create a new file in that new folder:

sudo touch /etc/systemd/system/fstrim.timer.d/override.conf

Press Enter.

c. Copy/paste the following command line into the terminal, in order to edit the new file:

xed admin:///etc/systemd/system/fstrim.timer.d/override.conf

(Note: the three consecutive dashes aren't a typo, but intentional! For Ubuntu: type gedit instead of xed.)

Press Enter.

d. Now copy/paste this blue text into that empty text document:

[Timer]
OnCalendar=
OnCalendar=daily


Note: the double entry for OnCalendar is no mistake but intentional!

Save the modified file and close it.

e. Reboot your computer.

f. Confirm that you've successfully edited trim's configuration by executing this terminal command:

systemctl cat fstrim.timer

Your output should look approximately like this:

# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
ConditionVirtualization=!container

[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/fstrim.timer.d/override.conf
[Timer]
OnCalendar=
OnCalendar=daily


Let's take a look at this output. The first part shows the default setting (weekly), the second part shows the overriding setting that you've applied. That overriding setting contains two elements: first the existing OnCalendar setting (weekly) is being deleted, and then a new OnCalendar setting is being applied (daily).

 

If you ever want to check whether fstrim has actually happened, and when it happened, you can use this terminal command:

journalctl | grep fstrim.service

If you're done with this step, you can continue with item 8.

 

How to undo (back to a weekly job)

6.1. Want to undo? It's easy to change the daily job back to a weekly job, namely as follows:

a. Copy/paste the following command line into the terminal, in order to remove the overriding settings:

sudo rm -v /etc/systemd/system/fstrim.timer.d/override.conf

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.

b. Reboot your computer.

 

Share:

0 comments:

Post a Comment