Chapter 31. Kernel Modules

The Linux kernel has a modular design. At boot time, only a minimal resident kernel is loaded into memory. Thereafter, whenever a user requests a feature that is not present in the resident kernel, a kernel module, sometimes referred to as a driver, is dynamically loaded into memory.

During installation, the hardware on the system is probed. Based on this probing and the information provided by the user, the installation program decides which modules need to be loaded at boot time. The installation program sets up the dynamic loading mechanism to work transparently.

If new hardware is added after installation and the hardware requires a kernel module, the system must be configured to load the proper kernel module for the new hardware. When the system is booted with the new hardware, the Kudzu program runs, detects the new hardware if it is supported, and configures the module for it. The module can also be specified manually by editing the module configuration file, /etc/modules.conf.

NoteNote
 

Video card modules used to display the X Window System interface are part of the XFree86 package, not the kernel; thus, this chapter does not apply to them.

For example, if a system included an SMC EtherPower 10 PCI network adapter, the module configuration file contains the following line:

alias eth0 tulip

If a second network card is added to the system and is identical to the first card, add the following line to /etc/modules.conf:

alias eth1 tulip

See the Red Hat Linux Reference Guide for an alphabetical list of kernel modules and the hardware supported by the modules.

31.1. Kernel Module Utilities

A group of commands for managing kernel modules is available if the modutils package is installed. Use these commands to determine if a module has been loaded successfully or when trying different modules for a piece of new hardware.

The command /sbin/lsmod displays a list of currently loaded modules. For example:

Module                  Size  Used by    Not tainted
iptable_filter          2412   0 (autoclean) (unused)
ip_tables              15864   1 [iptable_filter]
nfs                    84632   1 (autoclean)
lockd                  59536   1 (autoclean) [nfs]
sunrpc                 87452   1 (autoclean) [nfs lockd]
soundcore               7044   0 (autoclean)
ide-cd                 35836   0 (autoclean)
cdrom                  34144   0 (autoclean) [ide-cd]
parport_pc             19204   1 (autoclean)
lp                      9188   0 (autoclean)
parport                39072   1 (autoclean) [parport_pc lp]
autofs                 13692   0 (autoclean) (unused)
e100                   62148   1
microcode               5184   0 (autoclean)
keybdev                 2976   0 (unused)
mousedev                5656   1
hid                    22308   0 (unused)
input                   6208   0 [keybdev mousedev hid]
usb-uhci               27468   0 (unused)
usbcore                82752   1 [hid usb-uhci]
ext3                   91464   2
jbd                    56336   2 [ext3]

For each line, the first column is the name of the module, the second column is the size of the module, and the third column is the use count.

The information after the use count varies slightly per module. If (unused) is listed on the line for the module, the module is currently not being used. If (autoclean) is on the line for the module, the module can be autocleaned by the rmmod -a command. When this command is executed, any modules that are tagged with autoclean, that have not been used since the previous autoclean action, are unloaded. Red Hat Linux does not perform this autoclean action by default.

If a module name is listed at the end of the line in brackets, the module in the brackets is dependent on the module listed in the first column of the line. For example, in the line

usbcore                82752   1 [hid usb-uhci]

the hid and usb-uhci kernel modules depend on the usbcore module.

The /sbin/lsmod output is the same as the output from viewing /proc/modules.

To load a kernel module, use the /sbin/modprobe command followed by the kernel module name. By default, modprobe attempts to load the module from the /lib/modules/<kernel-version>/kernel/drivers/ subdirectories. There is a subdirectory for each type of module, such as the net/ subdirectory for network interface drivers. Some kernel modules have module dependencies, meaning that other modules must be loaded first for it to load. The /sbin/modprobe command checks for these dependencies and loads the module dependencies before loading the specified module.

For example, the command

/sbin/modprobe hid

loads any module dependencies and then the hid module.

To print to the screen all commands as /sbin/modprobe executes them, use the -v option. For example:

/sbin/modprobe -v hid

Output similar to the following is displayed:

/sbin/insmod /lib/modules/2.4.20-2.47.1/kernel/drivers/usb/hid.o
Using /lib/modules/2.4.20-2.47.1/kernel/drivers/usb/hid.o
Symbol version prefix 'smp_'

The /sbin/insmod command also exists to load kernel modules; however, it does not resolve dependencies. Thus, it is recommended that the /sbin/modprobe command be used.

To unload kernel modules, use the /sbin/rmmod command followed by the module name. The rmmod utility only unloads modules that are not in use and that are not a dependency of other modules in use.

For example, the command

/sbin/rmmod hid

unloads the hid kernel module.

Another useful kernel module utility is modinfo. Use the command /sbin/modinfo to display information about a kernel module. The general syntax is:

/sbin/modinfo [options] <module>

Options include -d which displays a brief description of the module and -p which lists the parameters the module supports. For a complete list of options, refer to the modinfo man page (man modinfo).