Zum Inhalt springen

Linux/Kernel/Module/Anwendung: Unterschied zwischen den Versionen

Aus Foxwiki
K Textersetzung - „etc.“ durch „und weitere“
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
[[Wikipedia:Loadable kernel module#Linux|Kernel module]]s 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.
[[Wikipedia:Loadable kernel module#Linux|Kernel module]]s 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 [https://sysprog21.github.io/lkmpg/ 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 {{ic|M}}).
To create a kernel module, you can read [https://sysprog21.github.io/lkmpg/ 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).


To rebuild a kernel module automatically when a new kernel is installed, see [[Dynamic Kernel Module Support]] (DKMS).
To rebuild a kernel module automatically when a new kernel is installed, see [[Dynamic Kernel Module Support]] (DKMS).


== Obtaining information ==
== Obtaining information ==
Usually modules depend on the kernel release and are stored in the /usr/lib/modules/''kernel_release''/ directory.


Usually modules depend on the kernel release and are stored in the {{ic|/usr/lib/modules/''kernel_release''/}} directory.
; Tip
: Run uname -r (or uname --kernel-release) to get your current kernel release.


{{Tip|Run {{ic|uname -r}} (or {{ic|uname --kernel-release}}) to get your current kernel release.}}
; NoteModule and [[#Aliasing|alias]] names often use underscores (_) or dashes (-); however, those symbols are interchangeable when using the ''modprobe'' command and in configuration files in /etc/modprobe.d/ (automatic conversion to underscores is performed, see 8|modprobe|DESCRIPTION and 5|modprobe.d|DESCRIPTION).
 
{{Note|Module and [[#Aliasing|alias]] names often use underscores ({{ic|_}}) or dashes ({{ic|-}}); however, those symbols are interchangeable when using the ''modprobe'' command and in configuration files in {{ic|/etc/modprobe.d/}} (automatic conversion to underscores is performed, see {{man|8|modprobe|DESCRIPTION}} and {{man|5|modprobe.d|DESCRIPTION}}).}}
 
To show what kernel modules are currently loaded:


To show what kernel modules are currently loaded
  $ lsmod
  $ lsmod


To show information about a module:
To show information about a module
 
  $ modinfo ''module_name''
  $ modinfo ''module_name''


To list the options that are set for a loaded module use {{man|1|systool}} from {{Pkg|sysfsutils}}:
To list the options that are set for a loaded module use systool from [[sysfsutils]]
 
  $ systool -v -m ''module_name''
  $ systool -v -m ''module_name''


To display the comprehensive configuration of all the modules:
To display the comprehensive configuration of all the modules
 
  $ modprobe -c | less
  $ modprobe -c | less


To display the configuration of a particular module:
To display the configuration of a particular module
 
  $ modprobe -c | grep ''module_name''
  $ modprobe -c | grep ''module_name''


List the dependencies of a module (or alias), including the module itself:
List the dependencies of a module (or alias), including the module itself
 
  $ modprobe --show-depends ''module_name''
  $ modprobe --show-depends ''module_name''


== Automatic module loading ==
== 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.
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.


=== Early module loading ===
=== Early module loading ===
 
Early module loading depends on the [[initramfs]] generator used
Early module loading depends on the [[initramfs]] generator used:
 
* [[Booster#Early module loading]]
* [[Booster#Early module loading]]
* [[Dracut#Early kernel module loading]]
* [[Dracut#Early kernel module loading]]
* [[Mkinitcpio#MODULES]]
* [[Mkinitcpio#MODULES]]


{{Note|The ''initramfs'' image may not contain the kernel modules asked for in {{ic|/etc/modules-load.d/}}, it also may lack the files that have been set in that folder (see [[#systemd]]).}}
; Note
: 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 (see [[#systemd]]).


=== systemd ===
=== 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 /etc/modules-load.d/''program''.conf. 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.


Kernel modules can be explicitly listed in files under {{ic|/etc/modules-load.d/}} for systemd to load them during boot. Each configuration file is named in the style of {{ic|/etc/modules-load.d/''program''.conf}}. 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 {{ic|#}} or {{ic|;}} are ignored.
; /etc/modules-load.d/virtio-net.conf
 
# Load virtio_net.ko at boot
{{hc|/etc/modules-load.d/virtio-net.conf|
virtio_net
# Load virtio_net.ko at boot
virtio_net
}}


See {{man|5|modules-load.d}} for more details.
See [[modules-load.d]] for more details.


== Manual module handling ==
== Manual module handling ==
 
Kernel modules are handled by tools provided by the kmod package, which is installed as a dependency of a kernel package. You can use these tools manually. To load a module:
Kernel modules are handled by tools provided by the {{Pkg|kmod}} package, which is installed as a dependency of a kernel package. You can use these tools manually. To load a module:
 
  # modprobe ''module_name''
  # modprobe ''module_name''


{{Note|If you have upgraded your kernel but have not yet rebooted, ''modprobe'' will fail with no error message and exit with code {{ic|1}}, because the path {{ic|/usr/lib/modules/''kernel_release''/}} no longer exists. Check manually if this path exists when ''modprobe'' failed to determine if this is the case.}}
; Note
 
: If you have upgraded your kernel but have not yet rebooted, ''modprobe'' will fail with no error message and exit with code 1, because the path /usr/lib/modules/''kernel_release''/ no longer exists. Check manually if this path exists when ''modprobe'' failed to determine if this is the case.
To load a module by a file name—i.e. one that is not installed in the {{ic|/usr/lib/modules/''kernel_release''/}} directory—use any of:


To load a module by a file name—i.e. one that is not installed in the /usr/lib/modules/''kernel_release''/ directory—use any of:
  # insmod ''file_name'' ''module_options''
  # insmod ''file_name'' ''module_options''
  # modprobe ''file_name''
  # modprobe ''file_name''


To unload—''remove''—a module, use any of:
To unload—''remove''—a module, use any of:
  # rmmod ''module_name''
  # rmmod ''module_name''
  # modprobe -r ''module_name''
  # modprobe -r ''module_name''
Zeile 82: Zeile 69:


== Setting module options ==
== 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]]. If the module is built into the kernel, the kernel command line must be used and other methods will not work.
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]]. If the module is built into the kernel, the kernel command line must be used and other methods will not work.


=== Using modprobe ===
=== Using modprobe ===
 
The basic way to pass parameters to a module is using the ''modprobe'' command. Parameters are specified on command line using simple 1=''key''=''value'' assignments:
The basic way to pass parameters to a module is using the ''modprobe'' command. Parameters are specified on command line using simple {{ic|1=''key''=''value''}} assignments:
 
  # modprobe ''module_name'' ''parameter_name''=''parameter_value''
  # modprobe ''module_name'' ''parameter_name''=''parameter_value''


=== Using modprobe.d ===
=== Using modprobe.d ===
 
Configuration files in the /etc/modprobe.d/ directory can be used to pass module settings to [[udev]], which will use ''modprobe'' to manage the loading of the modules during system boot. Files in this directory can have any name, given that they end with the ''.conf'' extension. The file name matters, see 5|modprobe.d|CONFIGURATION DIRECTORIES AND PRECEDENCE. To show the effective configuration:
Configuration files in the {{ic|/etc/modprobe.d/}} directory can be used to pass module settings to [[udev]], which will use ''modprobe'' to manage the loading of the modules during system boot. Files in this directory can have any name, given that they end with the ''.conf'' extension. The file name matters, see {{man|5|modprobe.d|CONFIGURATION DIRECTORIES AND PRECEDENCE}}. To show the effective configuration:


  $ systemd-analyze cat-config modprobe.d
  $ systemd-analyze cat-config modprobe.d


The syntax is:
The syntax is:
; /etc/modprobe.d/''file_name''.conf
options ''module_name parameter_name=parameter_value''


{{hc|/etc/modprobe.d/''file_name''.conf|2=
options ''module_name parameter_name=parameter_value''
}}


{{Note|All options for a given module '''must''' be defined in a single line. New {{ic|options}} line with the same module name replaces the previous one.}}
; Note
: All options for a given module '''must''' be defined in a single line. New options line with the same module name replaces the previous one.


Multiple module parameters are separated by spaces, in turn a parameter can receive a list of values which is separated by commas:
Multiple module parameters are separated by spaces, in turn a parameter can receive a list of values which is separated by commas:


{{hc|/etc/modprobe.d/''file_name''.conf|2=
; /etc/modprobe.d/''file_name''.conf
options ''module_name param1=value1 param2=value2a,value2b …''
options ''module_name param1=value1 param2=value2a,value2b …''
}}


For example:
; For example
/etc/modprobe.d/thinkfan.conf
# On ThinkPads, this lets the 'thinkfan' daemon control fan speed
options thinkpad_acpi fan_control=1


{{hc|/etc/modprobe.d/thinkfan.conf|2=
; Note
# On ThinkPads, this lets the 'thinkfan' daemon control fan speed
: If any of the affected modules is loaded from the [[initramfs]], then you will need to add the appropriate ''.conf'' file to FILES in [[mkinitcpio.conf]] or use the modconf [[Mkinitcpio.conf#HOOKS|hook]], then [[regenerate the initramfs]] to include the ''.conf'' file. To see the contents of the default initramfs use [[mkinitcpio#Extracting the image|lsinitcpio]].
options thinkpad_acpi fan_control=1
}}
 
{{Note|If any of the affected modules is loaded from the [[initramfs]], then you will need to add the appropriate ''.conf'' file to {{ic|FILES}} in [[mkinitcpio.conf]] or use the {{ic|modconf}} [[Mkinitcpio.conf#HOOKS|hook]], then [[regenerate the initramfs]] to include the ''.conf'' file. To see the contents of the default initramfs use [[mkinitcpio#Extracting the image|lsinitcpio]].}}


=== Using kernel command line ===
=== Using kernel command line ===
You can also pass options to the module using the kernel command line. This is the only working option for modules built into the kernel. For all common [[boot loader]]s, the following syntax is correct:
You can also pass options to the module using the kernel command line. This is the only working option for modules built into the kernel. For all common [[boot loader]]s, the following syntax is correct:
  ''module_name.parameter_name=parameter_value''
  ''module_name.parameter_name=parameter_value''


For example:
; For example
 
  thinkpad_acpi.fan_control=1
  thinkpad_acpi.fan_control=1


Zeile 133: Zeile 111:


== Aliasing ==
== Aliasing ==
Aliases are alternate names for a module. For example: alias my-mod really_long_modulename means you can use modprobe my-mod instead of modprobe really_long_modulename. You can also use shell-style wildcards, so alias my-mod* really_long_modulename means that modprobe my-mod-something has the same effect. Create an alias:


Aliases are alternate names for a module. For example: {{ic|alias my-mod really_long_modulename}} means you can use {{ic|modprobe my-mod}} instead of {{ic|modprobe really_long_modulename}}. You can also use shell-style wildcards, so {{ic|alias my-mod* really_long_modulename}} means that {{ic|modprobe my-mod-something}} has the same effect. Create an alias:
; /etc/modprobe.d/myalias.conf
 
alias my-mod really_long_module_name
{{hc|/etc/modprobe.d/myalias.conf|
alias my-mod really_long_module_name
}}


Aliases can be internal—contained in the module itself. Internal aliases are usually used for [[#Automatic module loading]] when it is needed by an application, e.g. when the kernel detects a new device. To see the module internal aliases:
Aliases can be internal—contained in the module itself. Internal aliases are usually used for [[#Automatic module loading]] when it is needed by an application, e.g. when the kernel detects a new device.  


To see the module internal aliases
  $ modinfo --field=alias ''module_name''
  $ modinfo --field=alias ''module_name''


To see both configured and internal aliases:
To see both configured and internal aliases
 
  $ modprobe --showconfig | grep '\<''module_name''$'
  $ modprobe --showconfig | grep '\<''module_name''$'


== Blacklisting ==
== 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.
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.


{{Tip|Do not confuse the ''blacklisting'' as a generic term with using the {{ic|blacklist}} keyword as a blacklisting [[#blacklist|particular case]].}}
; Tip
: Do not confuse the ''blacklisting'' as a generic term with using the blacklist keyword as a blacklisting [[#blacklist|particular case]].


Some modules are loaded as part of the [[initramfs]]. {{ic|mkinitcpio -M}} will print out all automatically detected modules: to prevent the initramfs from loading some of those modules, blacklist them in a ''.conf'' file under {{ic|/etc/modprobe.d}} and it shall be added in by the {{ic|modconf}} hook during image generation. Running {{ic|mkinitcpio -v}} will list all modules pulled in by the various hooks (e.g. {{ic|filesystems}} hook, {{ic|block}} hook, und weitere). Remember to add that ''.conf'' file to the {{ic|FILES}} array in {{ic|/etc/mkinitcpio.conf}} if you do not have the {{ic|modconf}} hook in your {{ic|HOOKS}} array (e.g. you have deviated from the default configuration), and once you have blacklisted the modules [[regenerate the initramfs]], and reboot afterwards.
Some modules are loaded as part of the [[initramfs]]. mkinitcpio -M 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 modconf hook during image generation. Running mkinitcpio -v will list all modules pulled in by the various hooks (e.g. filesystems hook, block hook, und weitere). Remember to add that ''.conf'' file to the FILES array in /etc/mkinitcpio.conf if you do not have the modconf hook in your HOOKS array (e.g. you have deviated from the default configuration), and once you have blacklisted the modules [[regenerate the initramfs]], and reboot afterwards.


=== Using modprobe.d ===
=== Using modprobe.d ===
==== alias ====
==== alias ====
Disable an [[#Aliasing|alias]] by overriding. For example, to prevent Bluetooth module autoloading taking module named off does not exist:


Disable an [[#Aliasing|alias]] by overriding. For example, to prevent Bluetooth module autoloading taking module named {{ic|off}} does not exist:
; /etc/modprobe.d/modprobe.conf
 
alias net-pf-31 off
{{hc|/etc/modprobe.d/modprobe.conf|
alias net-pf-31 off
}}


{{Note|Alias overriding can prevent automatic module loading, but will still allow the module to be loaded—both automatically and manually—by another alias or the module name.}}
; Note
: Alias overriding can prevent automatic module loading, but will still allow the module to be loaded—both automatically and manually—by another alias or the module name.


==== blacklist ====
==== blacklist ====
To disable all internal aliases for a given module use the blacklist keyword. For example, to prevent the pcspkr module from loading on boot to avoid sounds through the [[PC speaker]]:


To disable all internal aliases for a given module use the {{ic|blacklist}} keyword. For example, to prevent the {{ic|pcspkr}} module from loading on boot to avoid sounds through the [[PC speaker]]:
; /etc/modprobe.d/nobeep.conf
blacklist pcspkr


{{hc|/etc/modprobe.d/nobeep.conf|
blacklist pcspkr
}}


{{Note|The {{ic|blacklist}} configuration command—as it deals with aliases—has the same drawback as the {{ic|alias}} one does: automatic loading can be prevented, but the module still may be loaded manually, or automatically if another module depends on it.}}
; Note
: The blacklist configuration command—as it deals with aliases—has the same drawback as the alias one does: automatic loading can be prevented, but the module still may be loaded manually, or automatically if another module depends on it.


==== install ====
==== install ====
There is a workaround for the behaviour described in the [[#alias]] and [[#blacklist]] notes. The install configuration command instructs ''modprobe'' to run a custom command instead of inserting the module in the kernel as normal, so you can simulate the successful module loading with:


There is a workaround for the behaviour described in the [[#alias]] and [[#blacklist]] notes. The {{ic|install}} configuration command instructs ''modprobe'' to run a custom command instead of inserting the module in the kernel as normal, so you can simulate the successful module loading with:
; /etc/modprobe.d/blacklist.conf
 
install ''module_name'' /bin/true
{{hc|/etc/modprobe.d/blacklist.conf|
install ''module_name'' /bin/true
}}


You can force the module to always fail loading with {{ic|/bin/false}}: this will effectively prevent the module—and any other that depends on it—from loading by any means, and a log error message may be produced.
You can force the module to always fail loading with /bin/false: this will effectively prevent the module—and any other that depends on it—from loading by any means, and a log error message may be produced.


=== Using kernel command line ===
=== Using kernel command line ===
 
; Tip
{{Tip|This can be very useful if a broken module makes it impossible to boot your system.}}
: This can be very useful if a broken module makes it impossible to boot your system.


You can also blacklist modules from the [[boot loader]] boot entry configuration.
You can also blacklist modules from the [[boot loader]] boot entry configuration.


Simply add {{ic|1=module_blacklist=''module_name_1'',''module_name_2'',''module_name_3''}} to your kernel command line, as described in [[Kernel parameters#Boot loader configuration]].
Simply add 1=module_blacklist=''module_name_1'',''module_name_2'',''module_name_3'' to your kernel command line, as described in [[Kernel parameters#Boot loader configuration]].


{{Note|
; Note
* When you are blacklisting more than one module, note that they are separated by commas only. Spaces or anything else might presumably break the syntax.
* When you are blacklisting more than one module, note that they are separated by commas only. Spaces or anything else might presumably break the syntax.
* {{ic|module_blacklist}} will make the kernel completely refuse to load the module.
* module_blacklist will make the kernel completely refuse to load the module.
* If you only want to prevent implicit loading, but maybe load the module manually later, the correct parameter is {{ic|1=modprobe.blacklist=''module_name_1'',''module_name_2'',''module_name_3''}}. This will however not prevent explicit loads during the boot, e.g. by [[#systemd|systemd]] or other modules.
* If you only want to prevent implicit loading, but maybe load the module manually later, the correct parameter is 1=modprobe.blacklist=''module_name_1'',''module_name_2'',''module_name_3''. This will however not prevent explicit loads during the boot, e.g. by [[#systemd|systemd]] or other modules.
}}


Another use case for a command line option is to disable hardware-specific components of a module without disabling the module entirely. For example, disabling a microphone while retaining other sound out options. See [https://bbs.archlinux.org/viewtopic.php?id=303475 BBS#303475] for a few examples.
Another use case for a command line option is to disable hardware-specific components of a module without disabling the module entirely. For example, disabling a microphone while retaining other sound out options. See [https://bbs.archlinux.org/viewtopic.php?id=303475 BBS#303475] for a few examples.


== Troubleshooting ==
== Troubleshooting ==
=== Module does not load ===
=== Module does 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 /etc/modprobe.d/ does not show a corresponding entry, check another ''modprobe'' source directory at /usr/lib/modprobe.d/ for blacklisting entries.


In case a specific module does not load and the boot log (accessible by running {{ic|journalctl -b}} as root) says that the module is blacklisted, but the directory {{ic|/etc/modprobe.d/}} does not show a corresponding entry, check another ''modprobe'' source directory at {{ic|/usr/lib/modprobe.d/}} 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 modprobe --force-vermagic.
 
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 {{ic|modprobe --force-vermagic}}.


{{Warning|Ignoring the version checks for a kernel module can cause a kernel to crash or a system to exhibit undefined behavior due to incompatibility. Use {{ic|--force-vermagic}} only with the utmost caution.}}
; Warning
: Ignoring the version checks for a kernel module can cause a kernel to crash or a system to exhibit undefined behavior due to incompatibility. Use --force-vermagic only with the utmost caution.


== See also ==
== See also ==
* [[Disable PC speaker beep]]
* [[Disable PC speaker beep]]
* [https://lwn.net/Articles/391230/ Writing a WMI driver] - an LWM introduction
* [https://lwn.net/Articles/391230/ Writing a WMI driver] - an LWM introduction


[[Category:Kernel]]
[[Category:Kernel]]
[[Category:Hardware detection and troubleshooting]]
[[Category:Hardware detection and troubleshooting]]
[[Category:Boot process]]
[[Category:Boot process]]

Version vom 30. April 2025, 22:20 Uhr

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).

To rebuild a kernel module automatically when a new kernel is installed, see Dynamic Kernel Module Support (DKMS).

Obtaining information

Usually modules depend on the kernel release and are stored in the /usr/lib/modules/kernel_release/ directory.

Tip
Run uname -r (or uname --kernel-release) to get your current kernel release.
NoteModule and alias names often use underscores (_) or dashes (-); however, those symbols are interchangeable when using the modprobe command and in configuration files in /etc/modprobe.d/ (automatic conversion to underscores is performed, see 8|modprobe|DESCRIPTION and 5|modprobe.d|DESCRIPTION).

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 use systool from sysfsutils

$ 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.

Early module loading

Early module loading depends on the initramfs generator used

Note
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 (see #systemd).

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 /etc/modules-load.d/program.conf. 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.

/etc/modules-load.d/virtio-net.conf
# Load virtio_net.ko at boot
virtio_net

See modules-load.d for more details.

Manual module handling

Kernel modules are handled by tools provided by the kmod package, which is installed as a dependency of a kernel package. You can use these tools manually. To load a module:

# modprobe module_name
Note
If you have upgraded your kernel but have not yet rebooted, modprobe will fail with no error message and exit with code 1, because the path /usr/lib/modules/kernel_release/ no longer exists. Check manually if this path exists when modprobe failed to determine if this is the case.

To load a module by a file name—i.e. one that is not installed in the /usr/lib/modules/kernel_release/ directory—use any of:

# insmod file_name module_options
# modprobe file_name

To unload—remove—a module, use any of:

# rmmod module_name
# modprobe -r module_name
# modprobe --remove 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. If the module is built into the kernel, the kernel command line must be used and other methods will not work.

Using modprobe

The basic way to pass parameters to a module is using the modprobe command. Parameters are specified on command line using simple 1=key=value assignments:

# modprobe module_name parameter_name=parameter_value

Using modprobe.d

Configuration files in the /etc/modprobe.d/ directory can be used to pass module settings to udev, which will use modprobe to manage the loading of the modules during system boot. Files in this directory can have any name, given that they end with the .conf extension. The file name matters, see 5|modprobe.d|CONFIGURATION DIRECTORIES AND PRECEDENCE. To show the effective configuration:

$ systemd-analyze cat-config modprobe.d

The syntax is:

/etc/modprobe.d/file_name.conf
options module_name parameter_name=parameter_value


Note
All options for a given module must be defined in a single line. New options line with the same module name replaces the previous one.

Multiple module parameters are separated by spaces, in turn a parameter can receive a list of values which is separated by commas:

/etc/modprobe.d/file_name.conf
options module_name param1=value1 param2=value2a,value2b …
For example

/etc/modprobe.d/thinkfan.conf

# On ThinkPads, this lets the 'thinkfan' daemon control fan speed
options thinkpad_acpi fan_control=1
Note
If any of the affected modules is loaded from the initramfs, then you will need to add the appropriate .conf file to FILES in mkinitcpio.conf or use the modconf hook, then regenerate the initramfs to include the .conf file. To see the contents of the default initramfs use lsinitcpio.

Using kernel command line

You can also pass options to the module using the kernel command line. This is the only working option for modules built into the kernel. For all common boot loaders, the following syntax is correct:

module_name.parameter_name=parameter_value
For example
thinkpad_acpi.fan_control=1

Simply add this to the appropriate line in your boot loader configuration, as described in Kernel parameters#Boot loader configuration.

Aliasing

Aliases are alternate names for a module. For example: alias my-mod really_long_modulename means you can use modprobe my-mod instead of modprobe really_long_modulename. You can also use shell-style wildcards, so alias my-mod* really_long_modulename means that modprobe my-mod-something has the same effect. Create an alias:

/etc/modprobe.d/myalias.conf
alias my-mod really_long_module_name

Aliases can be internal—contained in the module itself. Internal aliases are usually used for #Automatic module loading when it is needed by an application, e.g. when the kernel detects a new device.

To see the module internal aliases

$ modinfo --field=alias module_name

To see both configured and internal aliases

$ modprobe --showconfig | grep '\<module_name$'

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.

Tip
Do not confuse the blacklisting as a generic term with using the blacklist keyword as a blacklisting particular case.

Some modules are loaded as part of the initramfs. mkinitcpio -M 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 modconf hook during image generation. Running mkinitcpio -v will list all modules pulled in by the various hooks (e.g. filesystems hook, block hook, und weitere). Remember to add that .conf file to the FILES array in /etc/mkinitcpio.conf if you do not have the modconf hook in your HOOKS array (e.g. you have deviated from the default configuration), and once you have blacklisted the modules regenerate the initramfs, and reboot afterwards.

Using modprobe.d

alias

Disable an alias by overriding. For example, to prevent Bluetooth module autoloading taking module named off does not exist:

/etc/modprobe.d/modprobe.conf
alias net-pf-31 off
Note
Alias overriding can prevent automatic module loading, but will still allow the module to be loaded—both automatically and manually—by another alias or the module name.

blacklist

To disable all internal aliases for a given module use the blacklist keyword. For example, to prevent the pcspkr module from loading on boot to avoid sounds through the PC speaker:

/etc/modprobe.d/nobeep.conf
blacklist pcspkr


Note
The blacklist configuration command—as it deals with aliases—has the same drawback as the alias one does: automatic loading can be prevented, but the module still may be loaded manually, or automatically if another module depends on it.

install

There is a workaround for the behaviour described in the #alias and #blacklist notes. The install configuration command instructs modprobe to run a custom command instead of inserting the module in the kernel as normal, so you can simulate the successful module loading with:

/etc/modprobe.d/blacklist.conf
install module_name /bin/true

You can force the module to always fail loading with /bin/false: this will effectively prevent the module—and any other that depends on it—from loading by any means, and a log error message may be produced.

Using kernel command line

Tip
This can be very useful if a broken module makes it impossible to boot your system.

You can also blacklist modules from the boot loader boot entry configuration.

Simply add 1=module_blacklist=module_name_1,module_name_2,module_name_3 to your kernel command line, as described in Kernel parameters#Boot loader configuration.

Note
  • When you are blacklisting more than one module, note that they are separated by commas only. Spaces or anything else might presumably break the syntax.
  • module_blacklist will make the kernel completely refuse to load the module.
  • If you only want to prevent implicit loading, but maybe load the module manually later, the correct parameter is 1=modprobe.blacklist=module_name_1,module_name_2,module_name_3. This will however not prevent explicit loads during the boot, e.g. by systemd or other modules.

Another use case for a command line option is to disable hardware-specific components of a module without disabling the module entirely. For example, disabling a microphone while retaining other sound out options. See BBS#303475 for a few examples.

Troubleshooting

Module does 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 /etc/modprobe.d/ does not show a corresponding entry, check another modprobe source directory at /usr/lib/modprobe.d/ 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 modprobe --force-vermagic.

Warning
Ignoring the version checks for a kernel module can cause a kernel to crash or a system to exhibit undefined behavior due to incompatibility. Use --force-vermagic only with the utmost caution.

See also