如何在 Linux 中永久关闭外部 USB 驱动器的写入缓存(我使用的是 Ubuntu)?
我试过了:
命令行方法:hdparm -W0 /dev/sdb <---- 有效但仅适用于当前驱动器并在重启后重置。
hdparm“-k1”标志应该强制它保留设置,但它说:
HDIO_SET_KEEPSETTINGS 失败:参数无效
HDIO_GET_KEEPSETTINGS 失败:参数无效
配置文件方法(似乎是永久执行此操作的另一种方法):我发现的下一件事是修改位于 /etc 中的“hdparm.conf”文件。但是,这似乎要求您提前知道驱动器号、“sdb、sdc...”等。
无论如何,您如何全面覆盖所有驱动器,或特别是所有 USB 外部驱动器?
关键问题是..我不确定我将以何种顺序连接这些 USB 外部驱动器,因此驱动器号会发生变化,所以我不能只将其命名为“sdb”,因为它可能不是“sdb”...
这种情况是否会导致 hdparm.conf 中出现多次条目,即使驱动器号未连接?这样,无论连接了哪个驱动器,它都会先行关闭 write_cache。还是会造成混乱?
可能的/etc/hdparm.conf示例(这有效吗?):
/dev/sda {
write_cache = off
}
/dev/sdb {
write_cache = off
}
/dev/sdc {
write_cache = off
}
/dev/sdd {
write_cache = off
}
再次,这些驱动器可能还不存在……只是预先覆盖了字母表中尽可能多的字母,所以无论如何,write_cache 都是关闭的。不过我认为一定有比这更好的方法……
还有其他想法吗?或者更好的方法?谢谢!
答案1
您需要使用 -K 选项。来自 man hdparm
-k Get/set the "keep_settings_over_reset" flag for the drive. When this flag is set, the drive will preserve the -dmu settings
over a soft reset, (as done during the error recovery sequence). This option defaults to off, to prevent drive reset loops
which could be caused by combinations of -dmu settings. The -k option should therefore only be set after one has achieved
confidence in correct system operation with a chosen set of configuration settings. In practice, all that is typically nec‐
essary to test a configuration (prior to using -k) is to verify that the drive can be read/written, and that no error logs
(kernel messages) are generated in the process (look in /var/adm/messages on most systems).
-K Set the drive´s "keep_features_over_reset" flag. Setting this enables the drive to retain the settings for -APSWXZ over a
soft reset (as done during the error recovery sequence). Not all drives support this feature.