0

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?

3
  • In order to answer your question without more than telling you it's coded that way, and using your own system as an example can you provide the output for lsusb and lspci? Commented May 8, 2024 at 14:21
  • eyoung100, yes, one row from lsusb output Bus 001 Device 005: ID xxxx:xxxx Kingston Technology Company Inc. lspci pcilib: Cannot open /proc/bus/pci lspci: Cannot find any working access method. Commented May 8, 2024 at 15:29
  • I'm just wondering if the type of module is specified when writing it to put it in the right directory? Commented May 8, 2024 at 15:34

1 Answer 1

2

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.