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

转载原文:https://www.cnblogs.com/hanxiaomeng/p/12728104.html

一、基本介绍

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)/“下面:

[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
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值