Linux under the concept of modules and use of the detailed [repost]

Source: Internet
Author: User

First, what is modules?

Modules literally means the module, which refers to the kernel modules; Simply put, a module provides a feature such as Isofs, Minix, NFS, LP, and so on. Traditionally, modularity has been solved in two ways: designers can separate functions into a separate process called threading, or recompile the kernel in a way that includes/excludes some functionality. If the function is separated into threads, then the kernel is called "microkernel" (Micro-kernel), which increases the communication overhead of coordination between threads. As the name implies, the advantage of this solution is the size of the kernel.

The Linux solution is to include kernel modules that can be loaded and unloaded as needed at any time. This allows the kernel to be sized and communicated to a minimum. Separate the modules from the kernel without having to "tie" them in kernel codes. This has three advantages: first, in the future to modify the kernel, do not have to re-compile all, can save a lot of time; second, if you need to install a new modules, you do not have to compile kernel, as long as you insert (via the Insmode command) the corresponding Modules, third, reduce the kernel to the system resources, the kernel can focus on the most basic things, and put some extension functions to modules implementation.

Modules can also be used to try out new kernel code without having to create and reactivate the kernel every time. However, the problem with this is that using kernel modules typically adds a slight increase in performance and memory overhead. A loadable module will definitely generate more code, and this code and additional data structures will take up a bit more memory. In addition, the efficiency of the module is reduced slightly because of the indirect access to the kernel resources.

The idea of modularity has been widely accepted, the main reason is that it can extend the function of the system, the user can flexibly configure the system. Apache has also taken this feature extension approach, the main discussion in this article is the kernel module installation and uninstallation, Apache module installation please refer to the relevant documents APAPCE.

Second, how to load the module?

There are two ways to load a kernel module. The first is to manually insert it into the kernel using the Insmod command. Another smarter approach is to load the module when needed: This is called load on Demand (demandloading). When the kernel discovers that a module is needed, such as when a user installs a file system that is not in the kernel, the kernel requests the kernel daemon (Kerneld) to attempt to load the appropriate module. In this case, we can not mention the kernel daemon Kerneld, it is very smart, be able to actively modules you need to automatically insert kernel, the useless module from kernel repaying. The Kerneld consists of two separate parts: part of the Linux kernel that is responsible for sending requests to daemon, and the other part of the system's user data area, which calls into the modules specified by the kernel request. If this kerneld is missing, it can only be loaded manually by using the Insmode or Modeprobe command.

Three, modules of the relevant command introduction

The commands related to modules are:

reference:

Lsmode: Lists modules that have been called into the kernel
Insmode: a mod Ule INSERT into the kernel
Rmmod: Uninstalls a module from the kernel
Depmod: Generates a dependent file that tells future Insmod where to transfer the modules from. This dependent file is/lib/modules/[your kernel version]/modules.dep.
Kerneld: Responsible for automating the transfer of modules into the kernel and unloading modules from the kernel.

Four, compile a minimal Linux kernel

Modules are typically used to support features that are infrequently used. For example, you typically use Dial-Up Networking only, so network functionality is not required at all times, so you should use a module that can be loaded to provide this functionality. The module is only loaded when you are dialing a connection. It is automatically removed when you break the connection. This minimizes the amount of memory used by the kernel and reduces the load on the system.

Of course, those functions, such as the need for hard disk access all the times, must be in the kernel. If you take a network workstation or Web server, then the network functions are needed at all times, and you should consider compiling the network functions into the kernel. Another way to do this is to load the network module at boot time. The advantage of this approach is that you do not need to recompile the kernel. The disadvantage is that network functions are not particularly efficient.

In accordance with the above principles, we will first list a list to see which options in kernel are non-essential, that is to say, these things must be compiled into the kernel. Remove those nonessential modules from the kernel. The first of the

is the hard disk configuration where root resides. If your hard drive is an IDE interface, mark the IDE's options. If it is a SCSI interface, please mark your interface parameters and SCSI ID.

The second is the choice of which file system to use. The default file system for Linux is ext2, so be sure to mark it down. If you have other operating systems in your machine, such as Win98 or WindowsNT, you may also choose to support FAT32 or NTFS, but you can add new module support by manually loading them later.

The third is to choose the executable file format supported by Linux. There are two formats to choose from:

Elf: This is the executable file format commonly supported by Linux and must be compiled into the kernel.

A.out: This is the format of the libraries of the old Linux executables, and if you confirm that you do not have the executable file in this format, you can not compile it into the kernel. The

above is something that must be compiled into the kernel. Other content all the options in the M hint, select m, so you can manually add the module.
Code:

* * Loadable module support*enable Loadable module Support (config_modules) [y/n/?] Set version
Information on all symbols for modules (config_modversions) [n/y/?] Kernel daemon Support (e.g.
AutoLoad of modules) (Config_kerneld) [y/n/?]

Answer Y,n,y respectively. Where the default value of Config_kerneld is N, be careful to select Y.

When make config is finished, it is still
Code:
Make DEP; Make clean.

Next, make Zlilo or do zimage.

then make modules; Make Modules_install. Once this is done, a "clean" kernel image file is compiled that does not have a spare module in it.

Five, how to manually load modules?

If you want to load the module manually, it is advisable to use modprobe, as it solves the dependency problem between modules, and in the case of sound cards, for example, in the Audio blaster, there are a total of the following modules:
Reference:

SB 33652 0 (AutoClean)
uart401 6160 0 (AutoClean) [SB]
Sound 56492 0 (AutoClean) [SB uart401]
Soundcore 2372 5 (AutoClean) [SB Sound]

These modules are loaded, and the entire sound card works, and there is a dependency between them. The core Soundcore must be loaded first, and finally loaded with SB. But the average person is not aware of its sequencing. Therefore, modprobe is used to solve this problem.

Usually we just need: Modprobe SB

It will automatically find all the modules that SB uses, and load them in one by one, so the general user will not have to bother.

So how does the kernel know about the dependencies between these modules? Originally, there is a ' depmod-a ' command in the system startup script that creates a list of dependencies for all available modules in the system. and ' Modprobe module-name ' will use this list, loading the specified

Before the module is loaded into the pre-loaded modules. If the ' module-name ' is not found in this subordinate list, it will give the corresponding error message.

However, if you use Insmod, it will not automatically transfer the other modules. For example, we are going to join the PPP module with this command:
Code:

Root/root>insmod PPP
Root/root>

If the operation succeeds, the system appears with an action prompt. If this is not successful, the following information may appear:
Reference:

/lib/modules/2.2.10/net/ppp.o:unresolved symbol SLHC_INIT_RSMP_1CA65FCA
/lib/modules/2.2.10/net/ppp.o:unresolved symbol slhc_compress_rsmp_cfd3a418
/lib/modules/2.2.10/net/ppp.o:unresolved symbol Slhc_free_rsmp_b99033d9
/lib/modules/2.2.10/net/ppp.o:unresolved symbol SLHC_TOSS_RSMP_A152CEC0
/lib/modules/2.2.10/net/ppp.o:unresolved symbol slhc_remember_rsmp_07972313
/lib/modules/2.2.10/net/ppp.o:unresolved symbol SLHC_UNCOMPRESS_RSMP_3BB36B01
[root/root]#

This indicates that the PPP module has not been loaded successfully, and the Unresolvedsymbol in the error message indicates that some modules required by the PPP module are not yet loaded. Error message the first line of content is: SLHC_INIT_RSMP_1CA65FCA, which module? This may require some experience to make a judgment, it starts with SLHC, try to slhc it.
Code:

Root/root>insmod SLHC Everything is OK then we load the PPP module again
Root/root>insmod PPP
Root/root>

This time there is no return message stating that the PPP module was loaded successfully.

VI. Uninstalling a modules from memory

To unload a module, first use Lsmod to see if the module is actually loaded, and then do the operation. In addition, in the case of modules that have dependencies, the process of unloading modules from the kernel is the opposite of loading, and it follows the "first in Lastout" guideline, in which a series of dependent modules must unload the last loaded module and finally unload the first loaded module. For example, if you want to use Rmmod to remove a module in use (as in the example above, to uninstall SLHC, but there is still a PPP module using it), an error message appears: Device or resource busy. Therefore, the SLHC module may be unloaded from memory after the PPP module is unloaded from memory.

In summary, when uninstalling a module, Linux gives you enough information to give you an indication of the possible inter-module dependencies, and to take a closer look at this information, to help you with the appropriate action and ultimately to solve the problem. http://blog.chinaunix.net/uid-10076460-id-2970735.html

The concept and use of modules under Linux [paste]

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.