Kernel module Management)

Source: Internet
Author: User
Kernel and kernel module

After talking about the entire startup process, you should know whether the hardware configuration of our host can be successfully driven during the entire startup process. It is the work of the kernel! The kernel is usually a compression file. Therefore, before using the kernel, You have to decompress it before loading the main memory.

In addition, to cope with the ever-changing hardware, the current kernel has a "readable modular driver"Program", That is, the so-called" modular "function! The so-called modularization can think of him as a "plug-in program". The plug-in program may be provided by hardware developers, or our kernel may have been supported ~ However, newer hardware usually requires hardware developers to provide driver modules!

So where are the kernel and kernel modules?

    • Kernel:/boot/vmlinuz or/boot/vmlinuz-version;
    • RAM disk required for Kernel decompression:/boot/initrd (/boot/initrd-version );
    • Kernel module:/lib/modules/version/kernel or/lib/modules/$ (uname-R)/kernel;
    • Original kernel code:/usr/src/Linux or/usr/src/kernels)

If the kernel is smoothly loaded into the system, there will be several records:

    • Kernel version:/proc/version
    • System kernel functions:/proc/sys/kernel

If I have a new hardware, but my operating system does not support it, what should I do? Easy!

    • Recompile the kernel and add the latest hardware driver original code;
    • Compile the hardware driver into a module and load the module at startup.

The first point above is very easy to understand. It is just to re-compile the kernel. However, it is not easy to compile the kernel!

 

Depmod

Now that we want to process kernel modules, we naturally need to understand the relevance between modules provided by our kernel! Basically, the kernel module is placed in/lib/modules/$ (uname-R)/kernel, which is mainly divided into several directories:

 
Arch: a project related to the hardware platform, such as the CPU level. crypto: the encryption technology supported by the kernel, such as MD5 or des. Drivers: some hardware drivers, for example, video card, network card, and PCI-related hardware; FS: filesystems supported by the kernel, such as vfat, reiserfs, and NFS; LIB: some library; Net: network-related protocol data, as well as the firewall module (net/IPv4/Netfilter/*Sound: The modules related to sound effects;

 

If we want to check the main information of these modules one by one and define their dependencies, we may go crazy! Therefore, our Linux certainly provides some module dependency solutions ~ Yes! Check/Lib/modules/$ (uname-R)/modules. DepThis file! It records the dependencies of modules supported by the kernel.

How to create this file? Easy! You can use the depmod command to create the file!

[Root @ WWW ~] # Depmod [-Ane] Options and parameters:-A: When no parameters are added, depmod will analyze the current kernel modules and write them again./Lib/modules/$ (Uname-R)/modules. Dep. If-When a parameter is set, depmod searches for modules that are newer than those in modules. Dep. If a new module is found, the module is upgraded.-N: output the result to the screen (Standard out) instead of writing modules. Dep );-E: The loaded Module name is displayed. Example 1: If I have a network card driver named A. Ko, how can I upgrade the kernel dependency? [Root @ WWW~] #CPA. Ko/lib/modules/$ (Uname-R)/kernel/Drivers/Net [root @ WWW~] # Depmod

In the preceding example, the kernel module extension of Linux kernel 2.6.x must be. after you use depmod, the program runs to the standard module directory/lib/modules/$ (uname-R)/kernel, all modules are captured for analysis based on the definition of the relevant directory, and the analysis results are written to modules. in the DEP file! This file is very important! Because it will affect what this chapter will introduce later.ModprobeCommand application!

 

Lsmod

Do you know how many modules are loaded in the kernel? Use lsmod!

[Root @ WWW ~] # Lsmod  Module size used byautofs4  24517    2  Hidp  23105    2  ... (Omitted in the middle)... 8139too  28737    0  8139  CP                  26305    0  MII  9409    2 8139tos, 8139 CP <= MII is also 8139 CP  , 8139too use... (omitted in the middle)... uhci_hcd  25421    0 <= The following three modules are related to USB flash drives! Ohci_hcd  23261    0  Ehci_hcd 33357    0 

After lsmod is used, the system displays the modules in the kernel, including:

    • Module name );
    • Module size (size );
    • Whether this module is used by other modules (used ).

That is to say, modules are actually dependent! Take the preceding table as an example. The MII module is used by 8139too. To put it simply, "when you want to load 8139too, You need to load the MII module to load 8139too smoothly.

In addition to displaying the current module, can I view the information of each module? For example, we know that 8139too is a crab card driver, so what is MII? Use modinfo to observe it!

[Root @ WWW ~] # Modinfo [-adln] [module_name | Filename] Options and parameters: - A: Only names of authors are listed; - D: only lists the description of the modules ); - L: only list licenses ); -N: only the detailed paths of this module are listed. Example 1: In the previous table, list information about the MII module: [root @ WWW ~ ] # Modinfo miifilename: /Lib/modules/ 2.6 . 18 - 92 . EL5/kernel/Drivers/NET/ MII. kolicense: gpldescription: MII hardware support libraryauthor: Jeff garzik <Jgarzik@pobox.com> Srcversion: 16dcedee4b5629c222c352ddepends: vermagic:  2.6 . 18 - 92 . EL5 SMP mod_unload686 Regparm 4 kstacks Gcc - 4.1  # You can see the source of this module and a brief description of this module! Example 2: I have a module named a.ko. What is the information about this module? [Root @ WWW ~ ] # Modinfo A. Ko... (Omitted ).... 

In fact, in addition to reading modules in the inner core, this modinfo can also check a module File. Therefore, if you want to know what a file represents, use modinfo to add the full file name! Let's see what it is!

 

Insmod and rmmod

Well, what should I do if I want to manually load the module? There are many methods. The simplest and recommended method is to use the modprobe command to load modules, because modprobe will actively search for modules. dep content first overcomes the dependency of modules before deciding which modules need to be loaded, which is very convenient. As for insmod, the user automatically loads a module with the full file name, and does not actively analyze the module dependency!

[Root @ WWW ~] #Insmod[/Full/path/Module_name] [parameters] Example 1: Please try to load the "File System" module CIFS. KO [root @ WWW~] #Insmod/Lib/modules/$ (Uname-R)/kernel/fs/CIFS/CIFS. KO [root @ WWW~] #Lsmod|GrepCifscifs2127890

He immediately loaded the module ~ However, the module after insmod must be a complete "file name! How can I remove this module?

 [root @ WWW ~] # Rmmod [- FW] module_name options and parameters: - F: Force remove the module, whether or not it is in use. - W  : If this module is in use, rmmod waits until it is used, to remove him! Example 1: remove the loaded CIFS module! [Root @ WWW  ~ ] # rmmod CIFS Example 2: Please load the "File System" module of vfat [root @ WWW  ~] #  insmod /lib/modules/$ ( uname -R)/kernel/fs/vfat/ vfat. ko   insmod : Error inserting  ' /lib/modules/2.6.18-92. EL5/kernel/fs/vfat. ko   ' :- 1  unknown symbol  in   Module # The vfat module cannot be loaded! Headache!  

 

Modprobe

The problem with using insmod and rmmod is that you must find the complete module File name on your own, and, as in the result of Example 2 above, if the module has dependency attributes, you cannot directly load or remove this module! In recent years, we have recommended that you directly use modprobe to handle the module loading problem. The usage of this command is:

[Root @ WWW ~] #Modprobe[-LCFR] module_name options and parameters:-C: List all modules of the current system! (More detailed code table)-L: List currently in/lib/modules /'Uname-R '/Complete file names of all modules in the kernel;-F: forces the module to be loaded;-R: similar to rmmod, it means to remove a module ~ Example 1: load the CIFS module [root @ WWW~] #ModprobeCIFS # Very convenient! You do not need to know the complete module File name. This is because the complete file name has been recorded in #/Lib/modules /'Uname-R '/Modules. Dep! If you want to remove it: [root @ WWW~] #Modprobe-R CIFS

It is much easier to use modprobe than insmod! Because he directly searches for the modules. Dep record, he certainly can overcome the dependency problem of the module and does not need to know the detailed path of the module!

 

Try to use modprobe to load the vfat module and observe which module is related to this module?

 

 
[Root @ WWW ~] #ModprobeVfat [root @ WWW~] #Lsmod|GrepVfatvfat158090Fat511651Vfat <=It turns out to be the fat module! [Root @ WWW~] #Modprobe-R vfat <= remove this module after testing

 

Additional kernel module parameter configuration:/etc/modprobe. conf

If you want to modify additional parameter configurations of some modules, configure them in this file! Let's assume that one case is good. Assume that the network card eth0 uses ne, but eth1 also uses ne. To avoid network card confusion caused by the same module, I can first find the I/O and IRQ of eth0 and eth1. Suppose:

    • Eth0: I/O (0x300) and IRQ = 5
    • Eth1: I/O (0x320) and IRQ = 7

Then:

 
[Root @ WWW ~] # Vi/etc/Modprobe. Confalias eth0 nealias eth1 neoptions eth0 Io=Zero X 300IRQ =5Options eth1 Io=Zero x 320IRQ =7

Hey! In this way, my Linux will not catch the corresponding network card! This is because I want to forcibly specify an I/O! Pai_^

 

From http://vbird.dic.ksu.edu.tw/linux_basic/0510osloader_2.php

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.