[SOLVED] TRIM and my SSD

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Klaas Vaak

[SOLVED] TRIM and my SSD

Post by Klaas Vaak »

I have the root partition and the EFI partition of LM 19.1 XFCE installed on an SSD, whereas my /home is installed on an HDD.
Root is designated as /dev/nvme0n1p1, EFI as /dev/nvme0n1p2. In the Easy Linux Tips Projects it says:
In Linux Mint 19.1 automatic TRIM is enabled by default, when you install Linux Mint 19.1 on an SSD. Namely by a weekly "job".
I assume that is the case, but is there way of checking the cron job is indeed set and runs 1x/week?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 4 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
deepakdeshp
Level 20
Level 20
Posts: 12334
Joined: Sun Aug 09, 2015 10:00 am

Re: TRIM and my SSD

Post by deepakdeshp »

You should be able to check cron log.
https://www.google.com/amp/s/linoxide.c ... buntu/amp/
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help.
Regards,
Deepak

Mint 21.1 Cinnamon 64 bit with AMD A6 / 8GB
Mint 21.1 Cinnamon AMD Ryzen3500U/8gb
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

deepakdeshp wrote: Wed May 08, 2019 12:22 pm You should be able to check cron log.
https://www.google.com/amp/s/linoxide.c ... buntu/amp/
Thank you for that. The output is not understandable for a newbie like me. Is there a way to get to some sort of more humanly intelligible output?
User avatar
Pjotr
Level 23
Level 23
Posts: 19886
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: TRIM and my SSD

Post by Pjotr »

Check the current setting with:

Code: Select all

systemctl cat fstrim.timer
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

Pjotr wrote: Wed May 08, 2019 12:47 pm Check the current setting with:

Code: Select all

systemctl cat fstrim.timer
Thanks Pjotr. Below is the output, which means it is not only set up, but it is running too, right?

Code: Select all

$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim

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

[Install]
WantedBy=timers.target
User avatar
Pjotr
Level 23
Level 23
Posts: 19886
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: TRIM and my SSD

Post by Pjotr »

Klaas Vaak wrote: Wed May 08, 2019 1:28 pm
Pjotr wrote: Wed May 08, 2019 12:47 pm Check the current setting with:

Code: Select all

systemctl cat fstrim.timer
Thanks Pjotr. Below is the output, which means it is not only set up, but it is running too, right?

Code: Select all

$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim

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

[Install]
WantedBy=timers.target
Yes. :)
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

Many thanks Pjotr, hartelijk dank :D
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: TRIM and my SSD

Post by smurphos »

journalctl | grep fstrim will show show you when the service has actually run...

Code: Select all

steve@steve-HP-Pavilion-g6-Notebook-PC:~$ journalctl | grep fstrim
Apr 15 04:31:59 steve-HP-Pavilion-g6-Notebook-PC fstrim[1193]: /home: 45.4 GiB (48688881664 bytes) trimmed
Apr 15 04:31:59 steve-HP-Pavilion-g6-Notebook-PC fstrim[1193]: /mnt/virtual_machines: 97.8 GiB (104946388992 bytes) trimmed
Apr 15 04:31:59 steve-HP-Pavilion-g6-Notebook-PC fstrim[1193]: /: 14.2 GiB (15232737280 bytes) trimmed
Apr 22 03:46:21 steve-HP-Pavilion-g6-Notebook-PC fstrim[1168]: /home: 45.6 GiB (48919089152 bytes) trimmed
Apr 22 03:46:21 steve-HP-Pavilion-g6-Notebook-PC fstrim[1168]: /mnt/virtual_machines: 17.7 GiB (19033665536 bytes) trimmed
Apr 22 03:46:21 steve-HP-Pavilion-g6-Notebook-PC fstrim[1168]: /: 15.9 GiB (17046007808 bytes) trimmed
Apr 30 05:16:58 steve-HP-Pavilion-g6-Notebook-PC fstrim[1169]: /home: 45.4 GiB (48728625152 bytes) trimmed
Apr 30 05:16:58 steve-HP-Pavilion-g6-Notebook-PC fstrim[1169]: /mnt/virtual_machines: 17.7 GiB (19033452544 bytes) trimmed
Apr 30 05:16:58 steve-HP-Pavilion-g6-Notebook-PC fstrim[1169]: /: 15.1 GiB (16261013504 bytes) trimmed
May 06 04:08:35 steve-HP-Pavilion-g6-Notebook-PC fstrim[1127]: /home: 45.3 GiB (48641093632 bytes) trimmed
May 06 04:08:35 steve-HP-Pavilion-g6-Notebook-PC fstrim[1127]: /mnt/virtual_machines: 17.7 GiB (19033460736 bytes) trimmed
May 06 04:08:35 steve-HP-Pavilion-g6-Notebook-PC fstrim[1127]: /: 15.6 GiB (16729300992 bytes) trimmed
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
HaveaMint
Level 6
Level 6
Posts: 1088
Joined: Fri Feb 02, 2018 9:56 pm

Re: TRIM and my SSD

Post by HaveaMint »

You can set fstrim to have a report on your desktop as such.

Code: Select all

#!/bin/sh
LOG=/home/mark/Desktop/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG
I have root and home on the ssd and Trimmed weekly. The output is like below.

Code: Select all

*** Thu, 09 May 2019 00:26:27 -0500 ***
/: 38.9 GiB (41766854656 bytes) trimmed
/home: 163.8 GiB (175808602112 bytes) trimmed
"Tune for maximum Smoke and then read the Instructions".
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

Thanks Steve, that's very useful.
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

HaveaMint wrote: Thu May 09, 2019 1:38 am You can set fstrim to have a report on your desktop as such.

Code: Select all

#!/bin/sh
LOG=/home/mark/Desktop/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG
I have root and home on the ssd and Trimmed weekly. The output is like below.

Code: Select all

*** Thu, 09 May 2019 00:26:27 -0500 ***
/: 38.9 GiB (41766854656 bytes) trimmed
/home: 163.8 GiB (175808602112 bytes) trimmed
HaveaMint, that's a nice one. Now, I want to ask you, and forgive 3 simple, basic questions from a newbie:
  • do you just add the code to an existing file, or do you create a new file (in xed I assume then)?
  • if it is the former, which file do you amend?
  • if it is the latter, where do you save it?
HaveaMint
Level 6
Level 6
Posts: 1088
Joined: Fri Feb 02, 2018 9:56 pm

Re: TRIM and my SSD

Post by HaveaMint »

That is the contents of fstrim located in /etc/cron.weekly/fstrim.
It is in cron.weekly because I want it to run weekly. If one wanted it to run daily, hourly or monthly then that file needs to be in the corresponding folder.
cron.png
"Tune for maximum Smoke and then read the Instructions".
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

Thanks HaveaMint.
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

HaveaMint wrote: Fri May 10, 2019 3:08 am That is the contents of fstrim located in /etc/cron.weekly/fstrim.
It is in cron.weekly because I want it to run weekly. If one wanted it to run daily, hourly or monthly then that file needs to be in the corresponding folder.

cron.png
I do have 1 other question:
as I understand it TRIM is enabled by default in Mint, and according to my output in a reply above that is indeed the case - weekly cron job - and I understand the fstrim file should have been created automatically. But when it came to adding your code for a desktop report, I found there was no fstrim file. I created it by copying your code to a text file and saving it as fstrim in /etc/cron.weekly. Isn't it strange the file wasn't there? I read somewhere:
If that file doesn’t exist on your system then you will need to create it with the following command:
sudo nano /etc/cron.weekly/fstrim

Then paste in the following code:
#!/bin/bash
/sbin/fstrim -a || true

Save and exit the file, then make it executable with the following command:
sudo chmod +x /etc/cron.weekly/fstrim
I did this check

Code: Select all

systemctl cat fstrim.timer
again and found the output is still the same as in an earlier reply above. What confuses me ( :? ) is the absence of fstrim containing

Code: Select all

#!/bin/bash
/sbin/fstrim -a || true
HaveaMint
Level 6
Level 6
Posts: 1088
Joined: Fri Feb 02, 2018 9:56 pm

Re: TRIM and my SSD

Post by HaveaMint »

I have been using this for a bit and I really don't remember the default location, hopefully someone will jump in and answer that for you. I changed it to the way I have it because it was easier for me to check up on it from time to time. Every so often I clean out older reports leaving the last one in the file on my desktop, not that the file is all that big by any means.
"Tune for maximum Smoke and then read the Instructions".
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

OK HaveaMint, if that works for you, it should work for me. And, like I said, even after saving "your" fstrim file there, my check showed that the TRIM operation is still enabled, so all should be well.
Perhaps the "enable" code as in my previous reply is not used anymore and TRIM is enabled in another way. Be that as it may, I'' run with this.
Thanks for your help.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: TRIM and my SSD

Post by smurphos »

Klaas Vaak wrote: Fri May 10, 2019 7:54 am Perhaps the "enable" code as in my previous reply is not used anymore and TRIM is enabled in another way. Be that as it may, I'' run with this.
Thanks for your help.
I think there may be some versioning related confusion going on in this thread....

Out of the box Mint 18.x use anacron via a script in /etc/cron.weekly/fstrim to manage it's automated weekly trim

Mint 19.x doesn't have this file and uses a systemd timed service instead.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Klaas Vaak

Re: TRIM and my SSD

Post by Klaas Vaak »

smurphos wrote: Sun May 19, 2019 2:26 am I think there may be some versioning related confusion going on in this thread....

Out of the box Mint 18.x use anacron via a script in /etc/cron.weekly/fstrim to manage it's automated weekly trim

Mint 19.x doesn't have this file and uses a systemd timed service instead.
Smurphos, many thanks for clearing that up !!! I must admit, I was a bit confused and concerned over the initial absence of the fstrim file.
Nevertheless, despite adding the fstrim file as per HaveaMint, the weekly report on my desktop did not appear on my desktop. I implemented HaveaMint's code in the fstrim file on 10th May, as I mentioned above, but did not receive the report as expected on 13th May, as shown in the code below. Any ideas?

Code: Select all

journalctl | grep fstrim
May 06 09:34:05 peter-Lenovo-ideapad-330-17ICH fstrim[1088]: /: 18,8 GiB (20199182336 bytes) trimmed
May 10 10:34:51 peter-Lenovo-ideapad-330-17ICH sudo[13913]:    peter : TTY=pts/0 ; PWD=/home/peter/Documents ; USER=root ; COMMAND=/bin/cp fstrim /etc/cron.weekly/
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH audit[23404]: AVC apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH kernel: audit: type=1400 audit(1557508767.543:265): apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH kernel: audit: type=1400 audit(1557508767.543:266): apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH audit[23404]: AVC apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 13 06:36:10 peter-Lenovo-ideapad-330-17ICH fstrim[1127]: /: 18,6 GiB (19953541120 bytes) trimmed
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: [SOLVED] TRIM and my SSD

Post by smurphos »

Can you run the additional script directly i.e. via this command in a terminal /etc/cron.weekly/fstrim. I suspect it's not set to be executable.

If you've got both the systemd timer and the script in cron.weekly both working, what i'd expect to see is trim running twice weekly (once via the systemd timer once via cron) with only the latter run producing the desktop report as per the script. I think both will show in jourtnalctl | grep fstrim
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Klaas Vaak

Re: [SOLVED] TRIM and my SSD

Post by Klaas Vaak »

smurphos wrote: Sun May 19, 2019 9:38 am Can you run the additional script directly i.e. via this command in a terminal /etc/cron.weekly/fstrim. I suspect it's not set to be executable.

If you've got both the systemd timer and the script in cron.weekly both working, what i'd expect to see is trim running twice weekly (once via the systemd timer once via cron) with only the latter run producing the desktop report as per the script. I think both will show in jourtnalctl | grep fstrim
What is the command to run the script? I tried

Code: Select all

sudo ./etc/cron.weekly/fstrim
but that does not work.

As for

Code: Select all

journalctl | grep fstrim
here is the output:

Code: Select all

peter@peter-Lenovo-ideapad-330-17ICH:~$ journalctl | grep fstrim
May 06 09:34:05 peter-Lenovo-ideapad-330-17ICH fstrim[1088]: /: 18,8 GiB (20199182336 bytes) trimmed
May 10 10:34:51 peter-Lenovo-ideapad-330-17ICH sudo[13913]:    peter : TTY=pts/0 ; PWD=/home/peter/Documents ; USER=root ; COMMAND=/bin/cp fstrim /etc/cron.weekly/
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH audit[23404]: AVC apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH kernel: audit: type=1400 audit(1557508767.543:265): apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH kernel: audit: type=1400 audit(1557508767.543:266): apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 10 20:19:27 peter-Lenovo-ideapad-330-17ICH audit[23404]: AVC apparmor="ALLOWED" operation="open" profile="libreoffice-soffice" name="/home/peter/Documents/fstrim" pid=23404 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
May 13 06:36:10 peter-Lenovo-ideapad-330-17ICH fstrim[1127]: /: 18,6 GiB (19953541120 bytes) trimmed
Locked

Return to “Software & Applications”