I know, running
fsck on a mounted filesystem is utterly unrecommended. The command warns you (it actually frightens you) with the following message:
# fsck /dev/VolGroup00/LogVol00 fsck 1.41.4 (27-Jan-2009) e2fsck 1.41.4 (27-Jan-2009) /dev/VolGroup00/LogVol00 is mounted. WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? no check aborted.
But sometimes I need to check a filesystem in a remote host, so I cannot boot from a liveCD to run
fsck in the unmounted device. Looking for an option allowing me to overcome this nuisance I found the following in e2fsck’s man page:
Note that in general it is not safe to run e2fsck on mounted filesys- tems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified.
e2fsck instead of
fsck is not a problem because it checks ext2 and ext3 filesystems and mine are ext3 (
fsck checks and optionally repairs a lot of filesystem types).
Let us see what the man page says about the
-n Open the filesystem read-only, and assume an answer of `no' to all questions. Allows e2fsck to be used non-interactively. (Note: if the -c, -l, or -L options are specified in addition to the -n option, then the filesystem will be opened read-write, to permit the bad-blocks list to be updated. However, no other changes will be made to the filesystem.) This option may not be specified at the same time as the -p or -y options.
So it seems to be safe running it with that option. But the
e2fsck man page also states (dealing with the safe check):
However, even if it is safe to do so, the results printed by e2fsck are not valid if the filesystem is mounted. If e2fsck asks whether or not you should check a filesystem which is mounted, the only correct answer is ``no''. Only experts who really know what they are doing should consider answering this question in any other way.
So, I use it only when I want to know if there is something wrong with the filesystem. I run it with the
-f option too which forces checking even if the file system seems clean.
# e2fsck -fn /dev/VolGroup00/LogVol00 e2fsck 1.41.4 (27-Jan-2009) Warning! /dev/VolGroup00/LogVol00 is mounted. Warning: skipping journal recovery because doing a read-only filesystem check. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information F10-i686-Live: 123335/475136 files (3.8% non-contiguous), 876070/1900544 blocks
If the output is like above all is OK, but if the device has errors, then you will need to run
fsck with the filesystem unmounted.