14
votes

I know insmod and modprobe are used to insert module into the kernel. But, what's the difference between them?

And, why is it dangerous to insert modules with force option in modprobe?

4
Get the best solution from ask ubuntuMD SHAYON

4 Answers

23
votes

modprobe is the intelligent version of insmod. insmod simply adds a module where modprobe looks for any dependency (if that particular module is dependent on any other module) and loads them.

Regarding --force option, here is the quote from the man page:

   Try to strip any versioning information from the module which might otherwise
   stop it from loading: this is the same as using both --force-vermagic and
   --force-modversion. Naturally, these checks are there for your protection,
   so using this option is dangerous unless you know what you are doing.

Which indicates it's been used to skip the kernel module version checking. Shouldn't be any problem if you do your own kernel module or from any trusted party. But you should know what you are doing.

1
votes

If you trust the Linux man pages isnmod.

Most users will want to use modprobe instead, which is more clever and can handle module dependencies.

1
votes

insmod: Used to load a module
modprobe: Much same way as insmod, but also loads any other modules that are required by the module that you want to load.
Although you’ll still need insmod when loading your own modules from the current directory, because modprobe looks only in the standard installed module directories.
Reference:https://lwn.net/Kernel/LDD3/

0
votes

modprobe is looks for dependencies while loading a module. Suppose, if I loaded a module, which has symbols defined in some other module (this module path is given inside the main module). So, modprobe loads the main module and the dependent module.

But in case if you are using insmod to loading , it won't load the dependency, and hence it will give compilation errors like Unresolved symbols. In this case, we have to manually look for dependent module and need to load them in order to resolve the errors.