2

I apologize if the query is too simple. But I want to ask is there a difference between linux system modules and linux kernel modules. If there is a difference then where are both located. Is it that /lib/module/$(uname -r) shows kernel modules and /sys/module/ shows system modules

4
  • Thanks for the edit, would be helpful if you can help me with the solution . Its my first moth working on Linux machines :) – Raghav Chadha Sep 23 '15 at 8:16
  • I was just writing an answer :) – dave_alcarin Sep 23 '15 at 8:23
  • lol, thanks for the ans. So in nut shell system and kernel modules are the same thing right ? – Raghav Chadha Sep 23 '15 at 8:25
  • AFAIK Yes, when speaking about "modules" in Linux, it generally refers to "kernel modules". In a nutshell /sys/module shows all modules by name, /lib/module/$(uname -r) has all the modules' file organized by function. Please, don't forget to vote/accept answers if they solved your question ;) – dave_alcarin Sep 23 '15 at 8:30
1

The directory /sys/module/ shows all modules in the system by their name as folders with diverse information needed by the system. The directory /lib/module/$(uname -r) contains the kernel module files, stored in a folder hierarchy according to their function.

For example, the Software Watchdog kernel module file would be in /lib/module/$(uname -r)/kernel/drivers/watchdog/softdog.ko. On the other hand, this module has its own "softdog" (the module name) directory in /sys/module/ with information used by the system when operating/inserting this module, but not the file of the module itself.

You can operate modules by name with modprobe [args] <module-name> [module-params]

You can operate modules by path to the .ko file with insmod [args] <path> [module-params].

Mind that operating kernel modules requires root privileges.

2

/lib/module/$(uname -r) is a directory on your disk¹. It contains files, most of which (*.ko) are module files: files that contain the code of a kernel module. The files in this directory (and its subdirectories) contain, in principle, modules that you can load into your running kernel.

/sys/module is a directory on a virtual filesystem that exposes kernel internals. Accessing a file in that directory invokes a function in the kernel which only looks at some internal kernel data structures, it doesn't go any further to a disk layer. Each entry in /sys/module corresponds to a component of the running kernel, with code that's loaded in memory and active. This includes all loaded modules, but also components that could be loaded as a module but were built directly into the kernel when the kernel was compiled.

Having files in /lib/module/$(uname -r) that don't correspond to an entry in /sys/module is very common: they're drivers for some piece of hardware (or other thing managed by the kernel) that you don't have in your computer. Entries in /sys/module with no corresponding file under /lib/module/$(uname -r) happen when the component was built into the kernel (here's how to tell), or if the module was loaded manually from a file that's located elsewhere (or is now deleted).

¹ Or rarely on something other than a disk, if your system keeps its root filesystem elsewhere, e.g. over the network or in a RAM disk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.