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.
The firs method is to use lsmod command which displays a list of kernel modules that are currently loaded, along with module dependency information.
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.
Given a kernel module X, you can check if what other module(s) that X depends on by running modinfo command.
filename: /lib/modules/2.6.32-5-686/kernel/net/ipv4/netfilter/ip_tables.ko description: IPv4 packet filter author: Netfilter Core Team license: GPL depends: x_tables vermagic: 2.6.32-5-686 SMP mod_unload modversions 686
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 following file. Replace a kernel version number as your own.
. . . . 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 . . . .
Subscribe to Xmodulo
You can have daily Linux tutorials and FAQs delivered to your email inbox. Simply enter your email address below to subscribe to our mailing list. You will receive hands-on guides and carefully written tutorials related to Linux, everything for free.