How to find information about the kernel modules installed on the system

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL)

Issue

  • How to see all the kernel modules installed on the system?
  • What are the kernel module utilities in Red Hat Enterprise Linux?
  • Where to find additional documentation on kernel modules and their utilities?
  • How to identify tainted third party modules?
  • How to manually load a kernel driver?

Resolution

Installed modules will vary between systems, even for the same version of Red Hat Enterprise Linux.

Many functionalities are implemented as drivers that can be optionally loaded on a system. Some modules are hardware dependent and will not be loaded at all on systems where the hardware is not present.

There are several utilities that will provide information about the modules loaded on a particular system:

List all loaded modules

$ lsmod
Module                  Size  Used by
xt_recent              18500  0
ip6t_rpfilter          12595  1
ipt_REJECT             12541  2
nf_reject_ipv4         13373  1 ipt_REJECT
ip6t_REJECT            12625  2
nf_reject_ipv6         13717  1 ip6t_REJECT
xt_conntrack           12760  11
ip_set_hash_ip         31658  1
ip_set                 45644  1 ip_set_hash_ip
nfnetlink              14490  1 ip_set
ebtable_nat            12807  1
ebtable_broute         12731  1
bridge                151336  1 ebtable_broute
stp                    12976  1 bridge
llc                    14552  2 stp,bridge
ip6table_nat           12864  1
nf_conntrack_ipv6      18935  7
nf_defrag_ipv6         35104  1 nf_conntrack_ipv6
nf_nat_ipv6            14131  1 ip6table_nat
ip6table_mangle        12700  1
ip6table_security      12710  1
ip6table_raw           12683  1
iptable_nat            12875  1
nf_conntrack_ipv4      15053  6
drm                   429744  4 ttm,drm_kms_helper,cirrus
--->8

lsmod formats the contents of /proc/modules. The /proc filesystem has more information on currently loaded modules, how big they are in bytes, and how often they have been loaded:

$ cat /proc/modules
dm_log 18411 2 dm_mirror,dm_region_hash, Live 0xffffffffc0140000
dm_mod 1244407 9 dm_mirror,dm_log, Live 0xffffffffc0120000

RHEL 7: List all modules that are built into the currently running kernel

$ cat /lib/modules/$(uname -r)/modules.builtin
kernel/lib/zlib_deflate/zlib_deflate.ko
kernel/lib/zlib_inflate/zlib_inflate.ko
kernel/lib/crc16.ko
kernel/lib/crc32.ko

Get detailed information about a specific module

$ modinfo drm
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/gpu/drm/drm.ko.xz
license:        GPL and additional rights
description:    DRM shared core routines
author:         Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl
license:        GPL and additional rights
description:    DRM bridge infrastructure
author:         Ajay Kumar <ajaykumar.rs@samsung.com>
retpoline:      Y
rhelversion:    7.6
srcversion:     5A6F52654991123195FEEA7
depends:        drm_panel_orientation_quirks
intree:         Y
vermagic:       3.10.0-957.el7.x86_64 SMP mod_unload modversions
signer:         Red Hat Enterprise Linux kernel signing key
sig_key:        7E:56:0E:30:26:1E:0B:B3:95:B8:94:5E:39:A3:B0:10:E2:B8:74:65
sig_hashalgo:   sha256
parm:           edid_firmware:Do not probe monitor, use specified EDID blob from built-in data or /lib/firmware instead.  (string)
parm:           vblankoffdelay:Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately) (int)
parm:           timestamp_precision_usec:Max. error on timestamps [usecs] (int)
parm:           edid_fixup:Minimum number of valid EDID header bytes (0-8, default 6) (int)
parm:           debug:Enable debug output, where each bit enables a debug category.
                Bit 0 (0x01) will enable CORE messages (drm core code)
                Bit 1 (0x02) will enable DRIVER messages (drm controller code)
                Bit 2 (0x04) will enable KMS messages (modesetting code)
                Bit 3 (0x08) will enable PRIME messages (prime code)
                Bit 4 (0x10) will enable ATOMIC messages (atomic code)
                Bit 5 (0x20) will enable VBL messages (vblank code)
                Bit 7 (0x80) will enable LEASE messages (leasing code) (int)

Starting from RHEL 9, the modinfo tool is able to provide an information on built-in modules too as shown below:

$ modinfo msr
name:           msr
filename:       (builtin)
license:        GPL
file:           arch/x86/kernel/msr
description:    x86 generic MSR driver
author:         H. Peter Anvin <hpa@zytor.com>

Identify tainted modules on the system

In /proc/modules the taint flag will appear next to the module name in parentheses. So we just have to search for the opening (.

$ grep "\(" proc/modules
falcon_lsm_serviceable 87169 1 - Live 0xffffffffc056f000 (PE)
falcon_nf_netcontain 17241 1 - Live 0xffffffffc051e000 (PE)
falcon_lsm_pinned_7602 24347 2 falcon_lsm_serviceable, Live 0xffffffffc0524000 (E)

The meaning of these flags is explained in the article Why is the kernel "tainted" and how are the taint values deciphered?.

Load a module

A kernel module can be loaded with the insmod command, but this is not the recommended practice:

$ insmod hid

Instead, use the modprobe command followed by the kernel module name.

modprobe attempts to load the module from /lib/modules/<kernel-version>/kernel/drivers/. This command will automatically check for module dependencies and load those drivers first before loading the specified module.

$ modprobe hid

Use the -v option for verbose output:

$ modprobe -v hid

/sbin/insmod /lib/modules/2.4.21-1.1931.2.399.ent/kernel/drivers/usb/hid.o
Using /lib/modules/2.4.21-1.1931.2.399.ent/kernel/drivers/usb/hid.o
Symbol version prefix 'smp_'

Unload a module

To unload kernel modules, use the rmmod command followed by the module name:

$ rmmod hid

The rmmod utility will only unload a module that is not in use and that is not a dependency of another active module.

Additional resources.

Detailed information on driver development and module utilities is available from the man pages and the Linux kernel documentation.

Kernel documentation on building out of tree modules

$ man lsmod 

$ man insmod

$ man modprobe

$ man rmmod

$ man modifno

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments