Kernel module files are located in directories such as
/lib/modules/drivers/
/lib/modules/storage/
/lib/modules/fs/
they all have the extension .ko
but how does the kernel understand that a specific module file belongs to a certain type and should be in a certain directory?
1 Answer
The top-level directory for kernel modules is determined by the kernel’s reported version (as shown by uname -r): modules go in /lib/modules/$(uname -r). Modules built alongside the kernel go in a subdirectory of the kernel directory in the top-level directory; modules built later go in a subdirectory of the updates directory.
Inside those directories, kernel modules are installed according to where their source code lives in the tree. Thus all block modules are in the block directory, all fs modules are in the fs directory, etc.
To pick a specific example, /lib/modules/$(uname -r)/kernel/drivers/crypto/padlock-aes.ko is built from drivers/crypto/padlock-aes.c; it’s declared in the relevant Makefile.
Modules are found at installation time by looking for modules.order files which are generated during the build. The implementation lives in scripts/Makefile.modinst.
lsusbandlspci?