9.4. Kernel Modules

There is a wide variety of PC hardware components. To use this hardware properly, you need a “driver” with which the operating system (in Linux, the kernel) can access this hardware. There are basically two ways of integrating drivers into your system:

Which drivers to compile into the kernel and which to load as runtime modules is defined in the kernel configuration. Basically, components not required for booting the system should be built as modules. This makes sure the kernel does not become too big to be loaded by the BIOS or a boot loader. Drivers for ext2, the SCSI drivers on a SCSI-based system, and similar drivers should be compiled into the kernel. In contrast, items, such as isofs, msdos, or sound, which are not needed for starting your computer system, should definitely be built as modules.

[Tip]Tip

Even drivers that are needed to boot the system may be built as modules. In this case, the initial RAM disk is used to load these modules during boot.

Kernel modules are located in /lib/modules/<version>. version stands for the current kernel version.

9.4.1. Hardware Detection with the Help of hwinfo

hwinfo can detect the hardware of your system and select the drivers needed to run this hardware. Get a small introduction to this command with hwinfo --help. If you, for example, need information about your SCSI devices, use the command hwinfo --scsi. All this information is also available in YaST in the hardware information module.

9.4.2. Handling Modules

The utilities to load modules into the kernel are available in the package module-init-tools. The following commands are available:

insmod

insmod loads the requested module after searching for it in a subdirectory of /lib/modules/<version>. It is better, however, to use modprobe rather than insmod, because modprobe also checks the module for dependencies.

rmmod

Unloads the requested module. This is only possible if this module is no longer needed. For example, the isofs module cannot be unloaded while a CD is still mounted.

depmod

Creates the file modules.dep in /lib/modules/<version> that defines the dependencies of all the modules. This is necessary to ensure that all dependent modules are loaded with the selected ones. This file is built after the system is started if it does not exist.

modprobe

Loads or unloads a given module while taking into account dependencies of this module. This command is extremely powerful and can be used for a lot of things, including probing all modules of a given type until one is successfully loaded. Unlike insmod, modprobe checks /etc/modprobe.conf, making it the preferred method of loading modules. For detailed information about this topic, refer to the corresponding man page.

lsmod

Shows which modules are currently loaded and how many other modules are using them. Modules started by the kernel daemon are tagged with autoclean. This label denotes that these modules will automatically be removed once they reach their idle time limit.

modinfo

Shows module information. Because this information is extracted from the module itself, only the information built in by the driver developers can be displayed. The information may include the author, a description, the license, module parameters, dependencies, and aliases.

9.4.3. /etc/modprobe.conf

The loading of modules is affected by the files /etc/modprobe.conf and /etc/modprobe.conf.local and the directory /etc/modprobe.d. See man modprobe.conf. Parameters for modules that access hardware directly must be entered in this file. Such modules, for example, CD-ROM driver or network driver, may need system-specific options. The parameters used here are described in the kernel sources. Install the package kernel-source and read the documentation in the directory /usr/src/linux/Documentation.

9.4.4. Kmod—the Kernel Module Loader

The kernel module loader is the most elegant way to use modules. Kmod performs background monitoring and makes sure the required modules are loaded by modprobe as soon as the respective functionality is needed in the kernel.

To use Kmod, activate the option Kernel module loader (CONFIG_KMOD) in the kernel configuration. Kmod is not designed to unload modules automatically. In view of today's RAM capacities, the potential memory savings would be marginal.


SUSE LINUX Administration Guide 9.3