3

I noticed that manual seldom invocations of fstrim -av take a lot of time (over 10 minutes) and report a lot of free space to the SSD:

# /usr/bin/time -p fstrim -av
/boot/efi: 503,2 MiB (527671296 Bytes) auf /dev/sda1 getrimmt
/: 377 GiB (404832960512 Bytes) auf /dev/sda2 getrimmt
real 691.65
user 0.00
sys 4.90

This makes me think that for whatever reason, the free blocks are not reported by the operating system automatically despite of the discard flags in /etc/fstab. So, I wish to go sure and get fstrim -a executed regularly; I'm ok with each computer start, each day, each week, or once a month. What's the best way to arrange this schedule automatically; in other words, into which script file do I add this call?

5

Your system by default is setup to do this using systemd. Check the status of the timer:

systemctl status fstrim.timer

By default, it is set to run fstrim -A once every week, as you can see in the output of:

systemctl cat fstrim.service

There is no use to do this more than once a week, expect for extreme usage with lots of file deletes, moves, etc., where more frequent trimming may be needed.

This actually answers also your question: you can have any job setup to run automatically using systemd. You still can use the "old" approach using crontab, which still is available by default on Ubuntu.

If you know what you do, you can edit the service.

| improve this answer | |
  • Oh, yes. Upon doing # systemctl cat fstrim.service, I saw ExecStart=/sbin/fstrim --fstab --verbose --quiet. Ist it possile to change -A (=--fstab) to -a (thus extending the scope, imho) and remove the --quiet option? – Just_A_Man May 23 at 18:23
  • 1
    You can edit a systemd service. I added link to relevant info. – vanadium May 24 at 8:41
  • Done, thx. Btw., do you know why debian uses -a, whereas ubuntu uses -A? – Just_A_Man May 24 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.