Common Linux kernel commands

Source: Internet
Author: User

1. What is modules?

The literal meaning of modules is the module, which refers to the kernel modules. Simply put, a module provides a function, such as isofs, minix, NFS, and LP. Traditionally, there are two ways to solve modularization: the designer can separate various functions into separate processing called threads, or re-compile the kernel by including/excluding some functions. If functions are separated into threads, the kernel is called "micro-kernel". This solution increases the communication overhead of Inter-thread coordination. As the name implies, the advantage of this solution lies in the size of the kernel.
Linux Solutions include kernel modules that can be loaded and detached at any time as needed. In this way, the kernel size and traffic can be minimized. The module is independent from the kernel and does not need to be pre-bound to the kernel codes. There are three advantages: First, you do not have to re-compile the kernel in the future, which saves a lot of time; second, if you need to install a new modules, you do not have to re-compile the kernel, you only need to insert the corresponding modules (using the insmode command). Third, to reduce the kernel's occupation of system resources, the kernel can focus on the most basic tasks, some extended functions are implemented by modules.
The module can also be used to try new kernel code without the need to create and reactivate the kernel every time. However, the problem is that using the kernel module usually slightly increases performance and memory consumption. A loadable module will certainly generate more code. This code and additional data structure will occupy more memory. In addition, indirect access to kernel resources also reduces the module efficiency slightly.
The idea of modularization has been widely accepted, mainly because it can expand the functions of the system and allow users to flexibly configure the system. Apache also adopts this function extension method. In this article, we mainly discuss how to install and uninstall the kernel module. For details about how to install the Apache module, refer to the apapce documentation.

Ii. How to load modules?

There are two ways to load the kernel module. First, use the insmod command to manually insert it to the kernel. Another more intelligent method is to load this module as needed: demand loading ). When the kernel discovers that a module is required, for example, when you install a file system that is not in the kernel, the kernel will request the kernel daemon (kerneld) to try to load the appropriate module. Speaking of this, we can't help but mention the kernel daemon kerneld. It is very intelligent and can automatically Insert the required modules into the kernel and Remove unused modules from the kernel. Kerneld consists of two independent parts: one part is used in the Linux kernel and is responsible for sending requests to daemon. The other part is used in the user data area of the system and is responsible for transferring the modules specified by the kernel request. If this kerneld is missing, it can only be loaded manually using the insmode or modeprobe command.

3. Introduction to modules commands

Commands related to modules include:

Lsmod: List modules that have been transferred to the kernel
Insmod: inserts a module into the kernel.
Rmmod: detaches a module from the kernel.
Modprobe: automatically loads modules based on dependent files
Depmod: generate the dependency file and tell modprobe and kerneld where to transfer the modules. The dependency file is in/lib/modules/kernel version/modules. Dep.
Kerneld: automatically transfers the module to the kernel and detaches the module from the kernel.

4. Compile a minimum Linux Kernel

The module is generally used to support functions that are not frequently used. For example, you usually only use a dial-up network, so the network function is not required at any time. Therefore, you should use a module that can be loaded to provide this function. This module is loaded only when you perform a dial-up connection. When you disconnect the connection, it will be automatically removed. This minimizes the amount of memory used by the kernel and reduces the system load.
Of course, those features that are always needed like hard disk access must be implemented in the kernel. If you build a network workstation or web server, the network function is always needed, and you should consider compiling the network function into the kernel. Another method is to mount the network module at startup. The advantage of this method is that you do not need to recompile the kernel. The disadvantage is that the network function cannot be particularly efficient.
In accordance with the above principles, we first list a list to see which options in the kernel are non-essential, that is, these things must be compiled into the kernel. Remove unnecessary modules from the kernel.
The first is the hard disk configuration of the root user. If your hard disk is an IDE interface, mark the IDE options. For a SCSI interface, mark your interface parameters and scsi id.
The second is to select which file system to use. In Linux, the default file system is ext2, so you must mark it. If other operating systems, such as Win98 or Windows NT, are also supported by FAT32 or NTFS, however, you can add new module support by manually loading later.
The third is to select the executable file format supported by Linux. There are two formats to choose from: 1. Elf: This is an executable file format commonly supported by Linux and must be compiled into the kernel. 2.. out: This is the format of different function libraries in the earlier version of Linux executable files. If you are sure you cannot use the executable files in this format, you can not compile them into the kernel.
The above content must be compiled into the kernel. For other content that is prompted by m in all options, select M. You can manually add this module.

** Loadable module support **
Enable loadable module support (config_modules) [Y/n/?]
Set versioninformation on all symbols for modules (config_modversions) [N/y/?]
Kernel daemon support (e. g. autoload of modules) (config_kerneld) [Y/n/?]

Answer Y, N, and Y respectively. The default value of config_kerneld is N, so select y.
After make config is complete, it is still make Dep; make clean. Next, make zlilo or make zimage. Then make modules; Make modules_install. After compilation, a "clean" kernel image file is compiled without calling any redundant modules.

5. How to manually load modules?

If you want to manually load a module, we recommend that you use modprobe because it can solve the dependency problem between modules. In the sound card section, sound blster is used as an example and has the following modules:
SB 33652 0 (autoclean)
Uart401 6160 0 (autoclean) [SB]
Sound 56492 0 (autoclean) [SB uart401]
Soundcore 2372 5 (autoclean) [SB sound]
These modules must be loaded, and the entire sound card can work, and there is a dependency between them. The most core soundcore must be loaded first, and finally sb. However, most people do not know their order. Therefore,

Modprobe is used to solve this problem.
Generally, as long as "modprobe Sb" is used, it will automatically find all the modules used by Sb and load them one by one. Therefore, general users do not have to worry about it.
So how does the kernel know the dependency between these modules? It turns out that there is a 'depmod-a' command in the system startup script, which creates a list of Dependencies for all available modules in the system. The 'modprobe module-name' will use this list to load the pre-loaded modules before loading the specified modules. If 'module-name' is not found in this slave list, it will provide the corresponding error information.
However, if you use insmod, it does not automatically call other modules. For example, to add the PPP module, run the following command:

Root/root> insmod PPP
Root/root>

If the operation is successful, an operation prompt is displayed. If it fails, the following information may appear:

/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 is not loaded successfully. The Unresolved symbol in the error prompt indicates that some modules required by the PPP module are not loaded yet. The first line of the error message is: slhc_init_rsmp_1ca65fca. Which module is this? In this case, some experience may be needed to make a judgment. It starts with slhc, so try slhc.

Root/root> insmod slhc is normal, and then we load the PPP Module
Root/root> insmod PPP
Root/root>

No information is returned, indicating that the PPP module has been loaded successfully.

6. Detach A modules from the memory

To uninstall a module, first use lsmod to check whether the module has been loaded and then perform the operation. In addition, when encountering a dependency module, the process of uninstalling the module from the kernel is the opposite of the loading process. It follows the "first in last out" principle, that is, in a series of dependency modules, you must first uninstall the last loaded module, and finally uninstall the first loaded module. For example, if you want to use rmmod to remove a module in use (in the above example, you want to uninstall slhc, but there are still PPP modules using it), the error message "device or resource busy" is displayed. Therefore, the slhc module can be detached from the memory only after the PPP module is detached from the memory.
In short, when uninstalling a module, Linux will prompt you with sufficient information for possible inter-module dependency issues and carefully check the information, it can help you take appropriate actions and finally solve the problem.

VII. Linux Command: modprobe

Function Description: automatically processes the loaded modules.

Syntax: modprobe [-acdlrtvv] [-- help] [module File] [Symbol name = symbol value]

Note: modprobe can load specified modules or a group of dependent modules. Modprobe determines the modules to be loaded Based on the dependency generated by depmod. If an error occurs during the loading process, the entire group of modules will be uninstalled in modprobe.

Parameters:
-A or -- all load all modules.
-C or -- show-conf displays the settings of all modules.
-D or -- debug uses the troubleshooting mode.
-K or -- autoclean specifies that the module is set to "auto-clear" mode.
-L or -- List displays available modules.
-N or -- show only displays the operation to be executed, instead of the actual operation.
-Q or -- Quiet does not display error messages.
When the-R or -- remove module is idle, it is automatically uninstalled.
-S or -- syslog // record the result to the system record.
-T or -- type specifies the module type.
-V or -- verbose displays detailed information during execution.
-V or -- version displays version information.
-C or -- config configfile specifies the configuration file. The/etc/modules. conf file is used by default as the configuration file.
-H or-help displays help.

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.