0

I have a couple of (clean) filesystems declared in my fstab with the noauto mount option set and fs_passno set to 2.

For whatever reason (power failure, kernel panic, hard reset…), those filesystems not having been mounted once since bootime, the system is not shutdown-ed normally.

On next reboot, each one of these filesystems are reported (on console) checked and quickly declared clean

Q1 : Is this conclusion (fs clean) driven by the sole reading of the superblock's s_state field or are there other checks made ?

Q2 : Does it depend on the reasons that triggered the abnormal shutdown ?

Q3 : Will these checks command fsck to mount the filesystem ?

Q4 : While these clean statuses are reported on console, why can't I find these reports echoed in my kernel (or any other) logs while traces for those file systems that actually needed repair and eventually recovering from journal are ?


Under Linux-5.4 / e2fsck 1.46.5 / openrc as init system and metalog acting as syslog daemon if that matters.
metalog's most relevant rules :

Kernel messages :
        facility        = "kern"
        logdir          = "/var/log/kernel"
        break=1
Fallback:
        facility        = "*"
        minimum         = 6
        logdir          = "/var/log/fallback"

2 Answers 2

0

Please don't ask multiple questions.

When a partition is mounted, the filesystem code copies the partition's block allocation tables into memory, and marks the disk's tables "needs recovery".

The filesystem code manages block allocation at memory speed, which is MUCH faster than disk speed.

Periodically, the in-memory tables are written back to disk, both to keep them relatively uptodate, and to avoid the need to keep all of them in memory at once.

When the partition is umounted, the in-memory tables are written to disk (clearing the "needs recovery" flag). The in-memory tables are discarded.

When the system crashes, the up-to-date in-memory tables are lost, and the "needs recovery" flag is still set on the disk.

If the filesystem is required for boot (/etc/fstab entry has auto), and the "needs recovery" flag is set on-disk, a filesystem-specific fsck is run (e.g. fsck.ext4 for ext4 filesystems) to "recover" the filesystem - make the block allocation tables "right" (minimize data loss, ensure that no blocks are neither free nor used, ...), preserve blocks that were written while "needs recovery", etc. Since the fsck is building its own tables, the disk may not be mounted, and, besides, the disk has the "needs recovery" flag set until fsck succeeds.

This pre-mount system-caused fsck activity takes place before the boot process is "up" enough to really log the messages, but try dmesg.

Thanks LustreOne,

At mount time, e2fsck will check both the journal "needs recovery" flag as well as do a basic check of the superblock and group descriptor blocks that it needs to mount the filesystem. If "needs recovery" is set, then it will replay the journal. If other errors are found in then it will run a full e2fsck of the filesystem. – LustreOne

3
  • Thank you for your detailed post. However, I fail to understand how it addresses my principal problem in understanding what checks make fsck declare clean a filesystem that was not mounted when the system crashed.
    – MC68020
    Commented Apr 21 at 9:01
  • At mount time, e2fsck will check both the journal "needs recovery" flag as well as do a basic check of the superblock and group descriptor blocks that it needs to mount the filesystem. If "needs recovery" is set, then it will replay the journal. If other errors are found in then it will run a full e2fsck of the filesystem.
    – LustreOne
    Commented Apr 22 at 16:01
  • Apologizes to all. From your answers and comments, I realize that my question was not appropriately worded. I rewrote it.
    – MC68020
    Commented May 3 at 11:47
0

Although your distro may not be with systemd, but the mechanics is the same:

systemd-fsck(8):

systemd-fsck does not know any details about specific filesystems, and simply executes file system checkers specific to each filesystem type (fsck.type). These checkers will decide if the filesystem should actually be checked based on the time since last check, number of mounts, unclean unmount, etc.

It seems that somehow you thought if you see this "clean" message, it means that the checker has auto-repaired the corresponding filesystem (which you thought to be corrupted for some reason even if "it was never mounted"), but that is simply not the case.

In case you are curious, fsck can be run on a filesystem that is not currently mounted, or is currently mounted with the option ro (read-only).

Also, FYI, the case of the boot-time fsck for the / filesystem is somewhat special. In some setup the / filesystem is mounted with ro first (the option is set in the kernel line of the boot entry in your bootloader), then fs_passno is used to determined whether the / checker should be executed. After the fsck, if requested, the filesystem would be remounted as per the corresponding fstab line. Normally / typically you would not have ro there (rw is the default, so it can be omitted), so that the / is remounted writable.

Another approach is that some configuration value in e.g. the boot entry and/or the initramfs (which are loaded by the bootloader in its own "context") would be used to determine whether the checker should be executed for the / filesystem, and the check, if requested, would be performed before it is mounted at all (in the OS-level "context"; I do NOT mean "has never been mounted before" here btw), which would allow it to be mounted with rw straight away after the fsck is done.

(NOTE: "requested", "after fsck", et al. in the above refers to the execution of the checker; as stated in the quote, the checker is what and what only decides whether actual check should be performed on a filesystem)

P.S. I don't mean that it is always true that a filesystem can't be corrupted if it was never mounted. It could still be corrupted for various reasons, obviously. For one if your drive is dying.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .