Compiling Kernel   «Prev  Next»

Lesson 3 Working with kernel modules
ObjectiveList available kernel modules.

Working with Linux Kernel Modules and compiling the Linux Kernel

You can load modules, which are simply object files[1] into your modular kernel at any time. You might need to load a module when, for example, you add new hardware or want to support a new kind of filesystem.
Linux stores its modules in /lib/modules/, under a directory named for the running kernel's version. This arrangement allows your system to support modules for multiple kernel versions. To determine the running kernel's version, use
uname -r 	or 
cat /proc/version.

Within each version directory there are various subdirectories that separate modules according to their type. For example, all network modules are in the net directory and all SCSI modules are in the scsi directory.

Listing currently loaded modules

The lsmod command lists the modules currently resident in the kernel.
More information on lsmod is discussed below.
# lsmod
pwc              43392 1
videodev         5120 2 [pwc]
usbcore          59072 1 [audio pwc usb-uhci]

Working with kernel modules
The next lesson discusses how to load kernel modules.
The Linux kernel is modular, which means it can extend its capabilities through the use of dynamically-loaded kernel modules. A kernel module can provide:
  1. a device driver which adds support for new hardware; or,
  2. support for a file system such as btrfs or NFS.
Like the kernel itself, modules can take parameters that customize their behavior, though the default parameters work well in most cases.
User-space tools can
  1. list the modules currently loaded into a running kernel,
  2. query all available modules for available parameters and module-specific information, and
  3. load or unload (remove) modules dynamically into or from a running kernel.
Many of these utilities, which are provided by the module-init-tools package, take module dependencies into account when performing operations so that manual dependency-tracking is rarely necessary.
On modern systems, kernel modules are automatically loaded by various mechanisms when the conditions call for it. However, there are occasions when it is necessary to load and/or unload modules manually, such as when a module provides optional functionality, one module should be preferred over another although either could provide basic functionality, or when a module is misbehaving, among other situations.

[1]Object files: Compiled source code (such as C or C++).