Course contentsShow
← Linux
Lesson 320 of 1,8193. The Filesystem Hierarchy and POSIX StandardsFree lesson

Kernel Module Loading and Pathing

Manage the integration of loadable kernel modules within the system's directory structure.

In this lesson, you will learn how the Linux filesystem organizes loadable kernel modules to ensure the system can dynamically extend its functionality without requiring a reboot.

The Home of Kernel Modules

While the core Linux kernel is a single monolithic binary, it is designed to be modular. Drivers for hardware, filesystems, and network protocols are often compiled as "Loadable Kernel Modules" (LKMs). These modules reside in a highly structured location within your filesystem hierarchy: /lib/modules/$(uname -r)/.

The path is version-specific because a module compiled for one kernel version is rarely binary-compatible with another. When you execute a command like modprobe, the system uses this path to locate the .ko (Kernel Object) files.

Understanding Module Pathing

The directory structure under /lib/modules/ mirrors the categories of kernel functionality. For example:

  • kernel/drivers/: Contains hardware-specific modules (e.g., net, gpu, usb).
  • kernel/fs/: Contains filesystem support (e.g., ext4, xfs, vfat).

When the system needs to resolve a module, it consults the modules.dep file, which is also located in that directory. This file maps module names to their absolute file paths and defines the dependency tree. If you load a module that requires another, the kernel uses these paths to load the prerequisites first, maintaining the stability of the kernel environment.

Managing Integration

Integration is managed through the kmod tools. Because these modules are effectively "plug-ins" for the kernel, they follow strict pathing conventions to avoid naming collisions and version mismatches.

# View the location of a currently loaded module's file
modinfo -n e1000e

# Output typically looks like:
# /lib/modules/5.15.0-generic/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko

By placing modules in a standardized path, the system ensures that the kernel can safely map these binary blobs into its own memory space during operation. This mechanism allows you to add features like a new encrypted filesystem or a specialized network bridge while the system remains fully operational.

Key Takeaway: Kernel modules are stored in versioned subdirectories under /lib/modules/ to ensure the kernel dynamically loads only the binary-compatible drivers required for your specific hardware and software configuration.