检查 trim 是否正常工作的命令?

检查 trim 是否正常工作的命令?

我已经安装了 Ubuntu 14.04 LTS 64 位,并且想确保 TRIM 已启用(据我所知 - 它默认启用)。是否有某种命令可以帮助我查明它是否正常工作?

答案1

您可以执行sudo fstrim -v /(如果有,请将“/”替换为其他挂载点),以检查 fstrim 是否出现任何错误。如果没有,请输入,cat /etc/cron.weekly/fstrim这将为您提供如下输出:

#!/bin/sh
# call fstrim-all to trim all mounted file systems which support it
set -e
#
# This only runs on Intel and Samsung SSDs by default, as some SSDs with
# faulty firmware may encounter data loss when running fstrim under high I/O
# load (e. g.  https://launchpad.net/bugs/1259829). You can append the
# --no-model-check option here to disable the vendor check and run fstrim on
# all SSD drives Like this (remove the hash):
#exec fstrim-all --no-model-check
exec fstrim-all

如果确实如此,则意味着你的 Ubuntu 自动识别到你有一个 SSD,并且会将其作为 cron 作业每周修剪一次。

如果您想针对 SSD 优化系统,请查看本文

答案2

我建议,确保 trim 正常工作的更直接(尽管有些复杂)的方法是创建一个文件,准确标识此文件的存储位置,检查此位置的文件内容,删除文件,然后重新检查文件位置的内容。如果 trim 正常工作,则文件的原始内容将被零替换。进行此测试的方法和具体命令记录在以下位置:http://andyduffell.com/techblog/?p=852该技术的一个具体示例如下:https://linuxnorth.wordpress.com/2014/03/18/trim-your-ssd-down-to-size/

答案3

在 18.04 上,您可以在 syslog 中检查它:

cat /var/log/syslog | grep -a fstrim | tail

如果您看到最近的日期和所有 SSD 的挂载点,则表示它正在运行。示例输出:

Oct  1 14:54:55 justapc fstrim[769]: /home: 80,1 GiB (86008037376 bytes) trimmed
Oct  1 14:54:55 justapc fstrim[769]: /boot: 360,2 MiB (377663488 bytes) trimmed
Oct  1 14:54:55 justapc fstrim[769]: /: 16,3 GiB (17486880768 bytes) trimmed
Oct  8 08:16:01 justapc fstrim[792]: /home: 76,8 GiB (82423615488 bytes) trimmed
Oct  8 08:16:01 justapc fstrim[792]: /boot: 360,1 MiB (377634816 bytes) trimmed
Oct  8 08:16:01 justapc fstrim[792]: /: 15,9 GiB (17038168064 bytes) trimmed
Oct  8 08:16:44 justapc ureadahead[283]: ureadahead:trimage_trimage.png: Ignored relative path
Oct 15 20:14:00 justapc fstrim[749]: /home: 73,5 GiB (78863814656 bytes) trimmed
Oct 15 20:14:00 justapc fstrim[749]: /boot: 360,1 MiB (377634816 bytes) trimmed
Oct 15 20:14:00 justapc fstrim[749]: /: 16 GiB (17104076800 bytes) trimmed

为了确保任何可能的错误,请手动详细执行 fstrim:

for mountpoint in $(cat /etc/fstab | awk '/ext[0-9]/ {print $2}'); do sudo fstrim -v "$mountpoint"; done

相关内容