kernel and kernel modules
After talking about the entire start-up process, you should know that in the entire startup process, whether it is possible to successfully drive the hardware of our host, is the core (kernel) work! The kernel is generally compressed, so before the kernel is used, it needs to be decompressed before it can load the main memory.
In addition, in order to cope with the ever-changing hardware, the current kernel is a "readable modular driver" function, that is, the so-called "modules (Modular)" Function! The so-called modularity can think of him as a "plug-in", the plug-in may be provided by hardware developers, it is possible that our core is supported ~ However, newer hardware usually requires the hardware developer to provide the driver module!
So where are the kernel and kernel modules?
- Kernel:/boot/vmlinuz or/boot/vmlinuz-version;
- Kernel decompression required RAM Disk:/BOOT/INITRD (/boot/initrd-version);
- Kernel modules:/lib/modules/version/kernel or/lib/modules/$ (uname-r)/kernel;
- Kernel source code:/usr/src/linux or/usr/src/kernels/(to be installed, not installed by default)
If the kernel is successfully loaded into the system, then there will be a few messages logged:
- Kernel version:/proc/version
- System kernel function:/proc/sys/kernel
The question comes, if I have a new hardware, but my operating system does not support, what should I do? It's simple!
- Recompile the kernel and add the latest hardware driver source code;
- Compile the driver for this hardware into a module and load the module at startup
The 1th of the above is also very well understood, anyway is to recompile the kernel just. However, kernel compilation is not easy Ah!
Depmod
Since we're dealing with kernel modules, it's natural to understand the dependencies between the modules that our kernel provides! Basically, the kernel module is located in the/lib/modules/$ (uname-r)/kernel, which is mainly divided into several directories:
Arch : Projects related to hardware platforms, such as CPU levels, etc. crypto : encryption techniques supported by the kernel, such as MD5 or DES, etc. drivers : Drivers for some hardware, such as graphics cards, network cards, PCI Related hardware and so on; FS : Filesystems supported by the kernel, such as VFAT, ReiserFS, NFS, and so on; Lib : some function libraries; NET : Network-related protocol data, as well as firewall modules (net/ipv4/ netfilter/*) and so on; Sound: Various modules related to audio;
If we're going to check out the main information for each of these modules one by one, and then define their dependencies, we're going to freak out! So, of course, our Linux will provide some solutions to the dependencies of the modules Luo ~! That is to check /lib/modules/$ (uname-r)/modules.dep this file! He records the dependencies of the modules supported in the kernel.
So how does this file be created? Very simple! The need to create this file can be achieved with the DEPMOD command!
[[email protected] ~]# depmod [-ane] options and Parameters:- A: When no parameters are added, Depmod will proactively parse the current kernel module and re-write /lib/modules/$ (uname-r)/ Among the MODULES.DEP. If the-a parameter is added, then Depmod will search for a new module than the MODULES.DEP, and if a new module is found, it will be upgraded. -N: Does not write to MODULES.DEP, but instead outputs the result to the screen (standard out);-e : shows an example of a non-running module name that is currently loaded: If I do a network card driver, file name is A.ko, how do I upgrade kernel dependencies? [[email protected] ~]# CP a.ko/lib/modules/$ (UNAME-R)/kernel/drivers/net[[email protected] ~]# Depmod
As an example of the example above, our Linux kernel 2.6.x version of the kernel module extension must be. Ko end, when you use Depmod, the program will run to the module standard placement directory/lib/modules/$ (uname-r)/kernel, and according to According to the definition of the relevant directory will be all the modules to capture the analysis, the results of the analysis will be written to the Modules.dep file in the Na! This file is very important. Because he will affect the application of the Modprobe command that will be introduced later in this chapter!
Lsmod
Do you know how many modules the kernel is currently loaded with? You can use Lsmod!
[Email protected] ~]# lsmodmodule Size used byautofs4 24517 2hidp 23105 2 .... ( Middle omitted) .... 8139too 28737 08139cp 26305 0mii 9409 2 8139too,8139cp <==mii also be 8139CP, 8139too use .... (omitted in middle) .... UHCI_HCD 25421 0 <== The bottom three is a U disk related module! OHCI_HCD 23261 0ehci_hcd 33357 0
After using Lsmod, the system will show the modules that are already present in the kernel, including the following:
- Module name (modules);
- The size of the module (size);
- Whether this module is used by other modules (used by).
In other words, the module really has a dependency! For example, the Mii module will be used by 8139too. Simply put, it means "when you want to load 8139too, you need to load the Mii module before it can load 8139too smoothly".
So besides showing the current module, can I check the information of each module? For example, we know that 8139too is the driver of the crab card, so what is Mii? Just use Modinfo to see it!
[[email protected] ~]# modinfo [-ADLN] [module_name|filename] options and Parameters: -A: Lists only the author name; -D: Lists only the description of the modules ( description); -L: List only authorization (license); -N: Lists only the detailed path of the module. Example one: From the previous table, please list the 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 4KSTACKS gcc-4.1# can see the source of this module, as well as the simple description of the module! (Is the hardware support function library) example Two: I have a module named A.ko, is the module information? [Email protected] ~]# modinfo A.ko .... (omitted) ....
In fact, this modinfo can check "a module file" In addition to "looking up modules within the kernel", so if you want to know what the meaning of a file represents, use Modinfo with the full file name! Look, you know what it is!
Insmod and Rmmod
Well, what if I want to manually load the module myself? There are many ways, the simplest and recommended, is to use modprobe this command to load the module, this is because modprobe will be active to search for MODULES.DEP content, first overcome the dependencies of the module, before deciding which modules to load, very convenient. As for Insmod, it is entirely up to the user to load a full file module, and will not actively analyze the module dependencies!
[Email protected] ~]# insmod [/full/path/module_name] [parameters] Example one: Please try to load Cifs.ko This "file system" module [[email protected] ~]# insmod/lib/modules/$ (UNAME-R)/kernel/fs/cifs/cifs.ko[[email protected] ~]# lsmod | grep cifscifs 212789 0
He immediately loaded the module ROM ~ But the module after the Insmod must be a complete "file name" line! So how do you remove this module?
[[email protected] ~]# rmmod [-FW] module_name options and parameters: -F: Forces the module to be removed, whether or not it is being used, or -W: If the module is being used, the Rmmod waits for the module to be used, Before I remove him! Example one: Remove the CIFS module just loaded! [[email protected] ~]# Rmmod CIFS example two: Please load VFAT This "file system" module [[email protected] ~]# insmod/lib/modules/$ (uname-r)/kernel/fs/ Vfat/vfat.koinsmod:error inserting '/lib/modules/2.6.18-92.el5/kernel/fs/vfat/vfat.ko ':-1 Unknown symbol in module# Unable to load VFAT this module Ah! Racking
modprobe
The problem with Insmod and Rmmod is that you have to find the full file name of the module yourself, and as a result of the example above, you will not be able to load or remove the module directly if the module has a dependency property problem! So in recent years we have suggested using modprobe directly to deal with the problem of module loading, the use of this command is:
[[email protected] ~]# modprobe [-LCFR] module_name options and parameters: -C: List all the current system modules! (More detailed code-name correspondence table)-L : Lists all the modules currently in the/lib/modules/' uname-r '/kernel full file name;-F : Force the module to load;-r: Similar to Rmmod, is to remove a module ROM ~ Example one: Load the CIFS module [[email protected] ~]# modprobe cifs# very convenient! Do not need to know the full module file name, this is because the full file name has been recorded in #/lib/modules/' Uname-r '/modules.dep in the sake of Ah! If you want to remove: [[email protected] ~]# Modprobe-r CIFS
Using Modprobe is really a lot easier than insmod! Because he is directly to search MODULES.DEP records, so Luo, of course, can overcome the dependencies of the module, and do not need to know the detailed path of the module!
Try to load the VFAT module with Modprobe, and see which module the module is related to?
[Email protected] ~]# modprobe vfat[[email protected] ~]# lsmod | grep vfatvfat 15809 0fat 51165 1 vfat <== is fat this module Ah! [[email protected] ~]# modprobe-r vfat <== Remove this module after testing
additional parameter configuration for kernel modules:/etc/modprobe.conf
If you want to modify the additional parameter configuration for some modules, configure it in this file! Let's say a case is good, assuming my network card eth0 is using NE, but eth1 also uses NE, in order to avoid the same module will cause network card confusion, so I can first find eth0 and eth1 I/O and IRQ, assuming:
- ETH0:I/O (0x300) and irq=5
- ETH1:I/O (0x320) and irq=7
The
[Email protected] ~]# vi/etc/modprobe.confalias eth0 nealias eth1 neoptions eth0 io=0x300 irq=5options eth1 io=0x320 IRQ =7
Hey! In this way, my Linux will not catch the wrong network card corresponding ROM! Because I was forced to specify an I/O. ^_^
Transfer from http://vbird.dic.ksu.edu.tw/linux_basic/0510osloader_2.php
Kernel module management [GO]