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?
5 Answers
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.
-
1modules.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?– DannyCommented Jul 15, 2019 at 5:39
-
1@Danny Make sure you use
uname -r
and not the more commonuname -a
– NairouCommented Jul 22, 2019 at 2:16
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.
-
1
-
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
-
no need to unzip if you just want to see. Just
zcat /boot/config-$(uname -r)
orzcat /proc/config.gz
. You can also usezgrep
orzmore
– phuclvCommented May 25, 2023 at 2:07
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.
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
.
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
-
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Nov 22, 2021 at 22:42
-
no need to gunzip. Just
zgrep 8021Q /proc/config.gz
is enough– phuclvCommented May 25, 2023 at 2:12