Linux 如何在运行时获取内核模块的完整依赖列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4073152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get complete dependency list of kernel modules at runtime
提问by Ankur Agarwal
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.
- 我使用以下方法获取所有加载模块的列表
lsmod
- 然后通过运行循环删除/卸载当前加载的内核模块。我正在使用
modprobe -r
. 此步骤失败(显然),因为某些模块正在使用中。(我可以切换到 usingrmmod -r
,但不想这样做,因为它不安全并且会导致系统崩溃。) - 然后我想再一次加载模块。
It is step 2 that is failing, as I cannot get all the module dependencies before using modprobe -r
.
失败的是第 2 步,因为在使用modprobe -r
.
Any ideas, suggestions or comments ?
任何想法、建议或意见?
采纳答案by user502515
However lsmod o/p is sometimes incomplete. It also does not always indicate all the modules dependent on a given module.
然而 lsmod o/p 有时是不完整的。它也不总是指示依赖于给定模块的所有模块。
What you see in lsmod in the "Used by" column are merely the static symbol dependencies that you can also look at using modinfo
.
您在 lsmod 的“Used by”列中看到的仅仅是静态符号依赖项,您也可以使用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.
但是,如果一段内核代码使用 (try_)module_get 引用了一个模块,则不会记录调用者。引用没有所有者(moduleA 可以将指针传递给 moduleB,然后 module_puts 它......),对于 Used by 列没有任何记录。
回答by Paulo Scardine
man lsmod: lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded.
man lsmod:lsmod 是一个简单的程序,它可以很好地格式化 /proc/modules 的内容,显示当前加载了哪些内核模块。
Edited: see also: depmod -n
编辑:另见:depmod -n
回答by ack
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
(即这通常应该是完整列表,但请参阅 user502515 的答案),请使用
$ 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.
请注意,此命令显示的信息比modinfo
的depends:
行多,因为它递归地列出依赖项(即依赖项的依赖项)。它还考虑alias
了 modprobe 配置文件中的命令。
Tested using:
测试使用:
$ modprobe -V
kmod version 14