Restricting kernel module loading.
Introduction
In Linux systems, managing kernel modules is crucial for controlling hardware functionality and system behavior. This involves loading, listing, and blacklisting modules. This guide covers the basics of using modprobe to load modules, lsmod to list loaded modules, and configuring blacklists to prevent certain modules from loading.
Commands and Configuration
1. Loading a Module with modprobe
The modprobe command is used to load or remove modules from the Linux kernel.
This command loads the pcspkr module, which controls the system speaker (often used for system beeps).
2. Listing Loaded Modules with lsmod
The lsmod command displays the status of currently loaded modules in the Linux kernel.
This command lists all the loaded kernel modules, providing information such as module size and usage count.
3. Blacklisting Modules to Prevent Loading
Blacklisting is used to prevent certain kernel modules from being loaded automatically.
- Blacklist Configuration Syntax:
This syntax is used in configuration files to specify modules that should not be loaded.
4. Blacklist Configuration File and Verifying with Reboot
To blacklist a module, you add its name to a configuration file in /etc/modprobe.d/.
- Steps:
-
Edit/Create Configuration File:
Add the following line to the file:
This prevents the
pcspkrmodule from being loaded. -
Reboot:
Reboot the system to apply the changes.
-
Verify with
lsmod: After rebooting, check if the module is loaded:If the module is blacklisted correctly, it should not appear in the
lsmodoutput.
By using these commands and configurations, you can effectively manage kernel modules, enhancing control over your system's hardware and functionality.