kernel Modules

  • Modules make it easy to develop drivers without rebooting: load, test, unload, rebuild, load...
  • Useful to keep the kernel image size to the minimum (essential in GNU/Linux distributions for PCs).
  • Also useful to reduce boot time: you don't spend time initializing devices and kernel features that you only need later.
  • Caution: once loaded, have full control and privileges in the system. No particular protection. That's why only the root user can load and unload modules.

Module dependencies

  • Some kernel modules can depend on other modules, which need to be loaded first.
  • Example: the usb-storage module depends on the scsi_mod, libusual and usbcore modules.
  • Dependencies are described both in /lib/modules//modules.dep and in /lib/modules//modules.dep.bin These files are generated when you run make modules_install.

Kernel log

When a new module is loaded, related information is available in the kernel log.

  • The kernel keeps its messages in a circular buffer (so that it doesn't consume more memory with many messages)
  • Kernel log messages are available through the dmesg command (diagnostic message)
  • Kernel log messages are also displayed in the system console (console messages can be filtered by level using the loglevel kernel parameter, or completely disabled with the quiet parameter).
  • Note that you can write to the kernel log from user space too: echo "Debug info" > /dev/kmsg

Module utilities

  • modinfo modinfo .ko Gets information about a module: parameters, license, description and dependencies. Very useful before deciding to load a module or not.

  • sudo insmod .ko Tries to load the given module. The full path to the module object file must be given.

When loading a module fails, insmod often doesn't give you enough details! Details are often available in the kernel log.

  • sudo modprobe Most common usage of modprobe: tries to load all the modules the given module depends on, and then this module. Lots of other options are available. modprobe automatically looks in /lib/modules// for the object file corresponding to the given module name.
  • lsmod Displays the list of loaded modules Compare its output with the contents of /proc/modules!

  • sudo rmmod Tries to remove the given module. Will only be allowed if the module is no longer in use (for example, no more processes opening a device file)

  • sudo modprobe -r Tries to remove the given module and all dependent modules (which are no longer needed after removing the module)

Passing parameters to modules

  • Find available parameters: modinfo snd-intel8x0m
  • Through insmod: sudo insmod ./snd-intel8x0m.ko index=-2
  • Through modprobe: Set parameters in /etc/modprobe.conf or in any file in /etc/modprobe.d/: options snd-intel8x0m index=-2
  • Through the kernel command line, when the driver is built statically into the kernel: snd-intel8x0m.index=-2
    • snd-intel8x0m is the driver name
    • index is the driver parameter name
    • -2 is the driver parameter value

Check module parameter values

How to find the current values for the parameters of a loaded module?

  • Check /sys/module//parameters.
  • There is one file per parameter, containing the parameter value.

results matching ""

    No results matching ""