Skip to content
Advertisement

Determining filesystem for block device if module not loaded

I’ve been wondering this for a while now. When using Linux and plugging in an e.g. USB stick or external storage device via USB, how does the kernel determine which filesystem is on that device, if the correct module is not currently loaded in memory?

Assume that the external storage device is ext4 formatted. At the time of plugging in the device, the ext4 module has not been loaded into memory yet. Now, usually the kernel tries to probe the different filesystems by calling the appropiate *_fill_super function of the respective module. But that only works if the module is even present at the time of probing. How does the kernel handle mounting devices in situations where the correct filesystem module is not yet loaded in memory?

For me it seems to be a kind of chicken-egg problem as the *_fill_super function needed to determine the correct module is located in the module itself. So the kernel wants to probe the filesystem on the device, but for that it requires the appropiate module to be loaded. But it is not loaded at that time, so the kernel neither knows what filesystem is on the device and thus does not know what filesystem module to load in the first place.

How does the kernel handle this? I’m thankful for any explanation or even references to the code where this logic happens.

Advertisement

Answer

In short: Unless some user space configuration file is aware of a filesystem, mount will fail to auto-detect this filesystem if its driver is not loaded.

.. usually the kernel tries to probe the different filesystems by calling the appropiate *_fill_super function of the respective module.

This is not quite true. The mount system call accepts filesystem name as a parameter, and this parameter is required for all cases except re-mount, which is out of scope of the current question. Moreover, the filesystem driver is expected to be already loaded at the time mount system call is performed.

That is, the kernel by itself never “probes” a filesystems, the kernel just tries the filesystem requested by the user space.

Actually, it is user space tool mount which performs probing.

Before probing, the mount tool could attempts to deduce a filesystem by inspecting /etc/fstab, by using blkid or other mechanisms.

After all deducing mechanisms have failed, the mount tool probes filesystems according to /etc/filesystems file. This file could contain a predefined (static) list of filesystems.

After attempts for every line in /etc/filesystems have failed (or if the file doesn’t exist), the mount tool probes filesystems listed in /proc/filesystems. This file is provided by the kernel and contains all filesystems which are registered (for which a driver is loaded).

After attempts for every line in /proc/filesystems have failed, the mount tool reports an error.


The algorithm of choosing a filesystem by the mount tool is described in man mount under the paragraph “If no -t option is given ..”. The question and its answers describe similar things.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement