52

While I can use lsmod in order to show currently active kernel modules, how can I see which drivers are statically built into the kernel AND currently active?

0

5 Answers 5

51

You could do a cat /lib/modules/$(uname -r)/modules.builtin

From the Kernel Documentaton

modules.builtin

This file lists all modules that are built into the kernel. This is used by modprobe to not fail when trying to load something builtin.

2
  • 1
    modules.builtin does not exist in my system with uname: Linux ecp 4.4.127-1.el6.elrepo.i686 #1 SMP Sun Apr 8 09:44:43 EDT 2018 i686 i686 i386 GNU/Linux. Is there another way to find what drivers are built in?
    – Danny
    Commented Jul 15, 2019 at 5:39
  • 1
    @Danny Make sure you use uname -r and not the more common uname -a
    – Nairou
    Commented Jul 22, 2019 at 2:16
11

If your linux has a /proc/config.gz

That has all the built modules. Copy it elsewhere and unzip it. Open the file everything with a "=M" is built as a module. Everything with a "=Y" is statically built.

hwinfo will list the "Driver:" check the above file to see if it is statically built.

FYI: All statically built drivers are always loaded into memory and ready for action. Without the corresponding hardware they will not do anything, but use memory.

4
  • 1
    What if there is no /proc/config.gz? Commented Apr 5, 2013 at 13:25
  • Ok I just found a .config file in the directory where I compiled the kernel, that's obviously what you meant. Commented Apr 5, 2013 at 13:51
  • 2
    This file also exists here: /boot/config-$(uname -r). Commented Apr 5, 2013 at 13:58
  • no need to unzip if you just want to see. Just zcat /boot/config-$(uname -r) or zcat /proc/config.gz. You can also use zgrep or zmore
    – phuclv
    Commented May 25, 2023 at 2:07
7

The sysfs module area /sys/module is a view into all the modules visible to the running kernel. Each module directory has a set of sysfs interface files to view and manage the module via userspace. Generally speaking, the LKMs have a refcnt file, which will be greater than 0 if it is being used along with a holder directory of those modules using it. The builtin modules do not have this file (or many others like initstate and taint.)

Try find /sys/module -name refcnt -printf '\n%p: ' -exec cat {} \; to see which are being used.

Under many modules is a parameters directory containing the parameters that can be viewed and modified from user-space. In the source this is generally a call to a module_param macro. For example, see kernel/printk.c and the module /sys/module/printk/parameters for some useful printk tuning.

All entities under /sys/module are set in the kernel module framework. Some are hardware drivers, some are netfilter, some are filesystems, some debug, etc.

4
ls /sys/module

seems to contain all built-in and external modules.

But it also appears to contain some entries which are not actually modules: https://unix.stackexchange.com/questions/225706/are-modules-listed-under-sys-module-all-the-loaded-modules

TODO: read the source and understand more precisely what gets put there.

The advantage of this method is that you don't rely on being able to find the kernel config under /boot or /proc/config.gz.

0

I was about to comment on cybernard response, but without reputation on this specific StackExchange service I can't.

To quickly check /proc/config.gz against some specific module, you don't need to unzip it anywhere (useful when you don't want to write to any partition of your device):

$ gunzip -c /proc/config.gz | grep 8021Q
CONFIG_VLAN_8021Q=y
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .