How to check kernel module dependencies on Linux

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.

Method One

The firs 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.

Method Two

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/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 

Method Three

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.

$ cat /lib/modules/2.6.32-5-686/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
. . . .

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *