< Day Day Up > |
The Linux kernel employs the use of modules to support different operating system features, including support for various devices such as sound and network cards. In many cases, you do have the option of implementing support for a device either as a module or by directly compiling it as a built-in kernel feature, which requires you to rebuild the kernel (see Chapter 33). A safer and more robust solution is to use modules. Modules are components of the Linux kernel that can be loaded as needed. To add support for a new device, you can now simply instruct a kernel to load the module for that device. In some cases, you may have to recompile only that module to provide support for your device. The use of modules has the added advantage of reducing the size of the kernel program as well as making your system more stable. The kernel can load modules in memory only as they are needed. Should a module fail, only the module stops running, and it will not affect the entire system. For example, the module for the PPP network interface used for a modem needs to be used only when you connect to an ISP.
The modules your system needs are usually determined during installation, based on the kind of configuration information you provided and the automatic detection performed by Kudzu. For example, if your system uses an Ethernet card whose type you specified during installation, the system loads the module for that card. You can, however, manually control what modules are to be loaded for your system. In effect, this enables you to customize your kernel whatever way you want. You can use several commands, configuration tools, and daemons to manage kernel modules. The 2.4 Linux kernel includes the Kernel Module Loader (Kmod), which has the capability to load modules automatically as they are needed. Kernel module loading support must also be enabled in the kernel, though this is usually considered part of a standard configuration and is included with Red Hat distributions. In addition, several tools enable you to load and unload modules manually, if you must. The Kernel Module Loader uses certain kernel commands to perform the task of loading or unloading modules. The modprobe command is a general-purpose command that calls insmod to load modules and rmmod to unload them. These commands are listed in Table 32-5. Options for particular modules, general configuration, and even specific module loading can specified in the /etc/modules.conf file. You can use this file to automatically load and configure modules. You can also specify modules to be loaded at the boot prompt or in grub.conf (see Chapter 27).
Device Name |
Type of Device |
---|---|
/dev/video |
Video capture interface |
/dev/vfx |
Video effects interface |
/dev/codec |
Video codec interface |
/dev/vout |
Video output interface |
/dev/radio |
AM/FM radio devices |
/dev/vtx |
Teletext interface chips |
/dev/vbi |
Data services interface |
The filename for a module has the extension .o. Kernel modules reside in the /lib/modules/version directory, where version is the version number for your current kernel. The directory for the 2.4.22-1 kernel is /lib/modules/2.4.22-1. As you install new kernels on your system, new module directories are generated for them. One method to access the directory for the current kernel is to use the uname -r command to generate the kernel version number. This command needs to have backquotes.
cd /lib/modules/`uname -r`
In this directory, modules for the kernel reside in the /kernel directory. Within the /kernel directory are several subdirectories, including the /drivers directory that holds subdirectories for modules like the sound drivers or video drivers. These subdirectories serve to categorize your modules, making them easier to locate. For example, the kernel/drivers/net directory holds modules for your Ethernet cards, and the kernel/drivers/sound directory contains sound card modules.
Command |
Description |
---|---|
lsmod |
Lists modules currently loaded. |
insmod |
Loads a module into the kernel. Does not check for dependencies. |
rmmod |
Unloads a module currently loaded. Does not check for dependencies. |
modinfo |
Display information about a module: -a (author),-d (description), -p (module parameters), -f (module filename), -v (module version). |
depmod |
Creates a dependency file listing all other modules on which the specified module may rely. |
modprobe |
Loads a module with any dependent modules it may also need. Uses the file of dependency listings generated by depmod: -r (unload a module), -l (list modules) |
As noted previously, there are several commands you can use to manage modules. The lsmod command lists the modules currently loaded into your kernel, and modinfo provides information about particular modules. Though you can use the insmod and rmmod commands to load or unload modules directly, you should use only modprobe for these tasks. (See Table 33-5 for kernel module commands.) Often, however, a given module requires other modules to be loaded. For example, the module for the Sound Blaster sound card, sb.o, requires the sound.o module to be loaded also.
Instead of manually trying to determine what modules a given module depends on, you use the depmod command to detect the dependencies for you. The depmod command generates a file that lists all the modules on which a given module depends. The depmod command generates a hierarchical listing, noting what modules should be loaded first and in what order. Then, to load the module, you use the modprobe command using that file. modprobe reads the file generated by depmod and loads any dependent modules in the correct order, along with the module you want. You need to execute depmod with the -a option once, before you ever use modprobe. Entering depmod -a creates a complete listing of all module dependencies. This command creates a file called modules.dep in the module directory for your current kernel version, /lib/modules/version.
depmod -a
To install a module manually, you use the modprobe command and the module name. You can add any parameters the module may require. The following command installs the Sound Blaster sound module with the I/O, IRQ, and DMA values. modprobe also supports the use of the * character to enable you to use a pattern to select several modules. This example uses several values commonly used for sound cards. You would use the values recommended for your sound card on your system.
modprobe sb io=0x220 irq=5 dma=1
To discover what parameters a module takes, you can use the modinfo command with the -p option.
modinfo -p sb
You can use the -l option to list modules and the -t option to look for modules in a specified subdirectory. In the next example, the user lists all modules in the sound directory:
# modprobe -l -t sound /lib/modules/2.4.22-1/kernel/drivers/sound/sb.o /lib/modules/2.4.22-1/kernel/drivers/sound/sb_lib.o /lib/modules/2.4.22-1/kernel/drivers/sound/sound.o /lib/modules/2.4.22-1/kernel/drivers/sound/soundcore.o
Options for the modprobe command are placed in the /etc/modules.conf file. Here, you can enter configuration options, such as default directories and aliases. An alias provides a simple name for a module. For example, the following entry enables you to reference the 3c59x.o Ethernet card module as eth0 (Kmod automatically detects the 3Com Ethernet card and loads the 3c59x module):
alias eth0 3c59x
The insmod command performs the actual loading of modules. Both modprobe and the Kernel Module Loader make use of this command to load modules. Though modprobe is preferred, because it checks for dependencies, you can load or unload particular modules individually with insmod and rmmod commands. The insmod command takes as its argument the name of the module, as does rmmod. The name can be the simple base name, like sb for the sb.o module. You can specify the complete module file name using the -o option. Other helpful options are the -p option, which lets you probe your system first to see if the module can be successfully loaded, and the -n option, which performs all tasks except actually loading the module (a dummy run). The -v option (verbose) lists all actions taken as they occur. In those rare cases where you may have to force a module to load, you can use the -f option. In the next example, insmod loads the sb.o module.
# insmod -v sb
The rmmod command performs the actual unloading of modules. It is the command used by modprobe and the Kernel Module Loader to unload modules. You can use the rmmod command to remove a particular module as long as it is not being used or required by other modules. You can remove a module and all its dependent modules by using the -r option. The -a option removes all unused modules. With the -e option, when rmmod unloads a module, it saves any persistent data (parameters) in the persistent data directory, usually /var/lib/modules/persist.
Notice that there is no device name for Ethernet devices in the /dev directory. This is because the device name is really an alias for a Ethernet network module that has been defined in the modules.conf file. If you were to add another Ethernet card of the same type, you would place an alias for it in the modules.conf file. For a second Ethernet card, you would use the device name eth1 as the alias. This way, the second Ethernet device can be referenced with the name eth1. A modules.conf entry is shown here:
alias eth1 ne2k-pci
Tip |
After making changes to /etc/modules.conf, you should run depmod again to record any changes in module dependencies. |
The preceding entry assumes that the Ethernet card was of the same model. If you had added a different model Ethernet card, you would have to specify the module used for that kind of card. In the following example, the second card is a standard PCI Realtek card. Kmod has already automatically detected the new card and loaded the ne2k-pci module for you. You only need to identify this as the eth1 card in the /etc/modules.conf file.
alias eth0 3c59x alias eth1 ne2k-pci
A sample modules.conf file is shown here. Notice the aliases for the USB controller and the sound card.
alias eth0 3c59x alias eth1 ne2k-pci alias parport_lowlevel parport_pc alias usb-controller usb-uhci alias sound-slot-0 i810_audio
Tip |
In some cases, Kmod may not detect a device in the way you want, and thereby not load the kernel module you would like. This was the case in Chapter 30, where you needed to provide SCSI emulation for IDE CD write devices. In this case, kernel parameters were specified to the GRUB boot loader to load the correct modules. |
The source code for your Linux kernel contains an extensive set of modules, of which only a few are actually used on your system. When you install a new device, you may have to install the kernel module that provides the drivers for it. This involves selecting the module you need from a list, and then regenerating your kernel modules with the new module included. Then the new module is copied into the module library, installing it on your system. You can then enter it in the /etc/modules.conf file with any options, or use modprobe to install it manually.
First, make sure you have installed the kernel source code in the /usr/src/linux directory (see Chapter 33). If not, simply use an installation utility such as rpm tool or redhat-config- packages to install the kernel source RPM packages. If you are using the source code version of the kernel, unpack it and move its contents to the /usr/src directory.
Now change to the /usr/src/linuxversion directory, where version is the kernel version. Red Hat includes the version number in the directory name. Then use the make command with the xconfig or menuconfig argument (gconfig for 2.6 Kernal) to display the kernel configuration menus, invoking them with the following commands. The make xconfig command starts an X Window System interface that needs to be run on your desktop from a terminal window.
make xconfig make menuconfig
Using the menus as described in Chapter 33, select the modules you need. Make sure each is marked as a module, clicking the Module check box in xconfig or typing m for menuconfig. Once the kernel is configured, save it and exit from the configuration menus. Then you compile the modules, creating the module binary files with the following command:
make modules
This places the modules in the kernel source modules directory: /usr/src/linuxversion/. You can copy the one you want to the kernel modules directory, /lib/modules/version/kernel, where version is the version number of your Linux kernel. A simpler approach is to reinstall all your modules, using the following command. This copies all the compiled modules to the /lib/modules/version/kernel directory.
make modules_install
For example, if you want to provide AppleTalk support, and your distribution did not create an AppleTalk module or incorporate the support into the kernel directly, you can use this method to create and install the AppleTalk modules. First, check to see if your distribution has the module already included. The AppleTalk modules should be in the /lib/modules/version/kernel/net/appletalk directory. If not, you can move to the /usr/src/linuxversion directory, run make xconfig, and select AppleTalk as a module. Then generate the modules with the make modules command. You could then use the make modules_install command to install the new module, along with your other modules. Or you can copy the appletalk directory and the modules it holds to the module directory.
< Day Day Up > |
This HTML Help has been published using the chm2web software. |