fsck ro mounted partition dangerous?!

  • Bernhard Kuemel

    Bernhard Kuemel - 2005-10-24

    fsck says even if a fs is mounted ro:

    "WARNING!!!  Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage."

    There is much confusion whether it is ok to fsck a ro mounted fs. I currently believe it is ok. Could you please clarify this in the program and the man page.

    Shall I make this a bug/feature/support request?

    Thanks, Bernhard

    • Vitaly Oratovsky

      I think it is NOT ok to run fsck on a mounted fs even if it is mounted read-only, unless you're running fsck with -n option.

      Look at it this way:  after the fs is mounted, a certain amount of data is cached in kernel memory.  As the directory structure is traversed, more info gets cached.  But fsck operates directly on the disk device, so if it makes any changes it can introduce inconsistencies with cached structures.  Therefore, it is not hard to imagine that you can confuse the kernel and cause your system to panic.

      • Theodore Ts'o

        Theodore Ts'o - 2006-02-13

        This is why after checking a filesystem which is mounted read-only, e2fsck returns an exit status which tells the init scripts to reboot the system.  It is definitely _not_ safe to remount the filesystem read/write after e2fsck completes, becaused of the cached structure.

        It is possible if the filesystem is sufficiently corrupted, that running e2fsck while mounted read-only could cause problems.  On the other hand, in that case the filesystem is almost certainly so badly corrupted that it's likely that the kernel might panic trying to read it, or more likely, detect an inconsistency and panic the system before e2fsck even has a chance to run.

        If you really want to be safe, the best thing to do is to run e2fsck out of initrd; but the advantage that you would gain is probably marginal at best, and would only be in how the system handled a so badly trashed filesystem that boot process would have aborted and required manual intervention anyway.


Log in to post a comment.