- How to Use the lsmod and modinfo Commands in Linux
- What are Linux Kernel Modules (LKM)?
- List Kernel Modules with lsmod
- Display Information About a Linux Kernel Module with modinfo
- Conclusion
- Команда Lsmod в Linux (список модулей ядра)
- Модули ядра
- Команда lsmod
- Выводы
- lsmod Command in Linux | Explained
- How to Use lsmod Command in Linux?
- Syntax:
- Example 1: Displays the Active kernel Modules
- Example 2: Displays the Particular Active kernel Modules
- Conclusion
How to Use the lsmod and modinfo Commands in Linux
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
The Linux kernel is modular in nature, which means it’s possible to add and remove modules as needed. This makes for a lightweight, secure, and lightweight kernel. Its flexibility enables you to add and remove the features you need to make an operating system fit your use case and preferences.
It is important to inspect a Linux system’s kernel modules, especially when troubleshooting a hardware or software installation. For example, you may encounter an issue if a kernel module for a specific piece of hardware or software has not loaded. In this scenario, you use the lsmod command to view the available modules on your Linux system. If a module is loaded, you can further troubleshoot by listing out the details of the module. This is achieved using the modinfo command. This tutorial shows you how to use the lsmod and modinfo commands to inspect your Linux system’s kernel modules.
What are Linux Kernel Modules (LKM)?
Linux kernel modules are pieces of code that can be added to or removed from the Linux Kernel as required. Kernel modules often enable certain hardware or system features. Some modules are built directly into the kernel and cannot be removed. Loadable modules, on the other hand, can be added and removed without having to reboot your Linux system.
Loadable kernel modules allow you to extend the functionality of your system. Without modules, Linux would have to depend on a monolithic kernel which isn’t nearly as agile and secure. Another issue with a monolithic kernel is when new functionality is needed it must be built directly into the kernel image. This means the kernel is not only larger, but takes considerably longer to build. With monolithic kernels, every time new functionality is added, a system has to be rebooted.
Linux Kernel Modules are all stored in the /lib/modules directory. By keeping kernel modules housed in a centralized, local directory, it is more efficient to load and unload kernel modules. If you inspect the /lib/modules directory, you can find subdirectories for every kernel that has been installed on your system. For example, your Linux server might display the following installed kernels:
4.19.0-18-amd64 grub-2.04-19-linode.img
If you view the contents of one the kernel directory stored in the 4.19.0-18-amd64 directory, for example, you can view module files related to your system.
kernel modules.alias.bin modules.builtin.bin modules.dep.bin modules.order modules.symbols modules.alias modules.builtin modules.dep modules.devname modules.softdep modules.symbols.bin
List Kernel Modules with lsmod
The lsmod command stands for “list modules,” and lists out every loaded kernel module on a system. From a terminal, use the lsmod command to list all of your system’s kernel modules.
The output of the command can be very long and displays the output in three columns:
- Module — the name of the module.
- Size — the size of the module in bytes.
- Used by — how many instances of the module are in use and what system is using the module.
The example below displays what a system might return when you issue the lsmod command. The output displays every module that is loaded and the associated details.
Module Size Used by nfnetlink 16384 2 nf_conntrack_netlink xt_MASQUERADE 20480 1 nf_nat 49152 2 nft_chain_nat,xt_MASQUERADE nf_conntrack_netlink 49152 0 xfrm_user 40960 1 . .
The nfnetlink module displayed above is used as a transport layer for all user space communication of the netfilter subsystems. The module is 16,384 bytes in size and is used twice by the nf_conntrack_netlink system. This system enables support for a netlink-based user space interface. The lsmod command helps to identify this information about the nfnetlink module and can similarly provide information about all other modules installed on your Linux system.
Display Information About a Linux Kernel Module with modinfo
You can uncover even more information about a specific kernel module using the modinfo command. Continuing with the example above, you can view more information about the nfnetlink module, with the following command:
The output for the modinfo nfnetlink command displays the following information.
filename: /lib/modules/5.11.0-41-generic/kernel/net/netfilter/nfnetlink.ko description: Netfilter messages via netlink socket alias: net-pf-16-proto-12 author: Harald Welte license: GPL srcversion: EFA3D70B6EF087871934E84 depends: retpoline: Y intree: Y name: nfnetlink vermagic: 5.11.0-41-generic SMP mod_unload modversions sig_id: PKCS#7 signer: Build time autogenerated kernel key sig_key: 0A:76:69:99:20:71:05:D9:91:E8:8C:EC:C7:61:22:0B:A5:B5:70:EF sig_hashalgo: sha512 signature: 5F:F3:5C:6B:B4:7A.
- filename — the specific path housing the module (in this case, /lib/modules/5.11.0-41-generic/kernel/net/netfilter/nfnetlink.ko ).
- alias — the module alias used within the kernel.
- author — the author of the module.
- license — the module license.
- srcversion — the specific version of the module source.
- depends — any dependencies a module might have.
- retpoline — if the module is retpoline enabled.
- intree — if the module is maintained in the kernel Git repository
- name — the name of the module.
- vermagic — the version of the kernel module.
- sig_id, signer, sig_key, sig_hashalgo, and signature — all display information about the module’s key signature.
If the modinfo nfnetlink command displays too much information for your needs, you can specify which field you want to be displayed using the —field option. For example, if you only need to view the filename field, issue the following command:
modinfo --field filename nfnetlink
/lib/modules/5.11.0-41-generic/kernel/net/netfilter/nfnetlink.ko
By default, modinfo lists information for modules used by the current running kernel. You can also find information about a module for a specific kernel that may not be running on your system. Perhaps you want information about the nfnetlink module from the previous kernel. To do so, issue the following command:
modinfo -k 5.11.0-40-generic nfnetlink
The output for the above command only lists information for the module from the 5.11.0-40-generic kernel, instead of the currently running kernel.
Conclusion
Whenever you need information about a particular Linux kernel module, lsmod and modinfo are commands you can rely on. Using the combination of lsmod and modinfo , you can gather plenty of details for each available module. If you’re looking for more information on managing your Linux kernel, check out our Managing the Kernel on a Linode guide.
This page was originally published on Friday, January 7, 2022.
Команда Lsmod в Linux (список модулей ядра)
lsmod — это утилита командной строки, которая отображает информацию о загруженных модулях ядра Linux.
Модули ядра
Ядро — это основной компонент операционной системы. Он управляет ресурсами системы и является мостом между оборудованием и программным обеспечением вашего компьютера.
Ядро Linux имеет модульную конструкцию. Модуль ядра, или часто называемый драйвером, — это фрагмент кода, расширяющий функциональные возможности ядра. Модули либо скомпилированы как загружаемые модули, либо встроены в ядро. Загружаемые модули могут быть загружены и выгружены в работающем ядре по запросу без необходимости перезагрузки системы.
Обычно модули загружаются по запросу через udev (диспетчер устройств). Вы также можете вручную загрузить модуль в ядро с помощью команды modprobe или автоматически во время загрузки с помощью файлов /etc/modules или /etc/modules-load.d/*.conf .
Модули ядра хранятся в каталоге /lib/modules/ . Чтобы узнать версию работающего ядра , используйте команду uname -r .
Команда lsmod
lsmod — это простая утилита, которая не принимает никаких параметров или аргументов. Что делает команда, так это то, что она читает /proc/modules и отображает содержимое файла в хорошо отформатированном списке.
Запустите lsmod в командной строке, чтобы узнать, какие модули ядра загружены в данный момент:
Команда выводит информацию для каждого загруженного модуля ядра в новой строке:
Module Size Used by cmac 16384 0 rfcomm 81920 4 . ahci 40960 1 intel_lpss_pci 20480 0 i2c_i801 32768 0 libahci 32768 1 ahci intel_lpss 16384 1 intel_lpss_pci .
Каждая строка состоит из трех столбцов:
- Module — в первом столбце отображается имя модуля.
- Size — во втором столбце указан размер модуля в байтах.
- Used by — в третьем столбце отображается число, указывающее, сколько экземпляров модуля используется в настоящее время. Нулевое значение означает, что модуль не используется. Список, разделенный запятыми после номера, показывает, что использует модуль.
Чтобы узнать, загружен ли конкретный модуль, отфильтруйте вывод с помощью grep . Например, чтобы узнать, загружен ли модуль kvm вы должны запустить:
kvm_intel 278528 0 kvm 651264 1 kvm_intel irqbypass 16384 1 kvm
Для получения подробной информации о модуле используйте команду modinfo .
Выводы
Команда lsmod показывает список загруженных в настоящее время модулей ядра.
Не стесняйтесь оставлять комментарии, если у вас есть вопросы.
lsmod Command in Linux | Explained
The “lsmod” command is part of the GNU utility packages. Almost all the well-known Linux distributions support the “lsmod” command line utility. The main objective of the “lsmod” command is to figure out all the active loaded kernel modules on the system. The “lsmod” command cannot support arguments or options like other commands. However, it displays the loaded kernel modules in the output.
This post will provide a brief working and usage of the “lsmod” command in Linux.
How to Use lsmod Command in Linux?
The working of the “lsmod” command depends on its syntax. The generalized syntax of the “lsmod” command is written below:
Syntax:
To get complete information about the “lsmod” command, check its “man” page. This page can be displayed by using the below-mentioned command:
Example 1: Displays the Active kernel Modules
The “lsmod” command reads the content of the “/proc/modules” files and displays it in the well-organized format as compared to the “cat /proc/modules” command:
The output of the “lsmod” command displays three columns discussed below:
- Module: The first column shows the active kernel module “name”.
- Size: The second column displays the module sizes in “bytes”.
- Used by: The third column specifies how often the module is being used. The “zero” tells that the specific module is not used. While the “,(Comma)” after the number indicates any information about what uses that particular module. This information may be the “filesystem identifier” or the “device” name.
Example 2: Displays the Particular Active kernel Modules
To show the specific active kernel module if the entire system runs the “lsmod” command and “grep” command combined with the “|(pipe)” symbol:
The above output displays that the “drm” module is loaded into the system.
That’s all from the lsmod command.
Conclusion
The “lsmod” command shows the Linux kernel status and displays the list of loaded kernel modules. Furthermore, the “lsmod” shows the “/proc/modules” file content in a more generalized format. It displays what kernel modules are currently loaded. This guide has demonstrated the complete information about the “lsmod” command line utility.