10

Why do these two commands return different results?

lsmod | wc -l
100

ls /sys/module | wc -l
138
HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
andy
  • 101
  • 2

2 Answers2

13

lsmod lists all of your dynamic modules that are loaded.

The entries in /sys/module correspond to dynamic modules and modules which are built into the kernel (and have parameters that need to be accessible) rather than loaded dynamically. For example:

[michael@brazzers:~]$ ls -d /sys/module/ip_tables/
/sys/module/ip_tables/
[michael@brazzers:~]$ lsmod |grep ^ip_tables
ip_tables              26995  3 iptable_filter,iptable_mangle,iptable_nat
[michael@brazzers:~]$ grep CONFIG_NF_NAT_IPV4 /boot/config-3.8.0-30-generic
CONFIG_NF_NAT_IPV4=m

You can see here that the iptables module is configured as a dynamic module. Contrast to:

[michael@brazzers:~]$ ls -d /sys/module/apparmor/
/sys/module/apparmor/
[michael@brazzers:~]$ lsmod |grep ^apparmor
[michael@brazzers:~]$ grep APPARMOR /boot/config-3.8.0-30-generic 
CONFIG_SECURITY_APPARMOR=y

whereas apparmor is built-in.

MikeyB
  • 39,291
  • 10
  • 105
  • 189
  • @MikeB when you see CONFIG_X_X=yes i think that means the code is builting in the kernel not as dinamic module: Example grep EXT4 /boot/config-3.6.11-4.fc16.i686 CONFIG_EXT4_FS=y modinfo ext4 ERROR: Module ext4 not found ls -l /sys/module/ext4 ls: cannot access /sys/module/ext4: No such file or directory – c4f4t0r Sep 19 '13 at 18:15
  • Yes, it looks as though built-in modules [need to have parameters](http://linux-kernel.2935.n7.nabble.com/What-is-listed-in-sys-module-td657227.html) for them to be visible. – MikeyB Sep 19 '13 at 18:48
5
  • /sys/module/MODULENAME

MODULENAME is the name of the module that is in the kernel. This module name will always show up if the module is loaded as a dynamic module. This is exactly what you can see when you issue lsmod command or when you check /proc/modules file.

If it is built directly into the kernel it will only show up if it has a version or at least one parameter. The available parameters are then available in the directory:

  • /sys/module/MODULENAME/parameters
dsmsk80
  • 5,817
  • 18
  • 22