Last updated on August 13, 2020 by Dan Nanni
Similar to software packages, many Linux kernel modules are not self-contained, but rather rely on other modules to load and operate successfully. It is useful to know kernel module dependencies under various circumstances. For example, you may want to know which other modules a particular misbehaving kernel module relies on, so that you can find the root cause of the behavior. In another case, you may want to unload kernel modules which are no longer needed on your system, so that you can minimize the memory footprint of your kernel.
Then how can you check kernel module dependencies in the first place? There are several ways to find kernel module dependency on Linux.
lsmod
The first method is to use lsmod
command which displays a list of kernel modules that are currently loaded, along with module dependency information.
$ lsmod
Module Size Used by iptable_filter 1790 1 ip_tables 7706 1 iptable_filter x_tables 8327 1 ip_tables vmhgfs 41755 0 vsock 30939 0 . . . .
In lsmod
output, kernel dependency information is revealed under "Used by
" column, which indicates the total number of kernel modules and Linux processes that are using a given module. The names of other kernel modules that rely on a given module are listed under that column as well.
However, note that if a kernel module is used by any existing Linux process (not kernel modules), the process name will be omitted in lsmod
output.
For example, in the above sample output, iptable_filter
is used by one (unknown) Linux process, while ip_tables
module is used by one kernel module called iptable_filter
.
modinfo
Given a kernel module X
, you can check if what other module(s) that X
depends on by running modinfo
command.
$ /sbin/modinfo ip_tables
filename: /lib/modules/4.15.0-128-generic/kernel/net/ipv4/netfilter/ip_tables.ko description: IPv4 packet filter author: Netfilter Core Teamlicense: GPL srcversion: DE5BF669F4D356757BF7344 depends: x_tables retpoline: Y intree: Y name: ip_tables vermagic: 4.15.0-128-generic SMP mod_unload
As shown in the above example output, ip_tables
module depends on x_tables
.
modules.dep
If you would like to get a complete list of all existing kernel module dependencies (regardless of whether kernel modules are loaded or not), you can simply check out the modules.dep
file for your kernel. modules.dep
is automatically generated by depmod
tool, and it shows the dependencides for all kernel modules that are found in /lib/modules/$(uname -r)
.
$ cat /lib/modules/$(uname -r)/modules.dep
. . . . kernel/net/ipv4/netfilter/ip_tables.ko: kernel/net/netfilter/x_tables.ko kernel/net/ipv4/netfilter/iptable_filter.ko: kernel/net/ipv4/netfilter/ip_tables.ko kernel/net/netfilter/x_tables.ko kernel/net/ipv4/netfilter/iptable_mangle.ko: kernel/net/ipv4/netfilter/ip_tables.ko kernel/net/netfilter/x_tables.ko kernel/net/ipv4/netfilter/iptable_nat.ko: kernel/net/ipv4/netfilter/ip_tables.ko kernel/net/ipv4/netfilter/nf_nat.ko kernel/net/netfilter/x_tables.ko kernel/net/ipv4/netfilter/nf_conntrack_ipv4.ko kernel/net/netfilter/nf_conntrack.ko kernel/net/ipv4/netfilter/nf_defrag_ipv4.ko . . . .
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean