You are not logged in.

#1 2020-01-27 16:16:22

swipe
Member
Registered: 2017-02-23
Posts: 10

[SOLVED] fstrim.service no longer showing trimmed drives

I just noticed that fstrim.service is no longer showing trimmed drives. This was not the case last week. Can anyone else confirm the same? Manually trimming them with fstrim works.

$ journalctl -u fstrim.service

-- Reboot --
Jan 20 07:16:24 Nuc systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Jan 20 07:16:37 Nuc fstrim[419366]: /: 8.8 GiB (9443913728 bytes) trimmed on /dev/mapper/VG-Root
Jan 20 07:16:37 Nuc fstrim[419366]: /home: 42 GiB (45112033280 bytes) trimmed on /dev/mapper/VG-Home
Jan 20 07:16:37 Nuc fstrim[419366]: /boot: 101.9 MiB (106875904 bytes) trimmed on /dev/sda2
Jan 20 07:16:37 Nuc fstrim[419366]: /boot/efi: 196.6 MiB (206108672 bytes) trimmed on /dev/sda1
Jan 20 07:16:37 Nuc systemd[1]: fstrim.service: Succeeded.
Jan 20 07:16:37 Nuc systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.
-- Reboot --
Jan 27 08:51:59 Nuc systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Jan 27 08:52:00 Nuc systemd[1]: fstrim.service: Succeeded.
Jan 27 08:52:00 Nuc systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.

$ systemctl cat fstrim.service

[Unit]
Description=Discard unused blocks on filesystems from /etc/fstab
Documentation=man:fstrim(8)
ConditionVirtualization=!container

[Service]
Type=oneshot
ExecStart=/usr/bin/fstrim --fstab --verbose --quiet
ProtectSystem=strict
ProtectHome=read-only
PrivateDevices=no
PrivateNetwork=yes
PrivateUsers=no
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
MemoryDenyWriteExecute=yes
SystemCallFilter=@default @file-system @basic-io @system-service

$ cat /etc/fstab

UUID=766D-8312 /boot/efi vfat defaults,rw,noatime 0 0
UUID=b60e2905-bdcb-435d-99b8-5508fee904ab /boot ext4 defaults,rw,noatime 0 0
/swapfile none swap defaults 0 0
UUID=d2682a36-ad7d-4afd-9328-505e076dde24 /home ext4 defaults,rw,relatime,data=ordered 0 0
UUID=7b8ad445-3d20-4b63-bf71-878fad678d92 / ext4 defaults,rw,relatime,data=ordered 0 1

$ uname -r

5.4.15-arch1-1

Last edited by swipe (2020-02-01 16:33:14)

Offline

#2 2020-01-27 17:03:39

Ropid
Member
Registered: 2015-03-09
Posts: 713

Re: [SOLVED] fstrim.service no longer showing trimmed drives

It's also not logging anything for me. What's interesting is that the timestamps are suspicious: the "Starting ..." and "Started ..." messages are very close to each other, as if fstrim has finished its work instantly which can't be right. In the old behavior there was a gap in time to give the service time to do its work.

Trying to research into what's going on, I found out that the "fstrim.service" file has changed on January 24 in an update for the "util-linux" package, but the changed "fstrim.service" file is not causing the different behavior. I extracted the old fstrim.service file and put it into /etc/systemd/system and started it, and it behaves exactly like the new file and does not log anything interesting.

If you are interested in seeing the old file, it looks like this:

[Unit]
Description=Discard unused blocks on filesystems from /etc/fstab
Documentation=man:fstrim(8)

[Service]
Type=oneshot
ExecStart=/usr/bin/fstrim --fstab --verbose --quiet
ProtectSystem=strict
ProtectHome=yes
PrivateDevices=no
PrivateNetwork=yes
PrivateUsers=no
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
MemoryDenyWriteExecute=yes
SystemCallFilter=@default @file-system @basic-io @system-service

But like I mentioned, this old file has the same problem and also does not log interesting output, just like the new file. If you still want to try it yourself to make sure, copy this file into /etc/systemd/system and do "systemctl daemon-reload" and then start the service.

Offline

#3 2020-01-27 17:15:31

swipe
Member
Registered: 2017-02-23
Posts: 10

Re: [SOLVED] fstrim.service no longer showing trimmed drives

As you say, due to the closeness of the log entries, I think it's a case of it not trimming rather than not just logging it.

Offline

#4 2020-02-01 13:09:30

swipe
Member
Registered: 2017-02-23
Posts: 10

Re: [SOLVED] fstrim.service no longer showing trimmed drives

Also confirmed on my laptop I use at my parents. Before and after util-linux upgrade:


journalctl -u fstrim.service

-- Reboot --
Jan 25 14:20:31 hp-laptop systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Jan 25 14:20:42 hp-laptop fstrim[414]: /: 217.7 GiB (233766383616 bytes) trimmed on /dev/sda1
Jan 25 14:20:42 hp-laptop systemd[1]: fstrim.service: Succeeded.
Jan 25 14:20:42 hp-laptop systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.
-- Reboot --
Feb 01 12:57:58 hp-laptop systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Feb 01 12:57:59 hp-laptop systemd[1]: fstrim.service: Succeeded.
Feb 01 12:57:59 hp-laptop systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.

Offline

#5 2020-02-01 14:16:48

progandy
Member
Registered: 2012-05-17
Posts: 3,717

Re: [SOLVED] fstrim.service no longer showing trimmed drives

I suggest you remove the --quiet option and then look at the error messages.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#6 2020-02-01 14:26:43

swipe
Member
Registered: 2017-02-23
Posts: 10

Re: [SOLVED] fstrim.service no longer showing trimmed drives

progandy wrote:

I suggest you remove the --quiet option and then look at the error messages.

I tried that and there were none.

Offline

#7 2020-02-01 14:38:31

progandy
Member
Registered: 2012-05-17
Posts: 3,717

Re: [SOLVED] fstrim.service no longer showing trimmed drives

Does it work with a minimal systemd service without any protection features?


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#8 2020-02-01 15:32:51

webcapcha
Member
Registered: 2019-02-14
Posts: 36

Re: [SOLVED] fstrim.service no longer showing trimmed drives

Can confirm too. The same behavior.

Offline

#9 2020-02-01 16:29:27

swipe
Member
Registered: 2017-02-23
Posts: 10

Re: [SOLVED] fstrim.service no longer showing trimmed drives

This is fixed by commenting out

ProtectSystem=strict

Offline

#10 2020-02-01 16:49:14

progandy
Member
Registered: 2012-05-17
Posts: 3,717

Re: [SOLVED] fstrim.service no longer showing trimmed drives

Hmm...  It seems they fixed a variable in the check for read-only fileystems. I wonder if that "fixed" the detection of read-only bindmounts that systemd uses in strict mode.
https://git.kernel.org/pub/scm/utils/ut … a345e6b409

		/* FITRIM on read-only filesystem can fail, and it can fail */
		if (access(tgt, W_OK) != 0) {
			if (errno == EROFS)
				continue;
			if (errno == EACCES)
				continue;
		}

| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

Board footer

Powered by FluxBB