Edit fstrim.timer configuration [Debian Linux 11]
# Edit fstrim.timer configuration [Debian Linux 11]
There are some guides out there, located in forums. I didn't like very much what I saw.
Here I describe what I did and the results.
### Checking
```bash
$ systemctl cat fstrim.timer
# /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
RandomizedDelaySec=6000
[Install]
WantedBy=timers.target
```
### Checking
```bash
$ systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Sun 2025-03-09 18:22:05 CET; 1 day 14h ago
Trigger: Mon 2025-03-17 00:38:54 CET; 5 days left
Triggers: ● fstrim.service
Docs: man:fstrim
Warning: some journal files were not opened due to insufficient permissions.
```
### Checking
```bash
$ sudo fstrim -av
/home: 120 MiB (125820928 bytes) trimmed on /dev/sda4
/boot: 0 B (0 bytes) trimmed on /dev/sda2
/: 554.1 MiB (581054464 bytes) trimmed on /dev/sda1
```
### Checking
```bash
$ systemctl list-timers fstrim.timer --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Mon 2025-03-17 00:09:02 CET 5 days left Mon 2025-03-10 08:31:27 CET 24h ago fstrim.timer fstrim.service
1 timers listed.
```
### Edit the file to change weekly -> daily
```bash
$ sudo vi /etc/systemd/system/fstrim.timer
```
Verify
```bash
$ cat /etc/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
ConditionVirtualization=!container
[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true
RandomizedDelaySec=6000
[Install]
WantedBy=timers.target
```
### Reload
#### Correct order
```bash
$ sudo systemctl daemon-reload
```
```bash
$ sudo systemctl restart fstrim.timer
```
#### Note
If you try the `restart` without doing the `daemon-reload` first then you get
```bash
$ sudo systemctl restart fstrim.timer
Warning: The unit file, source configuration file or drop-ins of fstrim.timer changed on disk. Run 'systemctl daemon-reload' to reload units.
```
### Verify
```bash
$ sudo systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/etc/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Tue 2025-03-11 09:22:21 CET; 14s ago
Trigger: Wed 2025-03-12 00:37:18 CET; 15h left
Triggers: ● fstrim.service
Docs: man:fstrim
Mar 11 09:22:21 osboxes systemd[1]: Stopped Discard unused blocks once a week.
Mar 11 09:22:21 osboxes systemd[1]: Stopping Discard unused blocks once a week.
Mar 11 09:22:21 osboxes systemd[1]: Started Discard unused blocks once a week.
```
```bash
$ systemctl list-timers fstrim.timer --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2025-03-12 00:37:18 CET 15h left Tue 2025-03-11 09:22:16 CET 36s ago fstrim.timer fstrim.service
1 timers listed.
```
The NEXT changed from next week to next day.