一、基本介紹
1、這些命令安裝在“kmod”包中,系統通常已經安裝了,如果沒有安裝請安裝:
[root@localhost ]# rpm -ql kmod|grep sbin /usr/sbin/depmod /usr/sbin/insmod /usr/sbin/lsmod /usr/sbin/modinfo /usr/sbin/modprobe /usr/sbin/rmmod /usr/sbin/weak-modules
2、CentOS中所有與內核模塊相關的文件都存放在"/lib/modules/$(uname -r)/“下面(不管32位還是64位系統,都在/lib/...之下):
[root@localhost ~]# cd /lib/modules/$(uname -r)/ [root@localhost 3.10.0-123.el7.x86_64]# ls build modules.builtin modules.modesetting source extra modules.builtin.bin modules.networking updates kernel modules.dep modules.order vdso modules.alias modules.dep.bin modules.softdep modules.alias.bin modules.devname modules.symbols modules.block modules.drm modules.symbols.bin
二、命令介紹
1、lsmod:查看內核已加載的模塊
[root@localhost ~]# lsmod|head -4 Module Size Used by ip6table_filter 12815 0 ip6_tables 27025 1 ip6table_filter iptable_filter 12810 0
2、modinfo:查看模塊的基本信息
[root@localhost ~]# modinfo /lib/modules/3.10.0-123.el7.x86_64/kernel/fs/ext4/ext4.ko filename: /lib/modules/3.10.0-123.el7.x86_64/kernel/fs/ext4/ext4.ko license: GPL description: Fourth Extended Filesystem author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others alias: fs-ext4 alias: ext3 alias: fs-ext3 alias: ext2 alias: fs-ext2 srcversion: 7854620F0551D7F88A126F0 depends: mbcache,jbd2 intree: Y vermagic: 3.10.0-123.el7.x86_64 SMP mod_unload modversions signer: CentOS Linux kernel signing key sig_key: BC:83:D0:FE:70:C6:2F:AB:1C:58:B4:EB:AA:95:E3:93:61:28:FC:F4 sig_hashalgo: sha256
3、insmod:將指定模塊加載到內核,建議使用modeprobe命令
4、rmmod:將已加載模塊從內核中移除,建議使用modeprobe命令
5、modprobe:加載或卸載內核模塊,需要根據modules.dep.bin文件進行加載操作,可以自動解決模塊間的依賴關系表
[root@localhost ~]# lsmod|grep ext4 [root@localhost ~]# modprobe ext4 #加載模塊 [root@localhost ~]# lsmod|grep ext4 ext4 528957 0 mbcache 14958 1 ext4 jbd2 98341 1 ext4 [root@localhost ~]# modprobe -r ext4 #卸載模塊 [root@localhost ~]# lsmod|grep ext4
6、depmod:查找/lib/moduels/(uname -r)/中的所有模塊並建立modules.dep.bin文件,該文件記錄了模塊位置及依賴關系
[root@localhost ~]# cd /lib/modules/$(uname -r)/ [root@localhost 3.10.0-123.el7.x86_64]# ls|grep dep modules.dep modules.dep.bin modules.softdep [root@localhost 3.10.0-123.el7.x86_64]# rm -rf modules.dep.bin [root@localhost 3.10.0-123.el7.x86_64]# modprobe ext4 modprobe: FATAL: Module ext4 not found. [root@localhost 3.10.0-123.el7.x86_64]# depmod -a #生成文件 [root@localhost 3.10.0-123.el7.x86_64]# modprobe ext4 [root@localhost 3.10.0-123.el7.x86_64]# lsmod|grep ext4 ext4 528957 0 mbcache 14958 1 ext4 jbd2 98341 1 ext4 [root@localhost 3.10.0-123.el7.x86_64]# ls|grep dep modules.dep modules.dep.bin modules.softdep