Article Title: Linux kernel management basics overview. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. What is the kernel;
Official kernel: http://www.kernel.org
Kernel foreign uses kernel. I just flipped through the dictionary. The Chinese meaning of kernel is kernel, core, center, and essence. It is also the meaning of nuts and fruits. Literally speaking, kernel is the center of a thing, and the fruit of a plant is also the kernel and 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, it is developed by Linux. 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 for some functions. If the kernel content related to iptables is 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. You 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 also 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. Mount the new module and the module on which the new module depends.
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, there is also the function of removing modules. 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 [- ...]
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 modules configuration file, 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 talk about this. 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. (create dependency for modules. dep file or ing file)
[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. configuration files related to kernel module Loading;
1. module configuration file modules. conf or modprobe. conf
The automatic mounting module of the kernel module is usually located in a configuration file. The common Linux releases all have/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
And 8029 of NICs should be
Alias eth0 ne2k-pci
In this way, the system will first modprobe 8139too, and then specify the alias for 8139too as eth0. Then, when we log on, we will use ifconfig to view the nic ip address and other conditions, of course, you must set an IP address for the NIC;
In general, modproe. conf or modules. the conf file is generated using the corresponding hardware configuration tool. If your hardware driver is not supported by the kernel, you can download it from the hardware vendor. In general, there are installation and help files. When their driver is configured, it will write hardware support to the modules. conf or modprobe. conf file.
For example, our sound card is in modules. conf or modprobe. conf also contains the relevant content, which is generated by the alsaconf Configuration tool. See it. Similarly, the NIC is in modprobe. conf or modules. the content in conf is also from the NIC Configuration tool.
Some hardware is driven by kernel modules. Once loaded, modules can be used, and there are no configuration tools, such as vfat and ntfs support; if the hardware driver is not supported by modules, but directly compiled into the kernel, it will not be used in modprobe. conf or modules. what content is added to the conf file;
If some of your modules cannot be loaded upon startup, you can directly write The modprobe module into the configuration file if you want some modules to be loaded automatically by adding machines;
2. Other configuration files of the kernel module
You need to know about other configuration files of the kernel module, such as the files in the/lib/modules/kernel version directory. Just take a look. For example:
[Root @ localhost beinan] # uname-r
2.6.11-1.1369 _ FC4
[Root @ localhost beinan] # ls/lib/modules/2.6.11-1.1369 _ FC4/
Build misc modules. ccwmap modules. ieee1394map modules. isapnpmap modules. symbols source
Kernel modules. alias modules. dep modules. inputmap modules. pcimap modules. usbmap
6. Directory of the hardware driver in the system;
Directory supported by modules in the kernel of the hardware driver;
The hardware driver must be supported by the kernel, whether we install the driver ourselves or the driver that comes with the kernel. If the hardware driver is supported by the kernel module, the driver directory is located in/lib/modules/kernel version/kernel/directory or/lib/modules/kernel version/kernel/drivers directory;
[Root @ localhost beinan] # uname-r
2.6.11-1.1369 _ FC4
[Root @ localhost beinan] # ls/lib/modules/2.6.11-1.1369 _ FC4/kernel
Arch crypto drivers fs lib net sound
Note: The driver is located in the/lib/modules/directory only when the driver is supported by the module in the kernel. If the driver is directly placed in the kernel, it will not appear in the directory related to the/lib/modules driver;
7. Compile the driver by yourself;
If the driver is provided by a hardware vendor or open-source community (not integrated in the kernel source code), the compilation driver process is generally. /configure; make install, sometimes the program does not provide. /configure, we can make or make install, or execute make; make install; if you cannot make install, We need to copy it by ourselves. o or. go to the/lib/modules/kernel version/kernel/directory or the corresponding driver directory in the/lib/modules/kernel version/kernel/drivers directory;
I 'd like to try it myself. I can't say it clearly. I will know how to solve the problem. The driver's REAME and INSTALL will prevail;
At present, most drivers automatically copy the. o or. ko files to the kernel module directory during compilation and installation. Most of them do not need to be copied by ourselves. If you try to compile and install the audio card driver alsa-drivers, you will understand what I mean;
If we re-compile the kernel to solve the driver problem, you can view the Documentation REAME in the kernel source code directory in the/usr/src/directory; all the help files are there;
Postscript:
Kernel compilation is a little difficult for beginners. I have written many similar articles, but I don't know what new beginners can learn from them; after all, the document I wrote tells some basic procedures and precautions in the kernel file. Kernel configuration can only be learned through multiple practices. When you configure the kernel, you should take a look at the help;
In terms of kernel module management, I have already written some in this article. In general, if you want to know more details, you can only read man and -- help by yourself, I write a document to view these things, and then write it to everyone. I can write it out. I think your abilities are not necessarily inferior to mine, so I should be more competent;