Linux Primer CentOS7 Kernel compilation trilogy (3)
in the previous article through some simple examples and uses introduced the Linux system the function and the function of the module. So every time after the system starts, and how to automatically load the required modules, then look back to the continuous module loading specific in the system startup phase of the start of the trigger. At the same time, the module is loaded according to the kernel itself, or the corresponding configuration file in the Linux file system?
default installed module file path:/lib/modules/$ (uname-r)/kernel, such as:
#查看内核模块列表目录
[[email protected] ~]# ls/usr/lib/modules/$ (uname-r)/kernelarch Crypto drivers fs kernel lib mm net sound
#当然还有另外一个目录/usr/lib/modules/$ (uname-r)/kernel
[[email protected] ~]# ls/usr/lib/modules/$ (uname-r)/kernelarch Crypto drivers fs kernel lib mm net sound
Note: The default is stored in the /lib/modules directory before CentOS6, and is not stored under /usr/lib/modules , but is installed CentOS7 You will then find that there are two directories that contain the kernel module files.
#其实是CentoOS7为了保留原来的结构, a soft connection was added
[Email protected] ~]# ls-dl/usr/lib/lib lrwxrwxrwx. 1 root root 7 Sep 7 16:11/lib-Usr/libdr-xr-xr-x. Root root 4096 Sep 7 16:17/usr/lib
Basic commands and common methods for specific operating modules:
View modules that are currently loaded
Cat/proc/modules # through mapping files
Lsmod # through command tools
Instance:
#查找ext4文件系统相关的模块
[[email protected] ~]# grep ' \<ext4\> '/proc/modules ext4 507694 3-live 0xffffffffa018e000mbcache 14958 1 ext4, Li ve 0xffffffffa004c000jbd2 98466 1 ext4, Live 0xffffffffa0174000[[email protected] ~]# lsmod | grep ' \<ext4\> ' ext4 507694 3 mbcache 14958 1 ext4jbd2 98466 1 ext4
View information for specific modules
Modinfo module_name
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/E3/wKioL1fj-ULSkGiZAAAxVjZ-6Ys299.png "title=" Modinfo.png "alt=" Wkiol1fj-ulskgizaaaxvjz-6ys299.png "/>
To view the dependencies of a specified package
Modprobe--show-depends module_name
Example: viewing dependent packages for EXT4
#通过命令查询
[Email protected] ~]# modprobe--show-depends Ext4insmod/lib/modules/2.6.32-642.el6.x86_64/kernel/fs/mbcache.ko Insmod/lib/modules/2.6.32-642.el6.x86_64/kernel/fs/jbd2/jbd2.ko Insmod/lib/modules/2.6.32-642.el6.x86_64/kernel /fs/ext4/ext4.ko
#通过depmod生成的配置文件查询
[[email protected] ~]# grep ' \<ext4\> '/lib/modules/$ (uname-r)/modules.depkernel/fs/ext4/ext4.ko:kernel/fs/ Jbd2/jbd2.ko Kernel/fs/mbcache.ko
#当然如果此模块已经被加载, you can also view dependencies by Lsmod
[Email protected] ~]# Lsmod | grep ' \<ext4\> ' ext4 379655 3 jbd2 93252 1 ext4mbcache 8193 1 E Xt4
View module specific parameters
Modprobe-c
#查看isofs的具体参数
[Email protected] ~]# Modprobe-c | grep ' \<isofs\> ' Alias iso9660 isofs
Parse: There are no additional kernel parameters, but an alias is defined as iso9660.
View the options used when loading a specified module
Systool-v-M Module_name
#查看ext4的具体选项属性
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/87/E6/wKiom1fj-caDBVF4AAAXK88LQi4934.png "title=" Systool.png "alt=" Wkiom1fj-cadbvf4aaaxk88lqi4934.png "/>
Loading the Unload module manually
Modprobe modprobe_name #指定模块名称卸载模块modprobe-R modprobe_name #指定模块名称卸载模块 Insmod/path/to/modprobe.ko #指定模块文件路径加载模块rmmod/path/to/modprobe.ko #指定模块文件路径卸载模块
parsing: Can be modinfo-n module_name to see the module's file storage path, if the module function is being used by the program is not uninstalled, if you want to uninstall, you can use the-F option to force the uninstall, This option is supported by both Modprobe and Rmmod, but it is not recommended to force uninstallation unless a system failure occurs.
Advanced Configuration of module functions
At the beginning of the CentOS6 system, the udev loading mechanism was used, and all the necessary modules were loaded automatically by Udev . Therefore, if you do not need any additional modules, it is not necessary to add the modules loaded at startup in any configuration file. However, in some cases it may be necessary to load an additional module at system startup, or to blacklist a module for the system to function properly.
Module Loading on Boot
The SYSTEMD process reads the configuration profile from the/etc/modules-load.d/directory to load additional kernel modules, which are typically/etc/modules-load.d/<program>.conf, and the format is simple, One line of the module name to read, and the blank line and the first non-whitespace character is # or the row is ignored, such as:
#查看虚拟化驱动目录
[Email protected] ~]# Ls/usr/lib/modules/3.10.89/kernel/drivers/virtio/virtio_balloon.ko Virtio.ko Virtio_pci.ko Virtio_ring.ko
#希望开机加载额外的virtio-net Drive
[Email protected] ~]# vim/etc/modules-load.d/virtio.conf[[email protected] ~]# cat/etc/modules-load.d/virtio.conf # Load Virtio.ko at Bootvirtio
Tip: Configure to see Man Help Manual, man 5 modules-load.d
Small Case: The solution CD cannot be mounted and the system cannot recognize the disc file system.
#挂载光盘, a mount error was found
[Email protected] ~]# mount/dev/cdrom/mnt/cdrom/mount:unknown filesystem type ' iso9660 '
Description: This prompts the unrecognized file system iso8660 type, starts to speculate whether it is necessary to mount the specified type, is mount when the problem occurs, and then mount again.
#再次挂载 and specify the type with MOUNT-T
[Email protected] ~]# mount-t iso9660/dev/cdrom/mnt/cdrommount:unknown filesystem type ' ISO9660 '
Description: Still not, the current system kernel does not support the iso9660 file system? It then looks at the file system categories supported by the current system kernel module.
#查看当前内核支持的文件系统
[Email protected] ~]# Cat/proc/filesystems Nodevsysfsnodevrootfsnodevbdevnodevprocnodevcgroupnodevcpusetnodevtmpfsnodevdevtmpfsnodevdebugfsnodevsecurityfsnodevsockf Snodevpipefsnodevanon_ Inodefsnodevconfigfsnodevdevptsnodevramfsnodevhugetlbfsnodevautofsnodevpstorenodevmqueuenodevselinuxfsext4
Description: Where Nodev indicates that this feature has been loaded but is not being used by the device or process, the left blank character indicates that the device is being used. Therefore, it is found that there is autofs automatic mount function, there is no iso9660 file system module.
#于是开始查看iso9660需要的模块, use the Depmod command to regenerate the dependent configuration before viewing
[Email protected] ~]# depmod-a
#然后通过滤iso来查找对应的配置文件
[[email protected] ~]# grep ' \<iso '/usr/lib/modules/$ (uname-r)/modules.depkernel/fs/isofs/isofs.ko:
parsing: The Isofs file system module is found here, and there are no other modules that show that the module is not dependent on other modules, so it can be loaded directly.
#加载模块, but the full path is displayed relative to the/usr/lib/modules/version number/kernel directory below
[Email protected] ~]# insmod/usr/lib/modules/$ (uname-r)/kernel/fs/isofs/isofs.ko
#检查是否已经加载isofs模块
[Email protected] ~]# Lsmod | grep ' \<isofs\> ' isofs 39846 0 [[email protected] ~]# grep ' \<isofs\> '/proc/modules isofs 39 846 0-live 0xffffffffa022b000
#确定加载isofs模块后, try mounting again
[Email protected] ~]# Mount/dev/cdrom/mnt/cdrom/mount:/dev/sr0 is write-protected, mounting read-only
#查看是否已经挂载成功
[Email protected] ~]# findmnt/dev/cdrom TARGET SOURCE fstype options/mnt/cdrom/dev/sr0 iso9660 ro,relatime
#将isofs文件系统模块设置开启自动加载, modify the configuration file
[Email protected] ~]# cat/etc/modules-load.d/virtio.conf # load Virtio.ko at Bootvirtio #这里表示 Module name
Parsing: File name is generally recommended to be set to the name of the module, no line below can add a module name, boot will automatically load each of the specified module name module from these configuration files.
#然后reboot重启测试
[email protected] ~]# reboot
#重启机器后 to see if the Isofs module is currently loaded
[Email protected] ~]# Lsmod | grep ' \<isofs\> ' isofs 39846 0 [[email protected] ~]# grep ' \<isofs\> '/proc/modules isofs 39 846 0-live 0xffffffffa0129000
#再次查看此时内核支持的文件系统列表
[Email protected] ~]# Cat/proc/filesystems
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/87/E7/wKiom1fj-umBF9ISAAAdnEgMAX4209.png " Title= "Procfilesystems.png" alt= "Wkiom1fj-umbf9isaaadnegmax4209.png"/>
Parsing: This shows that there is a iso9660 just set to indicate that this format will be loaded after it is opened, no longer the image file system format that is encountered in the ISO9660 format is not supported.
Summary and questions left:
This piece of paper once again collated the relevant commands for module management and its usage, and supplemented by a problem encountered to illustrate the module management of some ideas. Whether the file system, hardware device drivers, and service calls, as long as the function is not supported, it is likely that the module function does not load properly, and the program files need to rely on the corresponding library files, inseparable. Modules are loaded through some configuration, then what mechanism in the kernel to read the modprobe.conf configuration to load the corresponding module parameters? How do you identify an accessible file for each of the hardware that is identified by the driver after loading the hardware? Are these questions left? Of course, the problem of modules can only be dealt with after a continuous process to deal with the problem of loading mechanism.
This article from "Meng Tian pa-it garbage Collection Station" blog, declined reprint!
Linux Primer CentOS7 Kernel compilation trilogy (3)