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
?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityEach 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.
y
, 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.
Feb 25, 2019 at 18:41
Kconfig
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).
Feb 25, 2019 at 19:31