Linux kernel module related commands: Lsmod,depmod,modprobe,modinfo,insmod,rmmod instructions for use

Source: Internet
Author: User
Tags syslog syslog error messages

The usual process for loading kernel drivers:

1. Copy the. ko file to/lib/module/' Uname-r ' (kernel version number)/kernel/driver/... Directory,

The differences are divided into NET, IDE, SCSI, USB, video, Parport, MD, block, ATA, etc. depending on the specific purpose.

2. Run depmod-a, update module dependent on new, mainly update MODULES.DEP file

3. Run Modprobe load kernel module

Lsmodfunction: Lists the status of the kernel loaded moduleUsage: Lsmod Description: Lsmod lists the contents of/proc/modules in an aesthetically pleasing manner. The output is: module (block name) size (module size) used by ... use) eg. Ne2k_pci 8928 08390 9472 1 ne2k_pci in/proc/modules corresponding is: (module name, module size, by ... Use, module address (guessed, later confirmed)) Ne2k_pci 8928 0–live 0x30864008390 9472 1 ne2k_pci, Live 0xe086000 Depmodfunction: Analyze the dependencies of loadable modules, generate MODULES.DEP files and mapping files。 Usage: depmod [-B basedir] [-e] [-f System.map] [-n] [-v] [version] [-a]depmod [-E] [-f System.map] [-n] [-v] [version] [filen Ame ...] Description: The Linux kernel module provides services for other modules (using Export_symbol in code), a service called "symbols". If the second module uses this symbol, the module is obviously dependent on the first module. These dependencies are very complex. Depmod reads all modules in the/lib/modules/version directory and checks each module for the exported symbol and required symbol, and then creates a list of dependencies. By default, the list is written to the Modules.dep file in the/lib/moudules/version directory. If the filename in the command is specified, only those specified modules are checked (not very useful). If the version parameter is provided in the command, the dependency is generated using the directory specified by version, not the current kernel version (Uname-r returns). Option:-B basedir–basedir Basedir If your module is not properly under/lib/mdules/version, you can specify the directory generation dependency. The-e–errsyms and-f options are used together, and when a module requires a symbol that is not available in other modules, a report is made. Normally, the symbol that is not provided by the module is available in the kernel. -f–filesyms System.map provides a system.map file (generated at kernel compile time) with the-e option to report unresolved symbol. -n–dry_run outputs the result MODULES.DEP and various mapping files to standard output (stdout) instead of writing to the module directory. -a–quick checks if there is a module newer than the module in MODUES.DEP, and if not, exits without regenerating the file. modprobefunction: Add delete module to Linux kernelUsage: modprobe [-v] [-v] [-c Config-file] [-n] [-i] [-Q] [-O modulename] [modulename] [module parameters ...] modprobe [-R] [-v] [-n] [-i] [modulename ...] modprobe [-L] [-t dirname] [wildcard]modprobe [-c] Description: Modprobe can intelligently add and remove Linux kernel modules (for simplicity, the module name ' _ ' and '-' are the same). Modprobe will view all modules and files in the module directory/lib/modules/' Uname-r ', in addition to the optional/etc/modprobe.conf configuration file and/ETC/MODPROBE.D directory. Modprobe needs an up-to-date MODULES.DEP file that can be generated using DEPMOD. This file lists the other modules required for each module, and Modprobe uses this to automatically add or remove dependencies for the module. Option:-v–verbose shows what the program is doing, usually in case of a problem, modprobe only displays the information. -c–config overload (^_^, meaning take the overload of C + +) default configuration file (/etc/modprobe.conf or/ETC/MODPROBE.D). -c–showconfig output configuration file and exit-n–dry-run can be used with the-v option, debugging is very useful-i–ignore-install–ignore-remove this option causes Modprobe to ignore the configuration file, The install and remove commands entered on the command line. -q–quiet General Modprobe When a module is deleted or inserted, a prompt error is not found. With this option, the specified module is ignored and no error message is prompted.-r–removeThis option causes Modprobe to be removed instead of inserting a module. There is usually no reason to remove the kernel module unless it is a bug-free module. Your kernel does not necessarily support the uninstallation of the module. -v–verssion version Information-f–force and use –force-vermagic, –force-modversion. Using this option is more dangerous.-l–listList all modules-a–all Insert all command-line modules-t–type Force-L display modules in DirName-s–syslog error messages to Syslog Modinfofunction: Display information of kernel moduleUsage: Modinfo [-0] [-f field] [ModuleName | filename ...] Modinfo-vmodinfo-h Description: Modinfo lists information about the modules specified by the command line in the Linux kernel. If the module name is not a file name, it will be searched in the/lib/modules/version directory, just like modprobe. Modinfo by default, for readability, each property of the module is listed in the following format: Fieldname:value. Option:-v–version version-f–field displays field values on only one line, which is useful for scripting. Commonly used field are: Author, description, licence, param, depends, alias, filename. -0–null uses the '/0′ character to separate field values instead of a new row. Useful for scripting. -a-d-l-p-N These are short forms of author, description, license, param, and filename. Insmodfunction: Inserting a module into the Linux kernelUsage: insmod [filename] [modue options ...] Description: Insmod is a small program that inserts a module into the kernel: If the file name is a hyphen '-', the module is entered from the standard input.Most users use modprobe because it is more intelligent. Rmmodfunction: Remove a module from the kernelUsage: Rmmod [-F] [-W] [-S] [-v] [modulename] Description: Rmmod is a small program that can remove modules from the kernel,Most users use Modprobe-r to remove modules. Options:-v–verbose shows what the program is doing and generally displays only error messages at execution time. -f–force This option is very dangerous: unless the kernel is compiled, Config_module_force_unload is set to be effective, otherwise it is ineffective. Use this option to delete a module that is being used, a module that cannot be deleted, or a module that is marked unsafe. -w–wait Typically, Rmmod refuses to delete the module that is being used. With this option, the specified module is orphaned until it is not used. -s–syslog writes error information to the syslog instead of the standard error (STDERR). -v–version Version Information

The above content is the reference man translation, if you have any questions please use man ... View the original document and the translation may be incorrect.

Other:

(1) LSMOD displays all modules currently loaded, equivalent to Cat/proc/modules,

If you do not set the boot load of a module, such as NTFS, then after the boot execution lsmod, the list will not have NTFS this module,

Then after you execute mount-t NTFS xxx, after executing lsmod, the list will have NTFS this module.
Also note that Lsmod displays the module name, not the alias.

(2) modprobe and Insmod

Modprobe-l #显示当前可以加载的模块

Modprobe Xxx.ko #加载某个模块
Modprobe-r Xxx.ko #卸载某个模块

By understanding Modprobe's manpage We know that I can show the modules that can now be loaded by modprobe-l, so-called modules that can now be loaded,

It's actually the modules that are contained in the MODULES.DEP file, not the manpage that modprobe will load all the modules under/lib/modules/' Uname-r ' (perhaps I understand the error), and we'll prove that.

    insmod and modprobe are both load kernel module, but the general difference is that modprobe can handle the dependency problem of module loading.

For example, if you are loading a module, but a module requires the system to load the B module, the error message will usually appear when the insmod is mounted directly, but Modprobe is able to know that loading the B module before loading a module, so the dependency will be satisfied.

But Modprobe is not a great God, not strong to know the dependencies between module, the program is read/LIB/MODULES/2.6.XX/MODULES.DEP file to know the dependencies. And the file is established through the DEPMOD program.

(3)Above (1) mentioned modprobe loading a module is based on the/lib/modules/' uname-r ' directory of the MODULES.DEP file in the module list, the file in which the module modprobe will be loaded correctly, otherwise there will be an error.
We also take the NTFS module for example:
vi/lib/modules/' Uname-r '/MODULES.DEP
Comment out/lib/modules/2.6.18-4-k7/kernel/fs/ntfs/ntfs.ko this line, is to add a # number.
This modification is even in effect.
Modinfo NTFS
Modinfo:could not find module NTFS
Modprobe NTFS
Fatal:module NTFS not found.
Restart the machine, execute the same command will get the same result, stating that the boot will not automatically perform depmod, and
< Span style= "line-height:20px;" >locate ntfs.ko
/lib/modules/2.6.18-4-k7/ KERNEL/FS/NTFS/NTFS.KO
prove that we did not transfer the NTFS module.
Note If mount is OK before restarting the machine, the reboot will cause an error, and the top is immediately effective.
It's all just because we commented out Modules.dep's line about Ntfs.ko, and the module didn't delete or move. Since the MODULES.DEP file is so important, how is it generated? This is about the next order, Depmod.

(4) Depmod

Mans Depmod
Depmod-Program to generate MODULES.DEP and map files. Blank lines, and lines starting with a ' # ' (ignoring spaces) is ignored in MODULES.DEP.
Depmod is a program used to generate MODULES.DEP and map files. Blank lines in the Modules.dep file and lines beginning with ' # ' are ignored.

Linux kernel modules can provide services (called "symbols") for other
Modules to use (using Export_symbol in the code).
Linux core modules can provide services to other modules, called "Symbols"

Depmod creates a list of module dependencies, by reading each module
Under/lib/modules/version and determining what symbols it exports, and
What symbols it needs.
Depmod Create a record module dependency by reading each module in the/lib/modules/version directory
The list. This list is the MODULES.DEP in the/lib/modules/version directory.

If A version is provided, then that kernel version ' s module directory
is used, rather than the current kernel version (as returned by "uname
-R ").
If given version, then Depmod will check the modules directory for this version instead of
The modules directory that corresponds to the currently running kernel.

Depmod would also generate various map files in this directory
By the HotPlug infrastructure.
Depmod will also create many map files in the/lib/modules/version directory, which will be used by HotPlug.

OPTIONS:
-a--all  probe  all  modules.  This option is Enabled by default if NO
            file names is given in the COMMAND-LINE.
check all the modules, this command is the default if you don't specify the module name.

-a--quick  This option scans the see if any modules are  newer  than  the
                  MODULES.DEP file before any work is done%3

Linux kernel module related commands: Lsmod,depmod,modprobe,modinfo,insmod,rmmod instructions for use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.