cat /proc/modules
第一列: 模块的名字
第二列: 模块的内存大小,单位是bytes
第三列: 被load的次数,0以为着没有被load过
第四列: 是否依赖第三方moudle,列出这些module,不依赖第三方moudle使用-代替
第五列: 模块的状态,有Live, Loading, Unloading三种状态
第六列: 模块当前的内核内存偏移位置。这些信息,debug的时候会非常有用。例如一些诊断工具 oprofile。

[root@centos7-10 ~]# cat /proc/modules
xt_CHECKSUM 12549 1 - Live 0xffffffffc0763000
ipt_MASQUERADE 12678 3 - Live 0xffffffffc075e000
nf_nat_masquerade_ipv4 13412 1 ipt_MASQUERADE, Live 0xffffffffc074f000
tun 31665 1 - Live 0xffffffffc0755000
devlink 42368 0 - Live 0xffffffffc0743000
ip6t_rpfilter 12595 1 - Live 0xffffffffc073e000
ipt_REJECT 12541 4 - Live 0xffffffffc0739000
nf_reject_ipv4 13373 1 ipt_REJECT, Live 0xffffffffc0734000
ip6t_REJECT 12625 2 - Live 0xffffffffc072f000
nf_reject_ipv6 13717 1 ip6t_REJECT, Live 0xffffffffc072a000
xt_conntrack 12760 12 - Live 0xffffffffc071a000
ip_set 40680 0 - Live 0xffffffffc071f000
nfnetlink 14490 1 ip_set, Live 0xffffffffc070e000
ebtable_nat 12807 1 - Live 0xffffffffc0709000
ebtable_broute 12731 1 - Live 0xffffffffc0715000
bridge 146976 1 ebtable_broute, Live 0xffffffffc06e4000
stp 12976 1 bridge, Live 0xffffffffc06df000
llc 14552 2 bridge,stp, Live 0xffffffffc06d6000
ip6table_nat 12864 1 - Live 0xffffffffc06d1000
nf_conntrack_ipv6 18935 7 - Live 0xffffffffc06cb000
nf_defrag_ipv6 35104 1 nf_conntrack_ipv6, Live 0xffffffffc06bd000
nf_nat_ipv6 14131 1 ip6table_nat, Live 0xffffffffc06b4000
ip6table_mangle 12700 1 - Live 0xffffffffc06af000
ip6table_security 12710 1 - Live 0xffffffffc06aa000
ip6table_raw 12683 1 - Live 0xffffffffc06a5000
iptable_nat 12875 1 - Live 0xffffffffc06a0000
nf_conntrack_ipv4 15053 7 - Live 0xffffffffc069b000
nf_defrag_ipv4 12729 1 nf_conntrack_ipv4, Live 0xffffffffc068d000
nf_nat_ipv4 14115 1 iptable_nat, Live 0xffffffffc0684000
nf_nat 26787 3 nf_nat_masquerade_ipv4,nf_nat_ipv6,nf_nat_ipv4, Live 0xffffffffc0693000
nf_conntrack 133053 7 nf_nat_masquerade_ipv4,xt_conntrack,nf_conntrack_ipv6,nf_nat_ipv6,nf_conntrack_ipv4,nf_nat_ipv4,nf_nat, Live 0xffffffffc0662000
libcrc32c 12644 2 nf_nat,nf_conntrack, Live 0xffffffffc065d000
iptable_mangle 12695 1 - Live 0xffffffffc0658000
iptable_security 12705 1 - Live 0xffffffffc0653000
iptable_raw 12678 1 - Live 0xffffffffc05a1000
ebtable_filter 12827 1 - Live 0xffffffffc0477000
ebtables 35009 3 ebtable_nat,ebtable_broute,ebtable_filter, Live 0xffffffffc0649000
ip6table_filter 12815 1 - Live 0xffffffffc0472000
ip6_tables 26912 5 ip6table_nat,ip6table_mangle,ip6table_security,ip6table_raw,ip6table_filter, Live 0xffffffffc0466000
iptable_filter 12810 1 - Live 0xffffffffc0461000
sunrpc 353310 1 - Live 0xffffffffc05f1000
coretemp 13444 0 - Live 0xffffffffc05a6000
iosf_mbi 14990 0 - Live 0xffffffffc05ec000
gpio_ich 13476 0 - Live 0xffffffffc0567000
crc32_pclmul 13133 0 - Live 0xffffffffc058d000
snd_intel8x0 38199 0 - Live 0xffffffffc0596000
snd_ac97_codec 130556 1 snd_intel8x0, Live 0xffffffffc056c000
ghash_clmulni_intel 13273 0 - Live 0xffffffffc05df000
ac97_bus 12730 1 snd_ac97_codec, Live 0xffffffffc05e7000
snd_seq 62785 0 - Live 0xffffffffc05ce000
snd_seq_device 14356 1 snd_seq, Live 0xffffffffc05c5000
ppdev 17671 0 - Live 0xffffffffc04e3000
snd_pcm 101643 2 snd_intel8x0,snd_ac97_codec, Live 0xffffffffc05ab000

lsmod命令

lsmod的输出,是基于/proc/modules文件.

[root@centos7-10 ~]# lsmod
Module                  Size  Used by
xt_CHECKSUM            12549  1 
ipt_MASQUERADE         12678  3 
nf_nat_masquerade_ipv4    13412  1 ipt_MASQUERADE
tun                    31665  1 
devlink                42368  0 
ip6t_rpfilter          12595  1 
ipt_REJECT             12541  4 
nf_reject_ipv4         13373  1 ipt_REJECT
ip6t_REJECT            12625  2 
nf_reject_ipv6         13717  1 ip6t_REJECT
xt_conntrack           12760  12 
ip_set                 40680  0 
nfnetlink              14490  1 ip_set
ebtable_nat            12807  1 
ebtable_broute         12731  1 
bridge                146976  1 ebtable_broute
stp                    12976  1 bridge
llc                    14552  2 stp,bridge
ip6table_nat           12864  1 
nf_conntrack_ipv6      18935  7 
nf_defrag_ipv6         35104  1 nf_conntrack_ipv6
nf_nat_ipv6            14131  1 ip6table_nat
ip6table_mangle        12700  1 
ip6table_security      12710  1 
ip6table_raw           12683  1 

为了在稳定性和可用性之间达成有效的平衡,Linux 将内核隔离,但是允许您通过可加载内核模块 (LKM) 实时添加特定的功能。如下图所示,您可以将模块视为软件的一部分,它告诉内核在哪里找到一个设备以及如何使用它。反过来,内核使设备对用户和进程可用,并监视其操作。

使用命令

ls /lib/modules/`uname -r`

结果如下:

[root@centos7-10 rbtree]# ls /lib/modules/`uname -r`
build          modules.alias.bin    modules.dep      modules.modesetting  modules.symbols      vdso
extra          modules.block        modules.dep.bin  modules.networking   modules.symbols.bin  weak-updates
kernel         modules.builtin      modules.devname  modules.order        source
modules.alias  modules.builtin.bin  modules.drm      modules.softdep      updates
[root@centos7-10 rbtree]# ls /lib/modules/`uname -r`/kernel
arch  crypto  drivers  fs  kernel  lib  mm  net  sound  virt
[root@centos7-10 rbtree]# 

在kernel中可以看到所有模块。

lsmod |wc -l

modprobe -c | wc -l

find /lib/modules/$(uname -r) -type f -name ath9k*

[root@centos7-10 rbtree]# find /lib/modules/$(uname -r) -type f -name ath9k*
/lib/modules/3.10.0-862.el7.x86_64/kernel/drivers/net/wireless/ath/ath9k/ath9k_common.ko.xz
/lib/modules/3.10.0-862.el7.x86_64/kernel/drivers/net/wireless/ath/ath9k/ath9k_htc.ko.xz
/lib/modules/3.10.0-862.el7.x86_64/kernel/drivers/net/wireless/ath/ath9k/ath9k.ko.xz
/lib/modules/3.10.0-862.el7.x86_64/kernel/drivers/net/wireless/ath/ath9k/ath9k_hw.ko.xz

查找该模块是否已加载,没有加载的话加载ath9k模块:

[root@centos7-10 rbtree]# lsmod | grep ath9k
[root@centos7-10 rbtree]# modprobe ath9k
[root@centos7-10 rbtree]# lsmod | grep ath9k
ath9k                 136707  0 
ath9k_common           36236  1 ath9k
ath9k_hw              491188  2 ath9k_common,ath9k
ath                    29446  3 ath9k_common,ath9k,ath9k_hw
mac80211              714741  1 ath9k
cfg80211              623394  4 ath,ath9k_common,ath9k,mac80211
[root@centos7-10 rbtree]# 

使用rmmod去卸载模块。