From 18.04 fstrim
(discard unused blocks) is enabled to run weekly by default for all mounted filesystems on devices that support the discard operation.
fstrim
is managed by systemctl
, not cron
, and is defined by a systemd
service unit (fstrim.service
) and timer unit (fstrim.timer
)
View configuration of fstrim.service
:
$ systemctl cat fstrim.service
# /lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/sbin/fstrim -av
Note: ExecStart=/sbin/fstrim
-av
Where:
-a
, Trim all mounted filesystems on devices that support the discard operation.
-v
, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.
View configuration of fstrim.timer
:
$ 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
View status of fstrim.timer
:
$ 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 Thu 2018-07-05 05:45:11 BST; 4h 42min ago
Trigger: Mon 2018-07-09 00:00:00 BST; 3 days left
Docs: man:fstrim
Start/Stop/Restart fstrim.timer
:
(does not change startup status)
$ sudo systemctl [start/stop/restart] fstrim.timer
Enable/Disable fstrim.timer
:
(add to/remove from startup, does not change current active status)
$ sudo systemctl [enable/disable] fstrim.timer
View journal entries for fstrim.service
:
$ journalctl -u fstrim.service
...
May 01 07:57:48 user-laptop systemd[1]: Starting Discard unused blocks...
May 01 07:57:51 user-laptop fstrim[810]: /: 94.5 GiB (101432025088 bytes) trimmed
May 01 07:57:51 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
May 07 05:29:03 user-laptop systemd[1]: Starting Discard unused blocks...
May 07 05:29:05 user-laptop fstrim[776]: /: 94.3 GiB (101260668928 bytes) trimmed
May 07 05:29:05 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
etc...
View journal entries for fstrim.timer
:
$ journalctl -u fstrim.timer
...
May 01 07:57:48 user-laptop systemd[1]: Started Discard unused blocks once a week.
May 01 20:21:43 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
-- Reboot --
May 02 06:21:59 user-laptop systemd[1]: Started Discard unused blocks once a week.
May 02 20:37:11 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
-- Reboot --
etc...