How to get complete dependency list of kernel modules at runtime
-
28-09-2019 - |
Question
Is there a way to list down from command line the complete dependency list of kernel modules loaded in the kernel at runtime?
Let me clarify my question a little bit.
What I am trying to do:
- I get a list of all loaded modules using
lsmod
- Then remove/unload currently loaded kernel modules by running a loop. I am using
modprobe -r
. This step fails (obviously) as some modules are in use. (I can switch to usingrmmod -r
, but don't want to as it is unsafe and can crash the system.) - Then I want to load the modules one by one again.
It is step 2 that is failing, as I cannot get all the module dependencies before using modprobe -r
.
Any ideas, suggestions or comments ?
Solution
However lsmod o/p is sometimes incomplete. It also does not always indicate all the modules dependent on a given module.
What you see in lsmod in the "Used by" column are merely the static symbol dependencies that you can also look at using modinfo
.
If however a piece of kernel code takes a reference on a module using (try_)module_get, the caller will not be recorded. References do not have an owner (moduleA could pass the pointer to moduleB, which then module_puts it..), there is nothing to record for the Used by column.
OTHER TIPS
To get a list of module dependencies as would be used by modprobe
(i.e. this should normally be the full list, but see the answer by user502515), use
$ modprobe --show-depends <module>
Note that this command shows more information than modinfo
's depends:
line, as it lists dependencies recursively (i.e. dependencies of dependencies).
It also takes into account alias
commands in modprobe configuration files.
Tested using:
$ modprobe -V
kmod version 14
man lsmod: lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded.
Edited: see also: depmod -n