- Linux lsmod command
- Description
- Syntax
- Examples
- Related commands
- Команда Lsmod в Linux (список модулей ядра)
- Модули ядра
- Команда lsmod
- Выводы
- modprobe, lsmod, modinfo Command Tutorial With Examples To Load, List Linux Kernel Modules
- List Available Kernel Modules
- List Loaded Modules
- Get Information About Kernel Module
- Load or Install New Kernel Modules
- Remove or Unload Loaded Kernel Module
- Команда Lsmod в Linux (список модулей ядра)
- Модули ядра
- Команда lsmod
- 8 lsmod, rmmod, modprobe, and modinfo command examples in Linux
- What is Linux Kernel?
- What are types of Kernel?
- What is a Kernel module?
- What is a Monolithic kernel?
- What is a Modular kernel?
- How to see module loaded into the kernel?
- How to load Kernel modules in Linux?
Linux lsmod command
On Linux operating systems, the lsmod command lists the status of modules inserted in the kernel.
Description
Linux kernel modules, or LKMs, are system-level software used directly by operating system kernel. They can be inserted into the kernel and activated without the system needing to be rebooted.
lsmod has no options. It formats the contents of the file /proc/modules, which contains information about the status of all currently-loaded LKMs.
Syntax
Examples
To list all active kernel modules, run lsmod at the command line:
This is essentially the same as running «cat /proc/modules«, but the information is formatted a little nicer. You see three columns of information:
- Module: the name of the module. This is usually the name of the module file, minus the extension (.o or .ko), but it may have a custom name, which can be specified as an option when the module is inserted with the insmod command.
- Size: the amount of memory used by the resident module, in bytes.
- Used by: This column contains a number representing how many instances of the module are being used. If the number is zero, the module is not currently being used. Text after the number represents any available information about what uses the module: this is commonly a device name, a filesystem identifier, or the name of another module.
Output of lsmod resembles the following:
Related commands
depmod — Generate a list of kernel module dependencies and associated map files.
insmod — Insert a module into the Linux kernel.
modinfo — Show information about a Linux kernel module.
modprobe — Add and remove modules from the Linux kernel.
rmmod — Remove a module from the Linux kernel.
Источник
Команда 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 — в третьем столбце отображается число, указывающее, сколько экземпляров модуля используется в настоящее время. Нулевое значение означает, что модуль не используется. Список, разделенный запятыми после номера, показывает, что использует модуль.
Чтобы узнать, загружен ли конкретный модуль, отфильтруйте вывод с помощью grep . Например, чтобы узнать, загружен ли модуль kvm вы должны запустить:
Для получения подробной информации о модуле используйте команду modinfo .
Выводы
Команда lsmod показывает список загруженных в настоящее время модулей ядра.
Не стесняйтесь оставлять комментарии, если у вас есть вопросы.
Источник
modprobe, lsmod, modinfo Command Tutorial With Examples To Load, List Linux Kernel Modules
What makes an Operating system Linux Distribution? All Linux distributions use same kernel named Linux Kernel. Linux kernel provides operating system services, hardware management, process management, memory management etc.
Linux kernel is a monolithic kernel which means single executable all in one. But the operating systems should provide dynamic environments to comply user needs. Linux provides mechanism to load some drivers, features etc. This is called kernel modules. In this tutorial we will look kernel modules operations with modprobe command. Most of the examples in this tutorial requires root privileges.
List Available Kernel Modules
Linux kernel came with a lot of default kernel modules. These modules are loaded according to requirements and kernel config provided by the distribution. There is also an option to add new kernel modules externally to the Linux. We can list all of these modules with lsmod command
List Available Kernel Modules
List Available Kernel Modules
List Loaded Modules
As we know kernel modules are loaded or unloaded. We can list only installed kernel modules by using previous command. but in this command we need some external help. We will use egrep to filter installed kernel modules.
List Loaded Modules
Get Information About Kernel Module
Kernel modules can get different parameter for configuration purposes. Also there are different type of information. Here are some of them which can be listed with modinfo command.
- filename what is modules file name and the path
- license modules license type like GPL,GPL2,Apache,TM
- description short description about the kernel module
- depends specify what other kernel modules are needed to load this module
- intree specify if this kernel module is maintained in kernel git repository
- vermagic specifies the version of the kernel module
- parm specifies parameter that can be used to configure this kernel module.
Get Information About Kernel Module
Load or Install New Kernel Modules
Generally Linux operating system automatically loads related kernel modules. There is no need to load them manually in most situations. But some times manual operation may be needed to load kernel modules. We will install module named ipx by using insmod in this example.
Remove or Unload Loaded Kernel Module
We can remove kernel modules. We will use modprobe command again with -r option by providing the kernel module name. In this example we unload ipx kernel module
Источник
Команда 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 – Третий столбец показывает число, которое указывает, сколько экземпляров модуля используется в настоящее время. Нулевое значение означает, что модуль не используется. Разделенный запятыми список после числа показывает, что использует модуль.
Чтобы узнать, загружен ли конкретный модуль, отфильтруйте вывод с помощью команды grep. Например, чтобы узнать, загружен ли модуль kvm, вы должны выполнить:
Для получения подробной информации о модуле используйте команду modinfo.
Источник
8 lsmod, rmmod, modprobe, and modinfo command examples in Linux
Posted by Sahil Suri | Nov 1, 2017 | Basics | 0 |
lsmod, rmmod, modprobe, and modinfo commands
What is Linux Kernel?
The kernel is just a piece of code. Ok, not a bit of code 1000’s of lines. For example, Linux kernel has 20 million lines of code. A kernel is a central part of computer operating system which acts as a mediator between system hardware and applications installed in the system. The Kernel converts program’s instructions to machine understandable language and passes them through device drivers.
What are types of Kernel?
We have two types of Kernels are there.
- Monolithic kernel
- Modular kernel
Before going into difference of kernels we should know what is a kernel module is
What is a Kernel module?
A kernel module is a part of the kernel which can do some work. Say for example Linux Kernel will not support all types of hardware, So programmers will write some kernel modules and distribute them along with their software. Whenever you want to make this hardware to work, we have to load this piece of software into the kernel so that your system understands it. This software is nothing but Kernel module. The modules also referred to as device drivers are specialized pieces of software which power or control access to a peripheral. They are loaded into or unloaded from the running kernel without the need of a reboot.
What is a Monolithic kernel?
A monolithic kernel is where the entire operating system works in kernel space. There is no such space called User space where you can load/remove kernel modules from userspace. In other words, entire device drivers, Filesystem, and IPC will work in kernel space.
What is a Modular kernel?
A modular kernel is where only a particular part of OS is loaded into kernel space. In this way, we will reduce the burden on the system as we can load kernel modules into kernel where and whenever it is required. And the services will run complete isolation from Kernel space.
The /proc/devices file contains a mapping of the device major numbers and device types broadly classified as character and block devices. The kernel gains access to these devices through the corresponding module provided that it has been loaded correctly. Given below is a snippet of the content contained in this file.
The number on the left is the primary number of the module which is used internally by the kernel to identify the peripheral type and the names to the right of the number represent the device type.
The /proc/modules file contains a list of currently loaded modules. Here’s a snippet from the file:
The name in the leftmost/first column in the file represents the module name.
We could go to /sys/module/ directory to view the files that hold the settings for the driver.
Example 1: To view the corresponding files for the SCSI disk driver represented by sd_mod module, I could head to the /sys/module/sd_mod directory.
How to see module loaded into the kernel?
Example 2: If we open the initstate and rhelversion files they show that the module is loaded indicated by “live” and the OS for which it’s been loaded is 7.3
To manage kernel modules, we use the lsmod and modprobe commands.
We can add specific options to the modules to customize external access. These options can be configured in the /etc/modprobe.d directory.
Example 3: We use the lsmod command to list currently loaded drivers. This command actually obtains its data from the /proc/modules file.
Example 4: To filter out for a specific module we can use AWK command as shown below.
[root@linuxnix
Module Size Used by
sd_mod 46322 3
The size column indicates the amount of memory used by the module in bytes and the used by field indicates the number of modules that are dependent on this module is loaded.
How to load Kernel modules in Linux?
Now I’ll demonstrate how we could load and unload modules using modprobe. For this demonstration, I’ll be using the sr_mod module which is used to access the cd drive.
I won’t be working with the sd_mod module here because whatever happens we don’t unload sd_mod and probably lose access to the disks attached to the system.
Example 5: We use modprobe with the -r option to unload a module. We can add the -v option for verbose output.
Now if I search for this module in lsmod output or /proc/modules I won’t find it because we’ve just unloaded it.
At this point, we’ve lost access to our cdrom peripheral.
Example 6: To load the module type modporbe followed by the module name. You may add the -v flag for verbose output.
With that, the module has been loaded, and we have regained access to the systems’ cdrom.
You may have observed from the above Example 5 demonstrated modprobe command is calling rmmod to unload a module and insmod to load a module. You may use these commands directly as well.
Example 7: We can use the modinfo command to obtain some descriptive information about the module. Given below is the output obtained by running the modinfo command for the sd_mod module.
Example 8: Here is another example of using modinfo this time using the dm_mod module which is the device mapper module.
The fields that are present in the above output are actually the parameters which can be tweaked while loading the modules.
This concludes our exploration of kernel modules in Linux. I hope this has been an interesting read for you.
Источник