7.5. I Need to Add a Custom Kernel Module
Sometimes, the module associated with an item of your hardware is not included with your distribution. That's an annoyance every Linux geek should know how to fix.
In "My Wireless Card Works on Another Operating System, but Not Linux" in Chapter 5, we stressed the importance of knowing the make, the model, and, in many cases, the chipset associated with each hardware component. With this information, you can identify available Linux modules associated with your hardware.
To find the right hardware module, try the following in order:
I'll describe what you do if one the first four steps yields results. Refer to "My Wireless Card Works on Another Operating System, but Not Linux" in Chapter 5 if you have to resort to developmental (alpha or beta) drivers.
7.5.1. Check Installed Modules
The module that you need may already be properly installed; in this case, the operating system is ready and you may just have to do something hardware-specific to activate the hardware. (It may be as simple as checking that the cable is plugged in.)
As an example, assume you're looking for the Linksys Tulip driver. Based on the module name that you've found in your documentation or online web search, identifying the right driver is a simple:
lsmod | grep -i tulip
If the driver turns up in your list of modules, the problem may be with the hardware. If you're sure the hardware is working (perhaps because you've tried it under another operating system), you may have a defective module; you may try recompiling from a fresh copy of the driver software, using the techniques we've described in "Recompiling the Kernel," earlier in this chapter.
7.5.2. Check Compiled Modules
If you're fortunate, the module for your new hardware is part of your distribution's module directory. The right compiled module should be in the /lib/modules directory associated with your active kernel (you might have more than one kernel). This directory is defined by:
If the module is available only in a different directory, try copying it to the directory associated with the active kernel. It might work if you're fortunate. Otherwise, use the source code to recompile the module for your running kernel.
7.5.3. Check the Kernel Source Code
When you recompile your kernel, you can incorporate drivers of your choice. Assuming you've enabled loadable modules, there are three options for most drivers during kernel configuration:
The notes associated with a driver are often quite specific. For example, the HCI UART driver shown in Figure 7-4 is directly associated with several specific Bluetooth cards.
Figure 7-4. A Bluetooth driver in the kernel
The particular tool shown in this figure lists modules with dots, and notes drivers that are compiled directly into the kernel with check marks. Other tools may be more straightforward. For example, with the ncurses-based make menuconfig tool, y incorporates the driver into the kernel, m configures the driver as a module, and n excludes the driver from your kernel and list of modules.
7.5.4. Check Your Hardware Manufacturer
An increasing number of hardware manufacturers provide Linux drivers. If you haven't found a module for your component yet, try their web sites. You might be pleasantly surprised. Unfortunately, loading a driver is a bit more difficult than downloading and running an executable file.
While details vary, there are five basic steps associated with setting up a downloaded driver for Linux:
7.5.5. Making Sure Your Kernel Is Loaded
Once you have a working driver, Linux might automatically detect it the next time you reboot. If not, make sure the driver module is available from the correct directory, specifically a subdirectory of /lib/modules/`uname -r`. See if you can load it with the appropriate insmod or modprobe commands.
Assuming that works, you'll need to add the driver, with configuration options, to a module configuration file. The next time you boot Linux, driver modules are loaded based on instructions in this file. For distributions associated with Linux 2.4 series kernels, the file is /etc/modprobe.conf. For Linux 2.6 series kernels, the file name varies by distribution.
For example, Debian includes some generic drivers in /etc/modules. Specialty drivers are loaded via scripts in the /etc/modultils directory. Standard module aliases are listed in different files in the /etc/modprobe.d directory.
In SUSE and Fedora Core 3, standard modules are listed in /etc/modprobe.conf. SUSE User-defined modules can be loaded via /etc/modules.conf. Specific options can be added to appropriate files in the /etc/modprobe.d directory.