Difference between revisions of "Kernel modules"

From ArchWiki
Jump to: navigation, search
(group commands for getting info, simplify)
(new templates, see Help:Style)
Line 10: Line 10:
 
For a module to be recognized as such, it has to be compiled as a module in the kernel configuration (the line related to the module will therefore display the letter '''M''').
 
For a module to be recognized as such, it has to be compiled as a module in the kernel configuration (the line related to the module will therefore display the letter '''M''').
  
Modules are stored in {{Filename|/lib/modules/'''kernel_release'''}} (use the command {{Codeline|uname -r}} to print your current kernel release).
+
Modules are stored in {{ic|/lib/modules/'''kernel_release'''}} (use the command {{ic|uname -r}} to print your current kernel release).
  
The {{Codeline|/sbin/modprobe}} command handles the addition and removal of modules from the Linux kernel.
+
The {{ic|/sbin/modprobe}} command handles the addition and removal of modules from the Linux kernel.
  
The {{Filename|/etc/modprobe.d/}} directory can be used to pass module settings to [[udev]], which will use {{Codeline|modprobe}} to manage the loading of the modules during system boot. You can use configuration files with any name in the directory, given that they end with the {{Filename|.conf}} extension.
+
The {{ic|/etc/modprobe.d/}} directory can be used to pass module settings to [[udev]], which will use {{ic|modprobe}} to manage the loading of the modules during system boot. You can use configuration files with any name in the directory, given that they end with the {{ic|.conf}} extension.
  
{{Note|Module names often use underscores ("_") or dashes ("-"), however those symbols are interchangeable both when using the {{Codeline|modprobe}} command and in configuration files in {{Filename|/etc/modprobe.d/}}.}}
+
{{Note|Module names often use underscores ("_") or dashes ("-"), however those symbols are interchangeable both when using the {{ic|modprobe}} command and in configuration files in {{ic|/etc/modprobe.d/}}.}}
  
 
==Obtaining information==
 
==Obtaining information==
  
* Format the contents of {{Filename|/proc/modules}} and show what kernel modules are currently loaded:
+
* Format the contents of {{ic|/proc/modules}} and show what kernel modules are currently loaded:
 
  $ lsmod
 
  $ lsmod
  
* Use {{Codeline|modinfo}} to show information about a module:
+
* Use {{ic|modinfo}} to show information about a module:
 
  $ modinfo ''module_name''
 
  $ modinfo ''module_name''
  
* Use {{Codeline|modprobe}} to list the dependencies of a module (or alias), including the module itself:
+
* Use {{ic|modprobe}} to list the dependencies of a module (or alias), including the module itself:
 
  $ modprobe --show-depends ''module_name''
 
  $ modprobe --show-depends ''module_name''
  
Line 59: Line 59:
  
 
===Using files in /etc/modprobe.d/===
 
===Using files in /etc/modprobe.d/===
To pass options to a module using modprobe config files, a .conf file with any name (you can even use {{Filename|/etc/modprobe.d/modprobe.conf}}) needs to be placed in {{Filename|/etc/modprobe.d/}} with this syntax:
+
To pass options to a module using modprobe config files, a .conf file with any name (you can even use {{ic|/etc/modprobe.d/modprobe.conf}}) needs to be placed in {{ic|/etc/modprobe.d/}} with this syntax:
{{File|name/etc/modprobe.d/myfilename.conf|content=options modname parametername=parametercontents}}
+
{{hc|/etc/modprobe.d/myfilename.conf|2=options modname parametername=parametercontents}}
 
for example:
 
for example:
{{File|name=/etc/modprobe.d/thinkfan.conf|content=# On thinkpads, this lets the thinkfan daemon control fan speed
+
{{hc|/etc/modprobe.d/thinkfan.conf|2=# On thinkpads, this lets the thinkfan daemon control fan speed
 
options thinkpad_acpi fan_control=1}}
 
options thinkpad_acpi fan_control=1}}
  
Line 73: Line 73:
 
==Aliasing==
 
==Aliasing==
 
{{Expansion}}
 
{{Expansion}}
{{File|name=/etc/modprobe.d/myalias.conf|content=# Lets you use 'mymod' in MODULES, instead of 'really_long_module_name'
+
{{hc|/etc/modprobe.d/myalias.conf|<nowiki># Lets you use 'mymod' in MODULES, instead of 'really_long_module_name'
alias mymod really_long_module_name}}
+
alias mymod really_long_module_name</nowiki>}}
  
 
Some modules have aliases which are used to autoload them when they are needed by an application. Disabling these aliases can prevent auto-loading, but will still allow the modules to be manually loaded.
 
Some modules have aliases which are used to autoload them when they are needed by an application. Disabling these aliases can prevent auto-loading, but will still allow the modules to be manually loaded.
{{File|name=/etc/modprobe.d/modprobe.conf|content=# Prevent autoload of bluetooth
+
{{hc|/etc/modprobe.d/modprobe.conf|<nowiki># Prevent autoload of bluetooth
 
alias net-pf-31 off
 
alias net-pf-31 off
  
 
# Prevent autoload of ipv6
 
# Prevent autoload of ipv6
alias net-pf-10 off}}
+
alias net-pf-10 off</nowiki>}}
  
 
==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.
  
Some modules are loaded as part of the [[initramfs]]. {{Codeline|mkinitcpio -M}} will print out all autodetected modules: to prevent the initramfs from loading some of those modules, blacklist them in {{Filename|/etc/modprobe.d/modprobe.conf}}. Running {{Codeline|mkinitcpio -v}} will list all modules pulled in by the various hooks (e.g. filesystem hook, SCSI hook, etc.). Remember to rebuild the initramfs once you have blacklisted the modules and to reboot afterwards.
+
Some modules are loaded as part of the [[initramfs]]. {{ic|mkinitcpio -M}} will print out all autodetected modules: to prevent the initramfs from loading some of those modules, blacklist them in {{ic|/etc/modprobe.d/modprobe.conf}}. Running {{ic|mkinitcpio -v}} will list all modules pulled in by the various hooks (e.g. filesystem hook, SCSI hook, etc.). Remember to rebuild the initramfs once you have blacklisted the modules and to reboot afterwards.
  
{{Warning|Blacklisting modules in {{Filename|/etc/rc.conf}} has been obsoleted and no longer works in {{Package Official|initscripts}} 2011.06.1-1, so you will have to use one of the following methods.}}
+
{{Warning|Blacklisting modules in {{ic|/etc/rc.conf}} has been obsoleted and no longer works in {{Pkg|initscripts}} 2011.06.1-1, so you will have to use one of the following methods.}}
  
 
===Using files in /etc/modprobe.d/===
 
===Using files in /etc/modprobe.d/===
  
Create a {{Filename|.conf}} file inside {{Filename|/etc/modprobe.d/}} and append a line for each module you want to blacklist, using the {{Codeline|blacklist}} keyword. If for example you want to prevent the {{Codeline|pcspkr}} module from loading:
+
Create a {{ic|.conf}} file inside {{ic|/etc/modprobe.d/}} and append a line for each module you want to blacklist, using the {{ic|blacklist}} keyword. If for example you want to prevent the {{ic|pcspkr}} module from loading:
  
{{File|/etc/modprobe.d/nobeep.conf|content=<nowiki># Do not load the pcspkr module on boot
+
{{hc|/etc/modprobe.d/nobeep.conf|<nowiki># Do not load the pcspkr module on boot
 
blacklist pcspkr</nowiki>}}
 
blacklist pcspkr</nowiki>}}
  
{{Note|The {{Codeline|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.
+
{{Note|The {{ic|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 {{Codeline|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:
+
However, there is a workaround for this behaviour; the {{ic|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:
  
{{File|/etc/modprobe.d/blacklist.conf|content=...
+
{{hc|/etc/modprobe.d/blacklist.conf|<nowiki>...
 
install MODULE /bin/false
 
install MODULE /bin/false
...}}
+
...</nowiki>}}
  
 
This will effectively "blacklist" that module and any other that depends on it.}}
 
This will effectively "blacklist" that module and any other that depends on it.}}
Line 120: Line 120:
 
====Examples using GRUB====
 
====Examples using GRUB====
  
{{File|name=/boot/grub/menu.lst|content=...
+
{{hc|/boot/grub/menu.lst|<nowiki>...
 
kernel /vmlinuz-linux root=/dev/sda1 modprobe.blacklist=pcspkr,ipv6 ro
 
kernel /vmlinuz-linux root=/dev/sda1 modprobe.blacklist=pcspkr,ipv6 ro
...}}
+
...</nowiki>}}
  
{{File|name=/boot/grub/menu.lst|content=...
+
{{hc|/boot/grub/menu.lst|<nowiki>...
 
kernel /vmlinuz-linux root=/dev/sda1 pcspkr.disable=1 ipv6.disable=1 ro
 
kernel /vmlinuz-linux root=/dev/sda1 pcspkr.disable=1 ipv6.disable=1 ro
...}}
+
...</nowiki>}}
  
 
==See also==
 
==See also==

Revision as of 13:43, 7 November 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

This article covers the various methods for operating with kernel modules.

Overview

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Kernel modules#)

For a module to be recognized as such, it has to be compiled as a module in the kernel configuration (the line related to the module will therefore display the letter M).

Modules are stored in /lib/modules/kernel_release (use the command uname -r to print your current kernel release).

The /sbin/modprobe command handles the addition and removal of modules from the Linux kernel.

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. You can use configuration files with any name in the directory, given that they end with the .conf extension.

Note: Module names often use underscores ("_") or dashes ("-"), however those symbols are interchangeable both when using the modprobe command and in configuration files in /etc/modprobe.d/.

Obtaining information

  • Format the contents of /proc/modules and show what kernel modules are currently loaded:
$ lsmod
  • Use modinfo to show information about a module:
$ modinfo module_name
  • Use modprobe to list the dependencies of a module (or alias), including the module itself:
$ modprobe --show-depends module_name

Configuration

If you want to display the comprehensive configuration of all the modules you can use the command:

$ modprobe -c | less

To display the configuration of a particular module, use:

$ modprobe -c | grep module_name

Loading

To manually load (or add) a module, run:

# modprobe module_name

For information on loading modules automatically at system boot, see rc.conf.

Removal

Occasionally you could need to remove (or unload) a module; in this case use the following command:

# modprobe -r module_name

Or, alternatively:

# rmmod module_name

Options

To pass a parameter to a kernel module you can use a modprobe conf file or use the kernel command line.

Using files in /etc/modprobe.d/

To pass options to a module using modprobe config files, a .conf file with any name (you can even use /etc/modprobe.d/modprobe.conf) needs to be placed in /etc/modprobe.d/ with this syntax:

/etc/modprobe.d/myfilename.conf
options modname parametername=parametercontents

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 (e.g. in GRUB, LILO or Syslinux) using the following syntax:

modname.parametername=parametercontents

for example:

thinkpad_acpi.fan_control=1

Aliasing

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Kernel modules#)
/etc/modprobe.d/myalias.conf
# Lets you use 'mymod' in MODULES, instead of 'really_long_module_name'
alias mymod really_long_module_name

Some modules have aliases which are used to autoload them when they are needed by an application. Disabling these aliases can prevent auto-loading, but will still allow the modules to be manually loaded.

/etc/modprobe.d/modprobe.conf
# Prevent autoload of bluetooth
alias net-pf-31 off

# Prevent autoload of ipv6
alias net-pf-10 off

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. mkinitcpio -M will print out all autodetected modules: to prevent the initramfs from loading some of those modules, blacklist them in /etc/modprobe.d/modprobe.conf. Running mkinitcpio -v will list all modules pulled in by the various hooks (e.g. filesystem hook, SCSI hook, etc.). Remember to rebuild the initramfs once you have blacklisted the modules and to reboot afterwards.

Warning: Blacklisting modules in /etc/rc.conf has been obsoleted and no longer works in initscripts 2011.06.1-1, so you will have to use one of the following methods.

Using files in /etc/modprobe.d/

Create a .conf file inside /etc/modprobe.d/ and append a line for each module you want to blacklist, using the blacklist keyword. If for example you want to prevent the pcspkr module from loading:

/etc/modprobe.d/nobeep.conf
# Do not load the pcspkr module on boot
blacklist pcspkr
Note: The 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 /bin/false
...
This will effectively "blacklist" that module and any other that depends on it.

Using kernel command line

Tip: This is useful in an emergency where a broken module makes it impossible to boot your system.

You can also blacklist modules on the kernel command line (e.g. in GRUB, LILO or Syslinux) using the following syntax:

modprobe.blacklist=modname1,modname2,modname3

Alternatively:

modname.disable=1

Examples using GRUB

/boot/grub/menu.lst
...
kernel /vmlinuz-linux root=/dev/sda1 modprobe.blacklist=pcspkr,ipv6 ro
...
/boot/grub/menu.lst
...
kernel /vmlinuz-linux root=/dev/sda1 pcspkr.disable=1 ipv6.disable=1 ro
...

See also