I'm wondering if I can use the directory listing of /sys/module
instead of lsmod to get a list of currently loaded modules.
Is that the list of loaded modules only? Or maybe that combined with /sys/module/*/initstate
?
I'm wondering if I can use the directory listing of /sys/module
instead of lsmod to get a list of currently loaded modules.
Is that the list of loaded modules only? Or maybe that combined with /sys/module/*/initstate
?
Each loaded module has an entry in /sys/module
. But there are also kernel components with an entry in /sys/module
that are not loaded as modules. Each kernel component¹ that can be built as a module has an entry in /sys/module
, whether it is compiled and loaded as a module or compiled as part of the main kernel image.
lsmod
gets the list of loaded modules from /proc/modules
.
I think that only loaded modules have an initstate
file in their /sys/module
directory, so you can use that too.
¹ That's each component of the loaded kernel. The kernel doesn't know or care what modules you may have in files on your hard disk. The kernel doesn't care what modules were built at the same time of the kernel image, either; it may show that via /proc/config
but it doesn't use that information for anything.
lsmod | wc -l
=> 116.ls /sys/module | wc -l
= >201.grep '=m' /boot/config-$(uname -r)
=> 4934. – el_tigro Feb 25 '19 at 17:30grep '=y' /boot/config-$(uname -r) | wc -l
=> 2389. Out of all 2389 components statically compiled into the kernel, only 201-116=85 of them could have been compiled/loaded as modules. 2389-85=2304 could not be loaded as modules (therefore they can only be set toy
orn
in the config file). Does this make sense? – el_tigro Feb 25 '19 at 18:15y
, not all of which are components (some are yes/no settings but not a distinct component). You have 4934 components available as modules. You have 116 loaded modules, and 201-116=85 components that could be loaded as modules, but are built in. – Gilles 'SO- stop being evil' Feb 25 '19 at 18:41y
how would I go about determining which are components vs simple yes/no settings. 2) For each options set tom
, there is one corresponding ".ko" file that is built (stored at /lib /modules/$(uname -r) on my system) 3) Even if a component is set ton
at build time, it is possible to load that component as a module if you obtain the ".ko" file. – el_tigro Feb 25 '19 at 19:07Kconfig
files in the kernel source (either directly or via a kernel configuration tool). 2) Yes. 3) Yes (but you'd need to have a compatible.ko
file, which is hard to ensure unless the file was built from the same kernel version with the same options). – Gilles 'SO- stop being evil' Feb 25 '19 at 19:31/sys/modules
. On Ubuntu 20.04,ext4
is builtin and there is no corresponding/sys/module/ext4
. – Melab Sep 17 '20 at 03:36/sys/module/ext4
. – Gilles 'SO- stop being evil' Sep 17 '20 at 08:27