10.8 Working with Loadable Kernel Modules

10.8 Working with Loadable Kernel Modules

Loadable modules are little pieces of kernel code that you can load and unload into the kernel memory space while the kernel is running.

The make modules_install command (discussed in the "Installing Modules" section) installs the kernel module object files in /lib/modules/ ver-sion , where version is your kernel version number. Module object filenames end with .ko in kernel versions 2.6.0 and later, and .o in older releases.

All distributions use modules in some capacity. If you would like to see the modules currently loaded on your system, run this command:


The output should look something like this:

 Module            Size  Used by es1370           24768  0 (autoclean) appletalk        19696  13 (autoclean) 

This output includes es1370 (a sound card driver) and appletalk (a network protocol driver). autoclean means that the kernel may try to automatically unload the module if it is not used for some time.

To load a module, use the modprobe command:

 modprobe  module  

To remove a single module, use the -r option:

 modprobe -r  module  

As mentioned earlier, you can find module dependencies in /lib/modules/ version /modules.dep . Dependencies don't arrive on your system by magic; you must build an explicit list (the kernel module install process usually does this for you). You may need to create module dependencies by hand for all installed kernel versions after installing a module that doesn't come with the kernel. You can do this by running this command:

 depmod -a 

However, this doesn't always work, because depmod may try to read the symbol function memory address locations in the currently running kernel. This won't work if you're trying to build dependencies for kernels other than the one you're running. To zero in on a particular kernel version, find a System.map file that corresponds to that kernel, and then run this command:

 depmod -a -F System.map  version  

As mentioned earlier, though, you do not need to run depmod under normal circumstances, because make modules_install runs it for you.


If you can't find the module that corresponds to a particular feature, go to the feature in the kernel configuration menu and press ? to get the help screen. This usually displays the module name .

10.8.1 Kernel Module Loader

It's inconvenient to manually load a module every time you need to use a particular feature or driver. For example, if you compiled a certain filesystem as a module, it would be too much work to run a modprobe before a mount command that referenced the filesystem.

The Linux kernel provides an automatic module loader that can load most modules without additional modprobe or insmod commands. To use the loader, enable the Kernel module loader option in the kernel configuration. A kernel with the module loader runs modprobe to load modules that it wants.

There are limits to what the module loader can do without additional configuration. In general, it can load most modules that do not involve specific devices. For example, the module loader can load IP tables modules, and it can load filesystem modules as long as you specify the filesystem type with a mount command.

The module loader cannot guess your hardware. For instance, the module loader will not try to figure out what kind of Ethernet card is in your system. Therefore, you need to provide extra hints with the modprobe.conf file.

10.8.2 modprobe Configuration

The modprobe program reads /etc/modprobe.conf for important device information. Most entries are aliases such as this:

 alias eth0 tulip 

Here, the kernel loads the tulip module if you configure the eth0 network interface. In other cases, you may need to specify drivers by their major device numbers , such as this entry for an Adaptec host controller:

 alias block-major-8 aic7xxx 

Wildcards are also possible in modprobe.conf aliases. For example, if all of your Ethernet interface cards use the tulip driver, you can use this line to catch all interfaces:

 alias eth* tulip 

The module utilities discussed here are the ones that go with kernel version 2.6.0. These programs are part of the module-init- utils package. Earlier kernel versions used the modutils package. The most significant difference between the two sets of utilities is that the new package reads modprobe.conf instead of modules.conf . The syntax in both files is very similar.

Chaining Modules and the Install Keyword

You can chain modules together with the install keyword. For example, if SCSI disk support isn't compiled directly into the kernel, you can force it, as in this example for /dev/sda on the Adaptec host controller from the preceding section:

 alias block-major-8 my_scsi_modules install my_scsi_modules /sbin/modprobe sd_mod; /sbin/modprobe aic7xxx 

This works as follows :

  1. A process (or the kernel) tries to access /dev/sda . Assume that this device is not yet mapped to an actual device.

  2. The kernel sees that /dev/sda isn't mapped to its device, which has a block major number of 8. Therefore, the kernel runs this command:

     modprobe block-major-8 
  3. modprobe searches though /etc/modprobe.conf for block-major-8 and finds the alias line.

  4. The alias line says to look for my_scsi_modules , so modprobe runs itself, this time as follows:

     modprobe my_scsi_modules 
  5. The new modprobe sees install my_scsi_modules in modprobe.conf , and then runs the command(s) that follow in the file. In this case, these commands are two additional modprobe commands.

You can include any command that you like in an install line. If you need to debug something or just want to experiment, try adding an echo command.


There is a remove keyword that works like install but runs its command when you remove a module.

Module Options

Kernel modules can take various parameters with the options keyword, as shown in this example for a SoundBlaster 16:

 alias snd-card-0 snd-sb16 options snd-sb16 port=0x220 irq=5 dma8=1 dma16=5 mpu_port=0x330 

How Linux Works
How Linux Works: What Every Superuser Should Know
ISBN: 1593270356
EAN: 2147483647
Year: 2004
Pages: 189
Authors: Brian Ward

Similar book on Amazon

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