Filesystems

ext4:乾淨的文件系統是否需要日誌恢復?

  • June 1, 2015

我一直認為“乾淨”是不需要日誌恢復的同義詞。

然而,情況似乎並非如此

$ sudo file -s /dev/sdc4
/dev/sdc4: Linux rev 1.0 ext4 filesystem data, UUID=117ce600-a129-446b-8859-1e20ad8fe823, volume name "platform" (needs journal recovery) (extents) (large files) (huge files)
$ sudo fsck -n /dev/sdc4
fsck from util-linux 2.25.1
e2fsck 1.42.12 (29-Aug-2014)
Warning: skipping journal recovery because doing a read-only filesystem check.
platform: clean, 13031/186800 files, 129254/790272 blocks
$ sudo file -s /dev/sdc4
/dev/sdc4: Linux rev 1.0 ext4 filesystem data, UUID=117ce600-a129-446b-8859-1e20ad8fe823, volume name "platform" (needs journal recovery) (extents) (large files) (huge files)
$ sudo fsck -n /dev/sdc4
fsck from util-linux 2.25.1
e2fsck 1.42.12 (29-Aug-2014)
Warning: skipping journal recovery because doing a read-only filesystem check.
platform: clean, 13031/186800 files, 129254/790272 blocks

file 和 fsck 都同意需要日誌恢復。仍然 fsck 說文件系統是乾淨的。-n 標誌顯然做了我想要的,文件系統保持不變,所以 clean 不能指已成功清理(應用日誌)。

編輯:文件系統未安裝。

文件系統未正確解除安裝。

“fsck -n”輸出末尾的“clean”具有誤導性。這並不意味著不需要恢復。這只是意味著如果你已經達到了這一點,沒有-n,文件系統就會很乾淨。

如何重現:

sh-4.3# dd if=/dev/zero of=/tmp/test.fs bs=1M count=5
5+0 records in
5+0 records out
5242880 bytes (5.2 MB) copied, 0.00333063 s, 1.6 GB/s
sh-4.3# mkfs.ext4 /tmp/test.fs
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done                            
Creating filesystem with 5120 1k blocks and 1280 inodes

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
sh-4.3# mkdir /tmp/t
sh-4.3# mount -o loop /tmp/test.fs /tmp/t
sh-4.3# ls / > /tmp/t/file
sh-4.3# umount /tmp/test.fs 
sh-4.3# fsck -n /tmp/test.fs
fsck from util-linux 2.25.2
e2fsck 1.42.12 (29-Aug-2014)
/tmp/test.fs: clean, 12/1280 files, 1224/5120 blocks
sh-4.3# mount -o loop /tmp/test.fs /tmp/t
sh-4.3# ls / > /tmp/file2
sh-4.3# cp /tmp/test.fs /tmp/test-unclean.fs
sh-4.3# fsck.ext4 -n /tmp/test-unclean.fs 
e2fsck 1.42.12 (29-Aug-2014)
Warning: skipping journal recovery because doing a read-only filesystem check.
/tmp/test-unclean.fs: clean, 12/1280 files, 1224/5120 blocks
sh-4.3# mkdir /tmp/t2
sh-4.3# mount -o loop /tmp/test-unclean.fs /tmp/t2
sh-4.3# dmesg | tail
...
[66569.074538] EXT4-fs (loop1): recovery complete
[66569.074554] EXT4-fs (loop1): mounted filesystem with ordered data mode. Opts: (null)
sh-4.3# umount /tmp/test-unclean.fs 
sh-4.3# fsck -n /tmp/test-unclean.fs 
fsck from util-linux 2.25.2
e2fsck 1.42.12 (29-Aug-2014)
/tmp/test-unclean.fs: clean, 12/1280 files, 1224/5120 blocks

引用自:https://unix.stackexchange.com/questions/206884