13

We have RedHat 7.2 OS.

/dev/sdc is mounted to /bla/appLO

Is it possible to run fsck on mounted disks (without umount /bla/appLO) and to see only the errors if they exist?

Example:

e2fsck -n /dev/sdc
e2fsck 1.42.9 (28-Dec-2013)
Warning!  /dev/sdc is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
/dev/sdc: clean, 11/1310720 files, 126322/5242880 blocks

Does fsck -n show the error even though the disk is mounted?

Ankur S
  • 1,208
  • 2
  • 7
  • 17
yael
  • 12,598
  • 51
  • 169
  • 303

1 Answers1

10

No.

You should never run fsck on a mounted filesystem. Correcting errors on a live filesystem will mess up your disk. Even if you run the tool in read-only mode (without error correction) the results can't be trusted. This is true even if the filesystem is mounted read-only.

From man e2fsck:

Note that in general it is not safe to run e2fsck on mounted filesystems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified. 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.

From man fsck:

For some filesystem-specific checkers, the -n option will cause the fs-specific fsck to avoid attempting to repair any problems, but simply report such problems to stdout. This is however not true for all filesystem-specific checkers. In particular, fsck.reiserfs(8) will not report any corruption if given this option. fsck.minix(8) does not support the -n option at all.

You should take the time to unmount the disk and do a proper filesystem check; results that cannot be trusted aren't useful at all.

dr_
  • 28,763
  • 21
  • 89
  • 133
  • thank you , could you help me with my question on - https://unix.stackexchange.com/questions/439661/mount-verify-disk-status-disk-isnt-read-write – yael Apr 24 '18 at 08:44
  • I already seen your question, it puzzles me. I've never seen `ew` in the output of `mount`. I'd be interested to know the answer too. – dr_ Apr 24 '18 at 08:48
  • Does this prohibition against fsck, even with `-n` specified, include on filesystems that are mounted read-only? – Daniel Griscom Nov 26 '19 at 14:55
  • @DanielGriscom I'd say yes, as fsck would need to do writes on the filesystem anyway, in case of errors. – dr_ Dec 04 '19 at 19:27
  • 1
    @dr01 No: with the `-n` option fsck makes no changes to the filesystem, correct? So, if the filesystem is mounted read-only then the mounted state won't confuse fsck, and if `fsck -n` is used then no fsck changes would be made and the filesystem couldn't be corrupted, right? – Daniel Griscom Dec 04 '19 at 20:19
  • I've added the `fsck` man page output to the answer. By doing this you might get incorrect results (as I wrote in my answer, 2nd paragraph), and errors won't be fixed anyway. Perhaps it's just me, but I like to play safe, and would never run `fsck` on any mounted fs. – dr_ Dec 05 '19 at 12:42