
我有一個大型的、經常讀取的 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 正在談論的事情)有助於防止因服務中斷而導致的一致性問題,但您仍然需要考慮到您的硬體會直接消失。