Tune2fs "mountcount" and USB drive power-up filesystem checks

Looking to confirm true nature of behaviour.

I use an External USB drive for backups.

Using tune2fs, I have specified a mountcount value of 20 for each of the partitions on that drive. I can't remember how, but I did specify the individual count on each partition so that the fsck would be staggered (not all at the same boot) if I always mount all those USB partitions every time.

QUESTION:
If the partition's "mountcount" dictates that this power-up event would reach the count at which an fsck should be performed,

  • with no auto-mount directive in place, does the simple act of plugging in the USB drive trigger the fsck action ... before any mount directive has been given?           or

  • does the OS perform the fsck only as a pre-requisite first step during the performance of the mount command?

I don't really know much about this but I was reading some articles and I found this page so this may clear some things out possibly: https://linux.die.net/man/8/tune2fs

Here it says clearly that systemd-fsck is a service that checks everything before mounting i.e. as a pre-mount setup "

If I understand things correctly here I think it should not trigger fsck action on its own just by merely inserting a drive but I may be incorrect in the conclusion - I guess fsck is used when it's a part of the mount process by the system and follows settings that are given to it

I ran into this article as well and I saw here that udev is the thingy you are looking for since it is the one that detects what is being inserted into the system and it then, based on the rules given, decides if there will be mounting and if so then the system runs fsck:

This Arch wiki article though warns not to start mount from udev rules and here are extensive rules and examples of udev to see how it works exactly

Hope the information I provided make more sense to you than they did for me - I feel I am on the right track but I also feel that I am at my limits in regards to understanding how exactly to answer your question with clarity

2 Likes

Thank you, Alarik, for bringing all those to my attention. It is much appreciated.

I guess I'm guilty of having not read closely enough, or interpreting incorrectly, because the section on "mount-count" seems to have spelled it out clearly enough:

        -C mount-count
                  Set the number of times the file system has been
                  mounted. If set to a greater value than the
                  max- mount-counts parameter set by the -c option,
                  e2fsck(8) will check the file system at the next reboot.

So ... the fsck is not performed at the time the count reaches the the max count, it actually allows max+1 count before flagging the partition for a forced fsck ONLY during the next reboot.

Given that we are talking about removable USB devices, NOT permanently-attached nor visible at boot time, it must then mean that an fsck is forced after the partition is powered up and visible to the OS via the USB bus.



For the UDEV references, again, thank you.

I don't understand that whole architecture, any more than yourself, so I will need to study that to see if there is a way for me to customize the triggering of a syslog message recording the fsck action that, when it does happens. That would give me the positive feedback and peace of mind I am looking for. :slight_smile:

2 Likes

Glad I could help in any way - and good luck with your research :blush:

1 Like