Introduction to insmod and modprobe in linux, insmodmodprobe

Source: Internet
Author: User

Introduction to insmod and modprobe in linux, insmodmodprobe

Both insmod and modprobe load the kernel module, but the difference is that modprobe can handle the dependency issue of module loading.

For example, you want to load module a. However, when the system first loads module B, an error message is usually displayed when you directly use insmod to mount module, however, modprobe can know that loading module B before loading module a will satisfy the dependency.

However, modprobe is not a great idea, and it won't be so powerful as to know the dependency between modules. This program reads the/lib/modules/2.6.xx/modules. dep file to know the dependency. This file is created through the depmod program.

Modinfo ip_nat_ftp

1. What is the kernel;

The kernel uses kernel in English. I just flipped through the dictionary. The Chinese meaning of kernel is kernel, core, center, and essence. It also means nuts and fruit cores. Literally speaking, kernel is the center of a thing, and the fruit of a plant is also the fruit kernel and the fruit kernel; :) From this we can infer that the kernel is the center of the operating system.

We know that Linus Torvalds has developed Linux. In fact, he has developed the kernel. According to the official kernel homepage, this kernel is Linux. Other extensions and applications are developed around the kernel. All Linux applications will have direct or indirect contact with the kernel. For example, hardware requires Kernel support and network communication requires Kernel support. file systems require Kernel support more ......

Bluntly, my capabilities are not good. If you want to understand and learn about the operating system, the tutorials I wrote are only basic applications. The theoretical things are not clear in a single word, it is not clear to the application.

Ii. Why should we compile and manage the kernel?

Hardware requires Kernel support. Some hardware support is not compiled into the kernel, which also requires us to re-compile the kernel. The kernel includes not only the driver of the device, but also other content, for example, support for network protocols and firewall ...... for example, the implementation of iptables requires Kernel support. If the kernel and iptables-related content are not compiled, iptables-related functions cannot be implemented;

Iii. kernel Compilation Method

For details, refer to compile the kernel operation process-as a beginner's guide.

4. Manage commands of the kernel module

1. Kernel Modules mounted in the lsmod column;

Lsmod lists the names and sizes of loaded modules in the current system. In addition, we can also view/proc/modules. We can also know the loaded modules of the system;

[Root @ localhost beinan] # lsmod

2. modinfo: View module information;

Modinfo can view the module information and determine the purpose of the module by viewing the module information;

[Root @ localhost beinan] # moinfo Module name

Example:

[Root @ localhost beinan] # modinfo ne2k-pci

Filename:/lib/modules/2.6.11-1.1369 _ FC4/kernel/drivers/net/ne2k-pci.ko

Author: Donald Becker/Paul Gortmaker

Description: PCI NE2000 clone driver

License: GPL

Parmtype: debug: int

Parmtype: options: array of int

Parmtype: full_duplex: array of int

Parm: debug level (1-2)

Parm: options: Bit 5: full duplex

Parm: full_duplex: full duplex setting (s) (1)

Vermagic: 2.6.11-1.1369 _ FC4 686 REGPARM 4 KSTACKS gcc-4.0

Depends: 8390

Alias: pci: v201710ecd1168029sv * sd * bc * SC * I *

Alias: pci: vda-1050d00000940sv * sd * bc * SC * I *

Alias: pci: v201711f6d20171401sv * sd * bc * SC * I *

Alias: pci: vda-8e2ed1_3000sv * sd * bc * SC * I *

Alias: pci: vda-4a14dda-5000sv * sd * bc * SC * I *

Alias: pci: v20171106d00000926sv * sd * bc * SC * I *

Alias: pci: vda-10bdd00000e34sv * sd * bc * SC * I *

Alias: pci: v20171050d20175a5asv * sd * bc * SC * I *

Alias: pci: v201712c3d00000058sv * sd * bc * SC * I *

Alias: pci: v201712c3d20175598sv * sd * bc * SC * I *

Alias: pci: v20178c4ad20171980sv * sd * bc * SC * I *

Srcversion: 6ACE95F441CD26DF9DC31C2

The above example is we view the information of this module ne2k-pci, through view, we know that the ne2k-pci module is 8029 NIC (PCI NE2000 clone driver) driver; the module is located in the/lib/modules/2.6.11-1.1369 _ FC4/kernel/drivers/net/ne2k-pci.ko

We currently use 8139 of commonly used NICs, and 8139 of NICs use 8139too drivers?

[Root @ localhost beinan] # modinfo 8139too

Check the vfat and ntfs module information;

[Root @ localhost beinan] # modinfo vfat

[Root @ localhost beinan] # modinfo ntfs

Try it yourself;

Note: The Module name cannot contain a suffix. The modules we see through modprobe-l are all with. ko or. o suffixes;

3. modprobe mounts new modules and modules dependent on the new modules.

Modprobe our common function is to mount a module. When a kernel module is mounted, the modules on which this module depends are also mounted. Of course, modprobe also lists all kernel modules, the module removal function is more available. Next we will give an example to illustrate our common functions and parameters;

Modprobe [-v] [-V] [-C config-file] [-n] [-I] [-q] [-o] [parameters...]

Modprobe-r [-n] [-I] [-v]...

Modprobe-l-t [-a...]

The above is the usage of modprobe. For more detailed help, we can view man modprobe;

[Root @ localhost beinan] # modprobe-c

Modprobe-c can view the configuration file of modules, such as the module alias;

[Root @ localhost beinan] # modprobe-l

Modprobe-l is used to list all modules in the kernel, including mounted and unmounted modules. Through modprobe-l, we can view the modules we need and mount them according to our needs; in fact, the list of modules read by modprobe-l is located in the/lib/modules/'uname-R' directory, where uname-r is the kernel version;

[Root @ localhost beinan] # uname-r

2.6.11-1.1369 _ FC4

[Root @ localhost beinan] # ls/lib/modules/2.6.11-1.1369 _ FC4/

Through the above command, try it yourself?

[Root @ localhost beinan] # modprobe Module name Note: mount a module;

Example:

[Root @ localhost beinan] # modprobe ne2k-pci Note: mount the ne2k-pci module;

[Root @ localhost beinan] # modprobe vfat Note: mount the vfat Module

[Root @ localhost beinan] # modprobe ntfs Note: mount the ntfs Module

[Root @ localhost beinan] # lsmod Note: List mounted modules, we will see the ne2k-pci, vfat, ntfs modules;

Note: The Module name cannot contain a suffix. The modules we see through modprobe-l are all with. ko or. o suffixes;

[Root @ localhost beinan] # modprobe-r module name Note: remove the loaded module, which has the same function as rmmod;

Note: The Module name cannot contain a suffix. The modules we see through modprobe-l are all with. ko or. o suffixes;

[Root @ localhost beinan] # modprobe-r module name

Example:

[Root @ localhost beinan] # modprobe-r ne2k-pci

Let's just talk about it. For more details, use man modprobe to view and try it;

4. rmmod removed the mounted modules;

Command Format:

Rmmod Module name

Note: The Module name cannot contain a suffix. The modules we see through modprobe-l are all with. ko or. o suffixes;

Example:

[Root @ localhost beinan] # rmmod vfat Note: remove the mounted module vfat

5. depmod: List of module dependencies created

This module management tool is used to create a list of module dependencies. Just pay attention to a few parameters. Currently, the Linux release uses the kernel version 2.6x to automatically resolve dependencies, this command is fine. The module also has dependencies before. For example, if we want to drive a USB mobile hard disk, there are currently two types of drivers: udev, which are available in the kernel, however, it is not stable at present. Another method is to use the usb-storage driver, while the usb-storage depends on the scsi module. Therefore, we need to use the usb-storage module, you also need to compile and install scsi;

Another example is the sata hard disk. in Linux, the device represents/dev/sd *, for example,/dev/sda,/dev/sdb... to drive a sata hard disk, You need to select sata in the kernel, compile it into a module, or build it into the kernel. At the same time, you need to select the ide in the kernel, scsi support;

Depmod program to generate modules. dep and map files)

[Root @ localhost beinan] # depmod-a NOTE: For all columns in/etc/modprobe. conf or/etc/modules. create dependencies between all modules in conf and write them to modules. dep file;

[Root @ localhost beinan] # depmod-e Note: Lists mounted but unavailable modules;

[Root @ localhost beinan] # depmod-n Note: lists the dependencies of all modules, but only outputs (Write the dependency file on stdout only)

Note: modules. dep is located in the/lib/modules/kernel version directory.

For example, in Fedora Core 4.0, the default system kernel:

[Root @ localhost beinan] # ls/lib/modules/2.6.11-1.1369 _ FC4/modules. dep

/Lib/modules/2.6.11-1.1369 _ FC4/modules. dep

6. insmod mounting module;

The insmod tool is a bit similar to modprobe, but it does not have a strong modprobe function. In the Mount module, modprobe does not need to specify the path of the module file or the suffix of the file. o or. ko; what insmod needs is the absolute path of the directory where the module is located, and must contain the module File name suffix (modulefile. o or modulesfile. ko );

For this tool, we will only introduce it and it is not recommended. Because the module has dependency, you may not know which module the module depends on;

Example:

[Root @ localhost beinan] # insmod/lib/modules/2.6.11-1.1369 _ FC4/kernel/drivers/net/tg3.ko

We need to find the corresponding module in the Command output/lib/modules/kernel version uname-r/kernel/drivers. There must be an absolute path, the full name of the file name must be used, and the suffix of the file name cannot be omitted;

5. The configuration files related to kernel module loading;

1. The module configuration file modules. conf or modprobe. conf

The automatic mounting module of the kernel module is usually located in a setup file. The common Linux releases include/etc/modules. conf or/etc/modprobe. conf. For example, the file automatically loaded by the Fedora Core 4.0 kernel module upon startup is/etc/modprobe. conf; in this file, it is generally written to the module's load command or module alias definition. For example, in modules. A similar line may be released in conf;

Alias eth0 8139too

/// Response ///-----------------------------------------------------------------------------------------------------------------------

KERNELRELEASE definition, Linux $ (KERNELRELEASE)

Recently with the friendly arm of the board, found that the kernel name is: Linux-2.6.29.4-FriendlyARM. The rear of the FriendlyARM can not go away. Later I had to read the code.

1. 2.6.29.4 this version number is added by uboot during uimage creation. For details, refer to arch/arm/boot/Makefile:

Quiet_pai_uimage = UIMAGE $ @

Export _uimage = $ (CONFIG_SHELL) $ (MKIMAGE)-A arm-O linux-T kernel/

-C none-a $ (LOADADDR)-e $ (LOADADDR )/

-N'linux-$ (KERNELRELEASE) '-d $ <$ @

2. For comparison, 2.6.29.4-FriendlyARM is $ (KERNELRELEASE). Therefore, we need to find out how to define $ (KERNELRELEASE.

3. You can find the definition of $ (KERNELRELEASE) in include/config/kernel. release in the search. However, after the change, make again and there is FriendlyARM.

4. Check the makefile on the top layer of the kernel. About 872 lines are described as follows:

# Build the kernel release string

...

# $ (Localver-auto) (only if CONFIG_LOCALVERSION_AUTO is set)

#./Scripts/setlocalversion (SCM tag, if one exists)

# $ (LOCALVERSION) (from make command line if provided)

After careful comparison, the original FriendlyARM is $ (LOCALVERSION )!, After searching, we found that autoconf. h is available. Haha, This is the kernel graphic configuration.

5. make menuconfig right away and search for $ (LOCALVERSION). Hey, it turns out to be in Gernel Setup..., remove it immediately and re-compile it. No!

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.