In this lesson, you will learn how to orchestrate the Linux kernel's initialization sequence by resolving dependencies and enforcing specific module loading orders.
The Challenge of Module Dependencies
While the Linux kernel is excellent at auto-loading drivers via udev when hardware is detected, complex environments often require a specific sequence of operations. Sometimes, a high-level driver requires a specialized interface provided by a lower-level kernel module that is not automatically triggered. If the dependent module initializes before its prerequisite, the system may fail to initialize the hardware, leading to a "zombie" module or a non-functional device.
Enforcing Order with modprobe.d
The kernel does not inherently "know" the hierarchical requirement between two arbitrary modules unless they have defined symbols exported between them. To enforce a custom loading order, we use configuration files within /etc/modprobe.d/.
You can create a .conf file (e.g., /etc/modprobe.d/custom-order.conf) to use the softdep directive. This tells modprobe that a specific module has a "soft" dependency on another, forcing the loader to handle them in the correct sequence.
# Example: Ensure 'network_driver' loads only after 'custom_bus_module'
softdep network_driver pre: custom_bus_module
In this syntax, pre: tells the loader to insert custom_bus_module into the kernel memory space immediately before network_driver is attempted. Conversely, using post: would ensure the secondary module is loaded only after the primary has finished its initialization routine.
Why Load Order Matters
Beyond simple dependencies, loading order is critical when multiple modules claim the same hardware resource or I/O address. By using softdep, you prevent race conditions where a driver might scan the bus and fail to find the hardware because the infrastructure module is still sitting in the initramfs or the loading queue. Always verify your changes by checking lsmod and inspecting dmesg output to ensure the initialization sequence aligns with your expectations after a reboot.
Key Takeaway: Use the softdep directive in /etc/modprobe.d/ to explicitly define pre- or post-loading requirements, ensuring kernel modules initialize in the correct sequence to prevent hardware access conflicts.