Kernel module
Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system.
To create a kernel module, you can read The Linux Kernel Module Programming Guide. A module can be configured as built-in or loadable. To dynamically load or remove a module, it has to be configured as a loadable module in the kernel configuration (the line related to the module will therefore display the letter M
).
Obtaining information
Modules are stored in /usr/lib/modules/kernel_release
. You can use the command uname -r
to get your current kernel release version.
_
) or dashes (-
); however, those symbols are interchangeable when using the modprobe
command and in configuration files in /etc/modprobe.d/
.To show what kernel modules are currently loaded:
$ lsmod
To show information about a module:
$ modinfo module_name
To list the options that are set for a loaded module:
$ systool -v -m module_name
To display the comprehensive configuration of all the modules:
$ modprobe -c | less
To display the configuration of a particular module:
$ modprobe -c | grep module_name
List the dependencies of a module (or alias), including the module itself:
$ modprobe --show-depends module_name
Automatic module loading
Today, all necessary modules loading is handled automatically by udev, so if you do not need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any configuration file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.
systemd
Kernel modules can be explicitly listed in files under /etc/modules-load.d/
for systemd to load them during boot. Each configuration file is named in the style of . Configuration files simply contain a list of kernel modules names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is or are ignored.
See modules-load.d(5) for more details.
Early module loading
The initramfs image may not contain the kernel modules asked for in /etc/modules-load.d/
, it also may lack the files that have been set in that folder. Early module loading depend on the initramfs generator used:
Manual module handling
Kernel modules are handled by tools provided by package. You can use these tools manually.
To load a module:
# modprobe module_name
To load a module by filename (i.e. one that is not installed in ):
# insmod filename [args]
To unload a module:
# modprobe -r module_name
Or, alternatively:
# rmmod module_name
Setting module options
To pass a parameter to a kernel module, you can pass them manually with modprobe or assure certain parameters are always applied using a modprobe configuration file or by using the kernel command line.
Manually at load time using modprobe
The basic way to pass parameters to a module is using the modprobe command. Parameters are specified on command line using simple assignments:
# modprobe module_name parameter_name=parameter_value
Using files in /etc/modprobe.d/
Files in directory can be used to pass module settings to udev, which will use to manage the loading of the modules during system boot. Configuration files in this directory can have any name, given that they end with the .conf extension. The syntax is:
For example:
/etc/modprobe.d/thinkfan.conf
# On ThinkPads, this lets the 'thinkfan' daemon control fan speed options thinkpad_acpi fan_control=1
Using kernel command line
If the module is built into the kernel, you can also pass options to the module using the kernel command line. For all common bootloaders, the following syntax is correct:
module_name.parameter_name=parameter_value
For example:
thinkpad_acpi.fan_control=1
Simply add this to your bootloader's kernel-line, as described in Kernel Parameters.
Aliasing
Aliases are alternate names for a module. For example: alias my-mod really_long_modulename
means you can use instead of . You can also use shell-style wildcards, so means that has the same effect. Create an alias:
Some modules have aliases which are used to automatically load them when they are needed by an application. Disabling these aliases can prevent automatic loading but will still allow the modules to be manually loaded.
Blacklisting
Blacklisting, in the context of kernel modules, is a mechanism to prevent the kernel module from loading. This could be useful if, for example, the associated hardware is not needed, or if loading that module causes problems: for instance there may be two kernel modules that try to control the same piece of hardware, and loading them together would result in a conflict.
Some modules are loaded as part of the initramfs. will print out all automatically detected modules: to prevent the initramfs from loading some of those modules, blacklist them in a .conf file under /etc/modprobe.d
and it shall be added in by the hook during image generation. Running will list all modules pulled in by the various hooks (e.g. filesystems
hook, hook, etc.). Remember to add that .conf file to the array in if you do not have the hook in your array (e.g. you have deviated from the default configuration), and once you have blacklisted the modules regenerate the initramfs, and reboot afterwards.
Using files in /etc/modprobe.d/
Create a .conf file inside and append a line for each module you want to blacklist, using the keyword. If for example you want to prevent the module from loading to avoid sounds through the PC speaker:
blacklist
command will blacklist a module so that it will not be loaded automatically, but the module may be loaded if another non-blacklisted module depends on it or if it is loaded manually.
However, there is a workaround for this behaviour; the install
command instructs modprobe to run a custom command instead of inserting the module in the kernel as normal, so you can force the module to always fail loading with:
/etc/modprobe.d/blacklist.conf
... install ''module_name'' /bin/true ...This will effectively blacklist that module and any other that depends on it.
Using kernel command line
You can also blacklist modules from the bootloader.
Simply add to your bootloader's kernel line, as described in Kernel parameters.
Troubleshooting
Modules do not load
In case a specific module does not load and the boot log (accessible by running journalctl -b
as root) says that the module is blacklisted, but the directory does not show a corresponding entry, check another modprobe source directory at for blacklisting entries.
A module will not be loaded if the "vermagic" string contained within the kernel module does not match the value of the currently running kernel. If it is known that the module is compatible with the current running kernel the "vermagic" check can be ignored with .
See also
- Disable PC speaker beep
- Writing a WMI driver - an LWM introduction