Previous Section  < Day Day Up >  Next Section

Recipe 10.7. Adding a New Loadable Kernel Module

10.7.1 Problem

You have changed or added some hardware, such as a NIC card, sound card, or USB device, and you need to install a new kernel module (driver) for the device.

10.7.2 Solution

The steps are the same for 2.4 and 2.6 kernels. Change to the directory that contains the build tree (e.g., ~/src/linux-2.4.25). You'll need a good, up-to-date .config file. Copy it to the top level of your build tree, then run:

$ make oldconfig

As you go through the configuration, find the driver you need and select it as a module (for example, the tulip module, which is a common driver for many Ethernet cards). Then:

$ make dep

$ make modules

# make modules_install

# depmod -av

Load the module with modprobe:

# modprobe tulip

This whole process doesn't need a reboot.

10.7.3 Discussion

make menuconfig also works, if you can't use oldconfig. It just takes longer, and you have to be careful to not leave out anything important.

If you're installing a third-party module that is not in the kernel tree, you must rely on the vendor's installation instructions. The usual method is to download sources, build the module, then load it with modprobe. Some vendors, like nVidia, provide a script that does everything for you.

Most distributions probe hardware at bootup, and automatically load the correct modules. If this does not happen, you'll need to configure some startup files. On Red Hat and SuSE, add the module to /etc/modules.conf. On Debian, add it to /etc/modules. Slackware uses rc.modules.

Even easier is to enable kmod, the automatic module loader, in your kernel. Most distributions enable it by default. In the kernel configurator, look for "Automatic kernel module loading" (2.6 kernel) or "Kernel module loader" (2.4) under "Loadable module support."

Don't use kerneld; kmod replaced it starting from the 2.2 kernel.

10.7.4 See Also

  • This chapter's Introduction, for where to get kernel sources and where to look for documentation

  • Recipe 10.2, for explanations of the build commands, where to find a .config file, and how to preserve it for reuse

    Previous Section  < Day Day Up >  Next Section