我有一个大型的、经常读取的 ext3 文件系统,它以只读方式安装在一个系统上,该系统通常每天硬通电循环大约 2-3 次。
由于设备通常通过切断电源来关闭电源,因此 fsck 在该文件系统上启动时运行,但对于此应用程序,快速启动时间非常重要(秒级)。
我可以在 fstab 中禁用文件系统的启动时间检查,但我的问题是,这样做安全吗?鉴于文件系统以只读方式挂载但从未正确卸载,是否有任何如果禁用启动时间检查,是否会在很长一段时间内积累文件系统损坏的风险?
答案1
从mount
联机帮助页来看,
-r, --read-only
Mount the filesystem read-only. A synonym is -o ro.
Note that, depending on the filesystem type, state and kernel
behavior, the system may still write to the device. For example,
Ext3 or ext4 will replay its journal if the filesystem is dirty.
To prevent this kind of write access, you may want to mount ext3
or ext4 filesystem with "ro,noload" mount options or set the
block device to read-only mode, see command blockdev(8).
如果ro,noload
证明是不够的,我知道没有办法只用一个 fstab 条目来设置一个只读设备;在安装文件系统之前,您可能需要通过其他方式调用blockdev --setro
或创建只读循环设备( )。losetup --read-only
如果你将其设置为真正的只读,它甚至不会知道它已安装。因此,只要没有任何内容写入设备,就不会更新安装计数,也不会强制进行 fsck,尤其是不会发生损坏......
答案2
从tune2fs
联机帮助页:
-c max-mount-counts
Adjust the number of mounts after which the filesystem will be checked by e2fsck(8). If max-mount-counts is 0 or -1, the number
of times the filesystem is mounted will be disregarded by e2fsck(8) and the kernel.
Staggering the mount-counts at which filesystems are forcibly checked will avoid all filesystems being checked at one time when
using journaled filesystems.
You should strongly consider the consequences of disabling mount-count-dependent checking entirely. Bad disk drives, cables,
memory, and kernel bugs could all corrupt a filesystem without marking the filesystem dirty or in error. If you are using jour-
naling on your filesystem, your filesystem will never be marked dirty, so it will not normally be checked. A filesystem error
detected by the kernel will still force an fsck on the next reboot, but it may already be too late to prevent data loss at that
point.
See also the -i option for time-dependent checking.
和:
-i interval-between-checks[d|m|w]
Adjust the maximal time between two filesystem checks. No postfix or d result in days, m in months, and w in weeks. A value of
zero will disable the time-dependent checking.
It is strongly recommended that either -c (mount-count-dependent) or -i (time-dependent) checking be enabled to force periodic
full e2fsck(8) checking of the filesystem. Failure to do so may lead to filesystem corruption due to bad disks, cables, memory,
or kernel bugs to go unnoticed until they cause data loss or corruption.
所以你可以将两者设置为零,这应该禁用自动fsck
(假设你实际上不过我想这么做)。
答案3
出于历史和上下文原因留下我的其他答案,但重新阅读我看到你的实际问题:是的,你仍然想最终做一个fsck
.所有磁盘的寿命都是有限的,并且fsck
会将坏扇区分配给“坏块”inode/列表,以便没有新文件会使用它们。
只读(并且执行noload
frotschutz 正在谈论的事情)有助于防止由于服务中断而导致的一致性问题,但您仍然需要考虑到您的硬件会直接消失。