What's the difference between insmod and modprobe?
Asked Answered
B

5

26

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?

Broad answered 6/4, 2014 at 8:33 Comment(1)
Get the best solution from ask ubuntuCarrigan
P
32

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.

Pyroelectricity answered 6/4, 2014 at 8:44 Comment(0)
B
2

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/

Bonnie answered 28/11, 2016 at 16:19 Comment(0)
A
2

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.

Atonement answered 7/4, 2017 at 9:49 Comment(0)
B
1

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.

Bobseine answered 6/4, 2014 at 8:42 Comment(0)
N
0

modprobe and insmod:

During development, one usually uses insmod in order to load a module, It is low-level form of module loading and it should be given the path of the module to load:

 insmod /path/to/mydrv.ko

On the other hand, there is modprobe, mostly used by sysadmin or in a production system. modprobe is a clever command that parses the file "modules.dep" in order to load dependencies first, prior to loading the given module. It automatically handles module dependencies, as a package manager does:

  modprobe mydrv

Whether one can use modprobe or not depends on depmod being aware of module installation.

If you want some module to be loaded at boot time, just create the file /etc/modules- load.d/.conf, and add the module's name that should be loaded, one per line. should be meaningful to you, and people usually use module:/etc/modules-load.d/modules.conf. You may create as many .conf files as you need.

Nealon answered 11/9, 2023 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.