If you cant explain it simply, you dont understand it well enough

[Linux 运维]/proc/modules 以及内核模块工具

[Linux 运维] /proc/modules 以及内核模块工具

1. 基本情况

这个文件列出了所有load进入内核的模块列表。里面的内容会随着系统使用和配置的变化而变化。这里面的很多信息可以通过lsmod 命令获取

# cat /proc/modules
ipv6 334932 54 - Live 0xffffffffa00dd000
xenfs 5705 1 - Live 0xffffffffa00d8000
dm_mod 95622 0 - Live 0xffffffffa00b5000
xen_netfront 18994 0 - Live 0xffffffffa00a4000
i2c_piix4 11776 0 - Live 0xffffffffa009e000
i2c_core 29964 1 i2c_piix4, Live 0xffffffffa0090000
ext3 240580 1 - Live 0xffffffffa003f000
jbd 80950 1 ext3, Live 0xffffffffa0022000
mbcache 8193 1 ext3, Live 0xffffffffa001b000
xen_blkfront 15329 2 - Live 0xffffffffa0013000
pata_acpi 3701 0 - Live 0xffffffffa000f000
ata_generic 3837 0 - Live 0xffffffffa000b000
ata_piix 24409 0 - Live 0xffffffffa0000000
  • 第一列: 模块的名字
  • 第二列: 模块的内存大小,单位是bytes
  • 第三列: 被load的次数,0以为着没有被load过
  • 第四列: 是否依赖第三方moudle,列出这些module
  • 第五列: 模块的状态,有LiveLoadingUnloading三种状态
  • 第六列: 模块当前的内核内存偏移位置。这些信息,debug的时候会非常有用。例如一些诊断工具 oprofile

2. 相关工具

(1) lsmod

lsmod的输出,是基于/proc/modules

Module                  Size  Used by
ipv6                  334932  54 
xenfs                   5705  1 
dm_mod                 95622  0 
xen_netfront           18994  0 
i2c_piix4              11776  0 
i2c_core               29964  1 i2c_piix4
ext3                  240580  1 
jbd                    80950  1 ext3
mbcache                 8193  1 ext3
xen_blkfront           15329  2 
pata_acpi               3701  0 
ata_generic             3837  0 
ata_piix               24409  0 

(2)insmod

向内核中插入一个模块

(3)rmmod

删除内核中的一个模块

(4)modprobe

增加和删除内核中的模块(modprobe - program to add and remove modules from the Linux Kernel),现在比较多的用这个。

(5)modinfo

看内核模块的信息:

# modinfo xen_netfront
filename:       /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/xen-netfront.ko
alias:          xennet
alias:          xen:vif
license:        GPL
description:    Xen virtual network device frontend
srcversion:     5C6FC78BC365D9AF8135201
depends:        
vermagic:       2.6.32-504.el6.x86_64 SMP mod_unload modversions 

(6)depmod

分析可加载模块的依赖性,生成modules.dep文件和映射文件。

posted @ 2015-08-19 19:44  zk47  阅读(3986)  评论(0编辑  收藏  举报

I am a stupid bird, and I need to work hard