Linux device driver Load/unload methods Insmod and Modprobe commands

Source: Internet
Author: User
Tags system log

There are two ways to load/unload a Linux drive.

1.modprobe

Note: Use the DEPMOD-A command to generate the Modules.dep file before loading the module with this command, which is located in the/lib/modules/$ (uname-r) directory;
The modprobe command intelligently loads modules into the kernel or removes modules from the kernel, either loading the specified individual modules or loading a set of dependent modules. Modprobe will decide which modules to load based on the dependencies that the depmod generates. If an error occurs during onboarding, modprobe uninstalls the entire set of modules.

Commands to load modules:
(1) loading the specified module: modprobe drv.ko
(2) Loading all modules: modprobe-a

command to unload the module: Modprobe-r Drv.ko

The modprobe command is used to intelligently load modules into the kernel or remove modules from the kernel.

The modprobe can load the specified individual modules, or load a set of dependent modules. Modprobe will determine which modules to load based on the dependencies that the depmod generates. If an error occurs during onboarding, the entire set of modules is unloaded at modprobe.

Options

-A or--all: Load all modules;

-C or--show-conf: Displays the setup information for all modules;

-D or--debug: Use the debug mode;

-L or--list: Displays the available modules;

-R or--remove: when the module is idle, the module is unloaded automatically;

-T or--type: Specifies the module type;

-V or--verbose: Displays detailed information when executed;

-V or--version: Displays version information;

-help: Displays Help.

Argument Module Name: The name of the module to load or remove.

Instance

to view the configuration file for modules:

Modprobe-c

Here, you can view modules's configuration files, such as what the alias alias of the module is. Will print a number of line information, such as a line like this:

Alias Symbol:ip_conntrack_unregister_notifier Ip_conntrack

list all modules in the kernel that have been or are not mounted:

Modprobe-l

Here, we can look at the modules we need and then mount them according to our needs; the list of modules that Modprobe-l reads is located in the/lib/modules/' uname-r ' directory, where Uname-r is the kernel version, such as one of the output results:

/lib/modules/2.6.18-348.6.1.el5/kernel/net/netfilter/xt_statistic.ko

To mount the VFAT module:

Modprobe VFAT

Here, use the Format modprobe module name to mount a module. After mounting, you can use Lsmod to view the modules that have been mounted. Module names cannot have suffixes, and the modules we see through Modprobe-l are all with a. ko or. o suffix.

to remove a module that has already been loaded:

MODPROBE-R Module Name

Here, the loaded module is removed and the Rmmod function is the same.

2. Insmod/rmmod

The insmod needs to specify the absolute path of the module, unlike Modprobe, Insmod and does not load the module's dependent modules into it.
Usage: Insmod Drv.ko

Rmmod only need the name of the module to implement the module unloading, also does not have to unload the module of the dependency module to unload.
Usage: Rmmod Drv.ko

Lsmod: Displays the modules that are loaded into the system

Insmod (Install Module)

Function Description: Load module install loadable kernel module

Syntax: Insmod [-fkmpsvxx][-o < module name >][module file] [symbol name = symbol value]

Parameters:

-F does not check that the current kernel version is consistent with the kernel version at the time of module compilation, forcing the module to be loaded.
-K Sets the module to dismount automatically.
-M output module loading information.
-O < module name > Specifies the name of the module, which can be used with the file name of the module file.
Is the-P test module correctly loaded into the kernel.
-S records all information in the system log file.
-V displays detailed information when executed.
-X do not export the external symbols of the module.
-X sinks all external symbols of the module, which are pre-set.

Instructions for use: Linux has a number of features that can be loaded into the kernel, as needed, by way of a module. This allows the kernel to be streamlined, thus improving efficiency and maintaining greater flexibility. This type of module, which can be loaded, is usually a device driver.

The Insmod command is primarily used to load Linux kernel module commands before the Linux 2.4 kernel. For Linux kernel modules loaded with this command, the system does not automatically resolve dependencies between kernel modules, but also requires that the module path be written in detail. So when the Linux 2.6 kernel appeared, this command was gradually forgotten.

Load the RAID1 array level module as follows:

[Email protected] boot]# insmod/lib/modules/2.6.

18-8.el5/kernel/drivers/md/raID1.ko

[[email protected] boot]# lsmod | grep RAID1

RAID1 25153 0

From the results shown above, the RAID1 module has been successfully loaded. Only when the module is loaded with the Insmod command, an absolute path is required to load, and the dependency cannot be resolved automatically at load time.

Extended reading: The difference between Insmod and modprobe

Both Insmod and modprobe are loaded into the 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.

Linux device driver Load/unload methods Insmod and Modprobe commands

Related Article

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.