启用 fstrim.service 时出现错误消息

RTC*_*222 5 filesystem trim fstab services

自去年二月以来,我一直在运行 Ubuntu 20.04 桌面。

\n

今天我发布sudo systemctl enable fstrim.service并收到了这样的消息:

\n
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,\nAlias= settings in the [Install] section, and DefaultInstance= for template\nunits). This means they are not meant to be enabled using systemctl.\n \n\nPossible reasons for having this kind of units are:\n\xe2\x80\xa2 A unit may be statically enabled by being symlinked from another unit's\n  .wants/ or .requires/ directory.\n\xe2\x80\xa2 A unit's purpose may be to act as a helper for some other unit which has\n  a requirement dependency on it.\n\xe2\x80\xa2 A unit may be started when needed via activation (socket, path, timer,\n  D-Bus, udev, scripted systemctl call, ...).\n\xe2\x80\xa2 In case of template units, the unit is meant to be enabled with some\n  instance name specified.\n
Run Code Online (Sandbox Code Playgroud)\n

然后我检查该服务是否已启用,因此我发出journalctl -fu fstrim并得到 \xe2\x80\x9cLogs 从 Sun 2022-07-10 07:55:26 PDT\xe2\x80\x9d 开始,后面是事件列表8月8日和8月15日。

\n

最后,我发出systemctl status fstrim.service并得到以下消息:

\n
fstrim.service - Discard unused blocks on filesystems from /etc/fstab\n     Loaded: loaded (/lib/systemd/system/fstrim.service; static; vendor preset:>\n     Active: inactive (dead)\nTriggeredBy: fstrim.timer\n       Docs: man:fstrim(8)\n
Run Code Online (Sandbox Code Playgroud)\n

所以看起来 fstrim 已经在运行,并且在我二月份安装 Ubuntu 时默认启用。我的问题是:

\n

(1) 上面显示的来自 ``sudo systemctl enable fstrim.service 的消息有何意义?

\n

(2) 看来每周一运行一次。是足够频繁还是太频繁?如果需要,如何更改调整频率?

\n

(3) 由于它是开箱即用的,是否还有其他建议启用的选项?

\n

Rin*_*ind 4

是的。当安装程序看到 SSD 时,fstrim 将自动安装。

\n
    \n
  • 上面显示的这些消息有何意义sudo systemctl enable fstrim.service
  • \n
\n

除了已经显示的原因之外,当服务已经运行时也会显示这一点。当已经存在符号链接时它会被触发/etc/systemd/system/multi-user.target.wants/

\n
    \n
  • 它似乎每周运行一次,即周一。是足够频繁还是太频繁?如果需要,如何更改调整频率?
  • \n
\n

是的。不。从手册中可以看出:

\n
\n

频繁运行 fstrim,甚至使用mount -o discard,可能会对劣质 SSD 设备的使用寿命产生负面影响。对于大多数桌面\xe2\x80\x90\n顶部和服务器系统,每周一次\n就足够了。

\n
\n

并查看fstrim.timer服务。里面有一个“周刊”:

\n
$ more /usr/lib/systemd/system/fstrim.timer\n[Unit]\nDescription=Discard unused blocks once a week\nDocumentation=man:fstrim\nConditionVirtualization=!container\nConditionPathExists=!/etc/initrd-release\n\n[Timer]\nOnCalendar=weekly\nAccuracySec=1h\nPersistent=true\nRandomizedDelaySec=6000\n\n[Install]\nWantedBy=timers.target\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  • 由于它是开箱即用的,是否还有其他建议启用的选项?
  • \n
\n

不。建议不要更改其中任何一个。

\n

但除了fstrim.timer提供的功能之外,手册fstrim还有 4 个选项来控制功能fstrim

\n
\n

默认情况下,fstrim 将丢弃文件系统中所有未使用的块。\n可使用选项根据范围或大小修改此行为,\n如下所述。

\n
\n

它所指的选项有:

\n
\n

-o, --offset offset\n文件系统中的字节偏移量,从该偏移量开始搜索\n要丢弃的空闲块。默认值为零,从文件系统的开头开始。

\n
   -l, --length length\n       The number of bytes (after the starting point) to search for free\n       blocks to discard. If the specified value extends past the end of\n       the filesystem, fstrim will stop at the filesystem size boundary.\n       The default value extends to the end of the filesystem.\n\n   -I, --listed-in list\n       Specifies a colon-separated list of files in fstab or kernel\n       mountinfo format. All missing or empty files are silently ignored.\n       The evaluation of the list stops after first non-empty file. For\n       example:\n\n       --listed-in /etc/fstab:/proc/self/mountinfo.\n\n -m, --minimum minimum-size\n       Minimum contiguous free range to discard, in bytes. (This value is\n       internally rounded up to a multiple of the filesystem block size.)\n       Free ranges smaller than this will be ignored and fstrim will\n       adjust the minimum if it\xe2\x80\x99s smaller than the device\xe2\x80\x99s minimum, and\n       report that (fstrim_range.minlen) back to userspace. By increasing\n       this value, the fstrim operation will complete more quickly for\n       filesystems with badly fragmented freespace, although not all\n       blocks will be discarded. The default value is zero, discarding\n       every free block.\n
Run Code Online (Sandbox Code Playgroud)\n
\n