Wednesday, February 04, 2015

Linux modprobe vs insmod

OS: Red Hat Enterprise Linux Server release 6.4

Confused about modprobe and insmod?

First of all, the "man" page tells us:
  • modprobe - program to add and remove modules from the Linux Kernel
  • insmod - simple program to insert a module into the Linux Kernel
So "insmod" is just a trivial program to insert a module into the kernel, and only the most general of eroor messages are reported. It has no options, no diagnostic feedback, you will have to use "dmesg" to get more information.

"modeprobe" is much more sophisticated, it has many options, can insert/remove modules from the kernel. It can also find module dependencies.

Differences:

    - "modprobe" calculates all of the module dependencies and then load the module along with the dependencies, while "insmod" does not care, it only loads the module. The scene behind the calculation is the "/lib/modules/`uname -r`/modules.dep" file. This file is generated by "depmod" command when system is booted or when you run "depmod -a". An example, module1 depends on module2 and module3, in "modules.dep" file you will see module1: module2 module3. "modprobe" reads modules.dep file.

    - "modprobe" only deals with modules in /lib/modules/`uname -r`. So if you want to load an external module, you have to create a soft link from /path/to/module.ko to /lib/modules/`uname -r`/, for example:
# ln -s /path/to/module.ko /lib/modules/`uname -r`
# depmod -a

No comments: