Chapter 2 startup process, module management and loader

Source: Internet
Author: User

Core and core modules

Whether or not we can successfully drive the hardware configuration of our host throughout the startup process is a core task! The core is generally compressed files, so before using the core, you have to decompress it before loading the main memory.

In addition, in order to cope with the changing hardware, the current core is to have the "readable modular driver" function, that is, the so-called "modules (modular)" function!

Core and core module location:

  • Core:/boot/vmlinuz or/boot/vmlinuz-version;
  • RAM disk required for core decompression:/boot/initrd (/boot/initrd-version );
  • Core Module:/lib/modules/version/kernel or/lib/modules/$ (uname-R)/kernel;
  • Core original code:/usr/src/Linux or/usr/src/kernels/(this is required for installation. It is not installed by default)

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

  • Core version:/proc/version
  • System core functions:/proc/sys/kernel

If the operating system does not support new hardware:

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

How to load an existing module?

Core modules and dependency

Basically, the core 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 core, such as MD5 or des. Drivers: some hardware drivers, for example, video card, network card, and PCI-related hardware; FS: filesystems supported by core, such as vfat, reiserfs, and NFS; LIB: some library; Net: network-related protocol data, as well as firewall modules (net/IPv4/Netfilter/*); Sound: Sound-related modules;

/Lib/modules/$ (uname-R)/modules. Dep records the dependencies of the modules supported by the core.

[[Email protected] ~] # Depmod [-ane] Options and parameters:-A: When no parameters are added, depmod will take the initiative to analyze the current core module, and re-write/lib/modules/$ (uname-R)/modules. dep. If the-a parameter is added, depmod searches for modules that are newer than those in modules. Dep. If a new module is found, the module is upgraded. -N: Do not write modules. dep, but outputs the result to the screen (Standard out);-E: shows the currently loaded unrunnable Module name Example 1: If I have a network card driver, file Name:. ko, how to upgrade core dependency? [[Email protected] ~] # Cp a. Ko/lib/modules/$ (uname-R)/kernel/Drivers/net [[email protected] ~] # Depmod

The core module extension of Linux kernel 2.6.x must be. after using 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 affects the application of The modprobe command!

Observation of core modules

 

[[Email protected] ~] # Lsmodmodule size used byautofs4 24517 2 hidp 23105 2 .... (omitted in the middle ).... 8139too 28737 08139cp 26305 0mii 9409 2 8139too, 8139cp <= MII is also used by 8139cp and 8139too .... (omitted in the middle ).... uhci_hcd 25421 0 <== the bottom three are USB disk-related modules! Ohci_hcd 23261 0ehci_hcd 33357 0

After lsmod is used, the system displays the modules that already exist in the core, including:

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

Module dependency! Take the preceding table as an example. The MII module is used by 8139too. "To load 8139too, You need to load the MII module before loading 8139too 』. 8139too is the driver of the crab card

[[Email protected] ~] # Modinfo [-adln] [module_name | filename] Options and parameters:-A: only lists author names;-D: only lists description of this modules;-l: only the license is listed;-N: only the detailed paths of the module are listed. Example 1: In the previous table, please list information about the MII module: [email protected] ~] # Modinfo miifilename:/lib/modules/2.6.18-92. EL5/kernel/Drivers/NET/MII. kolicense: gpldescription: MII hardware support libraryauthor: Jeff garzik <[email protected]> srcversion: 16dcedee4b5629c222c352ddepends: vermagic: 2.6.18-92. EL5 SMP mod_unload 686 regparm 4 kstacks gcc-4.1 # You can see the source of this module, as well as a simple description of this module! Example 2: I have a module named a.ko. What is the information about this module? [[Email protected] ~] # Modinfo A. Ko... (Omitted )....

In fact, in addition to "checking the modules in the 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!

Core Module loading and Removal

Modprobe: load the module. modprobe will actively search for the content of modules. Dep. After the module dependency is overcome, it determines which modules need to be loaded. Insmod is completely loaded by the user with a complete file name, and does not actively analyze module dependencies!

[[Email protected] ~] # Insmod [/full/path/module_name] [parameters] Example 1: Please try to load the "File System" module CIFS. KO [[email protected] ~] # Insmod/lib/modules/$ (uname-R)/kernel/fs/CIFS. KO [[email protected] ~] # Lsmod | grep cifscifs 212789 0

The module after insmod must be a complete "file name 』

[[Email protected] ~] # Rmmod [-fw] module_name option and parameter:-F: Force remove this module, whether or not it is in use;-W: If this module is in use, then rmmod will remove the module after it is used! Example 1: remove the loaded CIFS module! [[Email protected] ~] # Rmmod CIFS Example 2: Please load the "File System" module of vfat [[email protected] ~] # Insmod/lib/modules/$ (uname-R)/kernel/fs/vfat. koinsmod: 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!

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:

[[Email protected] ~] # Modprobe [-LCFR] module_name option and parameter:-C: List all modules of the current system! (More detailed code table)-L: lists the complete file names of all modules currently in/lib/modules/'uname-R'/kernel;-F: forcibly load the module.-R: similar to rmmod, it means to remove a module ~ Example 1: load the CIFS module [[email protected] ~] # Modprobe CIFS # You do not need to know the complete module file name, because the full file name has been recorded in #/lib/modules/'uname-R'/modules. reason in dep! If you want to remove it, [[email protected] ~] # Modprobe-r CIFS

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

Example: Try to use modprobe to load the vfat module and observe which module is related to this module? A: We use modprobe for loading, and then use lsmod to observe and grep to retrieve keywords:
[[Email protected] ~] # Modprobe vfat [[email protected] ~] # Lsmod | grep vfatvfat 15809 0fat 51165 1 vfat <= It turns out to be the fat module! [[Email protected] ~] # Modprobe-r vfat <= remove this module after testing

Additional parameter configuration of the core module:/etc/modprobe. conf

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:

[[email protected] ~]# vi /etc/modprobe.confalias eth0 nealias eth1 neoptions eth0 io=0x300 irq=5options eth1 io=0x320 irq=7

 

 

Chapter 2 startup process, module management and loader

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.