乒乓世界杯_u20世界杯最新战况 - chhtzx.com

Linux内核模块管理:lsmod、insmod、rmmod、modinfo、modprobe、depmod命令详解

4333

一、基本介绍

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