|Lesson 3|| Working with kernel modules |
|Objective||List available kernel modules.|
Working with Linux Kernel Modules and compiling the Linux Kernel
In Red Hat Linux, the available kernel modules can be listed by accessing the appropriate system directories and using certain commands. Here is a step-by-step process for listing the available kernel modules.
- Use the lsmod Command: The lsmod command provides an immediate listing of all loaded kernel modules. To execute it, open the terminal and type:
The output will display three columns:
Please note that this command only lists the modules currently loaded by your system.
- Module: The name of the kernel module.
- Size: The size of the module (in kilobytes).
- Used by: The number of instances of the module currently in use and the dependent modules.
- Use the modprobe Command:
The modprobe command with the -l or --list option can be used to display all available modules. However, this has been deprecated in recent versions of modprobe. If your system's modprobe command supports it, use:
This command lists all the kernel modules available in the directories specified in
- Directly Browse the /lib/modules/ Directory:
All available kernel modules are generally stored in the
directory. Each subdirectory corresponds to a different kernel version.
The kernel version currently in use can be determined with the uname command:
To list all available kernel modules for the currently active kernel, use:
ls /lib/modules/$(uname -r)
Replace "$(uname -r)" with your specific kernel version if needed. This will list all the directories containing the available kernel modules. The .ko files in these directories represent the individual modules.
Remember that manipulating kernel modules can have significant system-wide effects, so always use these commands with care. Additionally, root or sudo permissions may be needed for some of these operations.
You can load modules, which are simply object files
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
, 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
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
lsmod command lists the modules currently resident in the kernel.
More information on
lsmod is discussed below.
pwc 43392 1
videodev 5120 2 [pwc]
usbcore 59072 1 [audio pwc usb-uhci]
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:
- a device driver which adds support for new hardware; or,
- 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
- list the modules currently loaded into a running kernel,
- query all available modules for available parameters and module-specific information, and
- 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.
Compiled source code (such as C or C++).