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?
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?
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.
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/
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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.