Difference between revisions of "Kernel modules (Русский)"

From ArchWiki
Jump to: navigation, search
(See also)
(Using kernel command line)
Line 135: Line 135:
==== Using kernel command line ====
==== Using kernel command line ====
{{Tip|This can be very useful if a broken module makes it impossible to boot your system.}}
{{Tip (Русский)|This can be very useful if a broken module makes it impossible to boot your system.}}
You can also blacklist modules from the bootloader.
You can also blacklist modules from the bootloader.

Revision as of 00:24, 6 November 2014

zh-CN:Kernel modules

Tango-preferences-desktop-locale.pngЭта страница нуждается в сопроводителеTango-preferences-desktop-locale.png

Статья не гарантирует актуальность информации. Помогите русскоязычному сообществу поддержкой подобных страниц. См. Команда переводчиков ArchWiki

Модули ядра — это отдельные кусочки кода, которые могут быть загружены и выгружены в ядро по мере необходимости. Они расширяют функциональность ядра без необходимости перезагрузки системы.


Чтобы создать модуль ядра, вы можете прочитать The Linux Kernel Module Programming Guide. Модуль можно сконфигурировать как вкомпилированный, а можно как загружаемый. Чтобы иметь возможность динамически загружать или выгружать модуль, его необходимо сконфигурировать как загружаемый модуль в настройке ядра (в этом случае строка, относящаяся к модулю должна быть отмечена буквой M).

Модули хранятся в /usr/lib/modules/kernel_release. Чтобы узнать текущую версию вашего ядра, используйте команду uname -r.

Примечание: Часто в названии модулей используются подчёркивания (_) или дефисы (-); однако, эти символы взаимозаменяемы как при использовании команды modprobe, так и в конфигурационных файлах в /etc/modprobe.d/.

Получение информации

Чтобы узнать, какие модули ядра загружены в настоящий момент:

$ lsmod

Чтобы показать информацию о модуле:

$ modinfo module_name

Чтобы вывести список опций, с которыми загружен модуль:

$ systool -v -m module_name

Чтобы отобразить настройки для всех модулей:

$ modprobe -c | less

Чтобы отобразить настройки для отдельного модуля:

$ modprobe -c | grep module_name

Чтобы узнать зависимости модуля (или его псевдонима), включая сам модуль:

$ modprobe --show-depends module_name


Today, all necessary module loading is handled automatically by udev, so if you do not want or 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.


Extra kernel modules to be loaded during boot are configured as a static list in files under /etc/modules-load.d/. Each configuration file is named in the style of /etc/modules-load.d/<program>.conf. Configuration files simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored.

# Load virtio-net.ko at boot

См. также modules-load.d(5).

Setting module options

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

Using files in /etc/modprobe.d/

Files in /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. Configuration files in this directory can have any name, given that they end with the .conf extension. The syntax is:

options modname parametername=parametervalue

For example:

# On ThinkPads, this lets the 'thinkfan' daemon control fan speed
options thinkpad_acpi fan_control=1
Примечание: If any of the affected modules is loaded from the initramfs, then you will need to add the appropriate .conf file to FILES in /etc/mkinitcpio.conf or use the modconf hook, so that it will be included in the initramfs.

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:


For example:


Simply add this to your bootloader's kernel-line, as described in Kernel Parameters.


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:

alias mymod really_long_module_name

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.

# Prevent Bluetooth autoload
alias net-pf-31 off

Запрет загрузки

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 automatically detected 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. filesystems hook, block hook, etc.). Remember to add that .conf file to the FILES section in /etc/mkinitcpio.conf, if you have not done so already, and rebuild the initramfs once you have blacklisted the modules, and reboot afterwards.

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:

# Do not load the 'pcspkr' module on boot.
blacklist pcspkr
Примечание: 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:

install module_name /bin/false
This will effectively blacklist that module and any other that depends on it.

Using kernel command line

Совет: This can be very useful if a broken module makes it impossible to boot your system.

You can also blacklist modules from the bootloader.

Simply add modprobe.blacklist=modname1,modname2,modname3 to your bootloader's kernel line, as described in Kernel parameters.

Примечание: 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.

Загрузка модуля вручную

Kernel modules are handled by tools provided by kmod package. You can use these tools manually.

Примечание: If you updated your kernel via pacman without rebooting, modprobe may fail silently when the /lib/modules/$(uname -r)/ directory does not exist. Consider checking for this directory manually, or checking the exit code of the modprobe command, if this case applies to you.

Загрузка модуля:

# modprobe module_name

Загрузка модуля из другого места (для тех модулей, которых нет в /lib/modules/$(uname -r)/):

# insmod filename [args]

Выгрузка модуля:

# modprobe -r module_name

Альтернативный вариант выгрузки модуля:

# rmmod module_name