4.6. Kernel modules

The kernel is capable of loading dynamic portions of code (modules) on demand [Hen], in order to complement its functionality (this possibility is available from kernel version 1.2 and higher). For example, the modules can add support for a file system or for specific hardware devices. When the functionality provided by the module is not necessary, the module can be downloaded, freeing up memory.

On demand, the kernel usually identifies a characteristic not present in the kernel at that moment it makes contact with a thread of the kernel known as kmod (in kernel versions 2.0.x the daemon was called kerneld), this executes a command, modprobe, to try and load the associated module from or of a chain with the name of the module or else from an generic identifier; this information is found in the file /etc/modules.conf in the form of an alias between the name and the identifier.

Next, we search in /lib/modules/version_kernel/modules.dep

to find out whether there are dependencies with other modules. Finally, with the insmod command the module is loaded from /lib/modules/version_kernel/ (the standard directory for modules), the version_kernel is the current version of the kernel using the uname -r command in order to set it. Therefore, the modules in binary form are related to a specific version of the kernel, and are usually located in /lib/modules/version-kernel.

If we need to compile them, we will need to have the sources and/or headers of the version of the core for which it is designed.

Example 4-10. Note

The modules offer the system a large degree of flexibility, allowing it to adapt to dynamic situations.

There are some utilities that allow us to work with modules (they usually appear in a software package called modutils, which was replaced by the module -init-tools for managing modules of the 2.6.x branch):

Example 4-11. Example

Some modules in a Debian distribution:

modprobe: tries the loading of a module and its dependencies.

insmod: loads a specific module.

depmod: analyses dependencies between modules and creates a file of dependencies.

rmmod: removes a module from the kernel.

• Other commands can be used for debugging or analysing modules, like modinfo, which lists some information associated to the module or ksyms, which (only in versions 2.4.x) allows examination of the symbols exported by the modules (also in /proc/ksyms).

In order to load the module the name of the module is usually specified, either by the kernel itself or manually by the user using insmod and specific parameters optionally. For example, in the case of devices, it is usual to specify the addresses of the I/O ports or IRQ or DMA resources. For example:

insmod soundx io = 0x320 irq = 5