This is achieved by the Linux kernel using modprobe helper tool. The modprobe tool would take a look at all the dependencies that exists for the current loadable module and inserts all those dependency modules first, prior to the loading of the loadable module. In order to achieve this, the Linux kernel makes use of another tool called the “depmod” tool which auto-generates a file called the “modules.dep” containing a list of all the dependencies for various loadable modules.
The syntax of the modules.dep file is as follows:
(Any blank line or the lines beginning with a # is ignored)
Using this file, the modprobe tool would load each of the dependency modules first, starting from the modules on the right most side in the above line and loading each of the modules while moving to the left. Thus ensuring that all the dependent modules are loaded prior to loading your loadable module file.
Yet another example as seen in the modules.dep man page is listed below:
For example, if /lib/modules/2.6.29/kernel/a.ko depended on b.ko and c.ko in the same directory, and c.ko depended on b.ko as well, the file might look like:
# This is a comment.
/lib/modules/2.6.29/kernel/a.ko: /lib/modules/2.6.29/kernel/c.ko /lib/modules/2.6.29/kernel/b.ko
/lib/modules/2.6.29/kernel/b.ko:
/lib/modules/2.6.29/kernel/c.ko: /lib/modules/2.6.29/kernel/b.ko
Knowing the syntax and the working of this file will be advantageous if you are debugging or hacking your LKM. The most common issue one could see during module insertion that reads:
“insmod: error inserting ‘/lib/xxx.ko’: -1 Unknown symbol in module”
Can be attributed to missing symbols due to module loading dependencies and can be fixed off by adding dependency entries for your module in the modules.dep file.
Post a Comment