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 is dynamically loaded into memory. After a specified period of inactivity, the module may be removed from memory.

The mechanism that supports dynamic loading of modules is a kernel thread called kmod. Modules are not loaded unless they are needed. When the kernel requests a module, the module is loaded along with all its module dependencies. Red Hat Linux also includes a cron task that removes all unused modules every ten minutes. The cron task is located in the file /etc/cron.d/kmod.

When you install Red Hat Linux, the hardware on your system is probed and you provide information about how the system will typically be used and which programs should be loaded. Based on this probing and the information you provide, 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 you build your own custom kernel, you can make all of these decisions for yourself.

If you add new hardware after installation and the hardware requires a kernel module, you need to set up the dynamic loading mechanism. Kudzu runs when the system boots and usually detects new hardware. You can also add the new driver by editing the module configuration file, /etc/modules.conf.

For example, if your system included a model SMC EtherPower 10 PCI network adapter at the time of installation, the module configuration file will contain the following line:

alias etho0 tulip

After installation, if you install a second, identical network adapter on your system, add the following line to /etc/modules.conf:

alias eth1 tulip

Kernel Module Utilities

You can also use a group of commands to list, load, or unload kernel modules. These commands are useful if you want to try different modules or see if a module has been loaded successfully. The command /sbin/lsmod displays a list of currently loaded modules, as shown in Listing 12-1.

Listing 12-1: Sample lsmod output

start example
Module               Size      Used by sr_mod              15264        0 (autoclean) mga                 95984        1 agpgart             23392        3 nfs                 79008        1 (autoclean) lockd               52464        1 (autoclean) [nfs] sunrpc              61328        1 (autoclean) [nfs lockd] autofs              11264        4 (autoclean) 3c59x               25344        1 (autoclean) ipchains            38976        0 (unused) ide-scsi             8352        0 scsi_mod            95104        2 [sr_mod ide-scsi] ide-cd              26848        0 cdrom               27232        0 [sr_mod ide-cd] usb-uhci            20720        0 (unused) usbcore             49664        1 [usb-uhci]
end example

As you can see in this example, lsmod displays the size, use count, and referring modules for each module currently loaded.

To load a kernel module, you can use the command /sbin/insmod followed by the kernel module name. By default, insmod tries 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 before the dependent module can be loaded. To resolve these dependencies, you can either load the module dependencies and then load the module you want, or you can use the command /sbin/modprobe followed by the module name to load the desired module along with its dependencies.

For example, the command

/sbin/modprobe tulip

loads the tulip network interface mdoule.

Another useful kernel module utility is modinfo. You can 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 that the module supports. For a complete list of options, refer to the modinfo man page by typing man modinfo.




Official Red Hat Linux Administrator's Guide
Official Red Hat Linux Administrators Guide
ISBN: 0764516957
EAN: 2147483647
Year: 2002
Pages: 278
Authors: Red Hat Inc

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net