副标题#e#
lsmod 命令能够告诉你当前系统上加载了哪些内核模块,以及关于使用它们的一些有趣的细节。
什么是 Linux 内核模块?
内核模块是可以根据需要加载到内核中或从内核中卸载的代码块,因此无需重启就可以扩展内核的功能。事实上,除非用户使用类似 lsmod
这样的命令来查询模块信息,否则用户不太可能知道内核发生的任何变化。
需要知道的重要一点是,在你的 Linux 系统上总会有很多可用的模块,并且如果你可以深入其中了解到很多细节。
lsmod
的主要用途之一是在系统不能正常工作时检查模块。然而,大多数情况下,模块会根据需要加载的,而且用户不需要知道它们如何运作。
显示内核模块
显示内核模块最简单的方法是使用 lsmod
命令。虽然这个命令包含了很多细节,但输出却是非常用户友好。
$ lsmod
Module Size Used by
snd_hda_codec_realtek 114688 1
snd_hda_codec_generic 77824 1 snd_hda_codec_realtek
ledtrig_audio 16384 2 snd_hda_codec_generic,snd_hda_codec_realtek
snd_hda_codec_hdmi 53248 1
snd_hda_intel 40960 2
snd_hda_codec 131072 4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel
,snd_hda_codec_realtek
snd_hda_core 86016 5 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel
,snd_hda_codec,snd_hda_codec_realtek
snd_hwdep 20480 1 snd_hda_codec
snd_pcm 102400 4 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda
_core
snd_seq_midi 20480 0
snd_seq_midi_event 16384 1 snd_seq_midi
dcdbas 20480 0
snd_rawmidi 36864 1 snd_seq_midi
snd_seq 69632 2 snd_seq_midi,snd_seq_midi_event
coretemp 20480 0
snd_seq_device 16384 3 snd_seq,snd_seq_midi,snd_rawmidi
snd_timer 36864 2 snd_seq,snd_pcm
kvm_intel 241664 0
kvm 626688 1 kvm_intel
radeon 1454080 10
irqbypass 16384 1 kvm
joydev 24576 0
input_leds 16384 0
ttm 102400 1 radeon
drm_kms_helper 180224 1 radeon
drm 475136 13 drm_kms_helper,radeon,ttm
snd 81920 15 snd_hda_codec_generic,snd_seq,snd_seq_device,snd_hda
_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd
_hda_codec_realtek,snd_timer,snd_pcm,snd_rawmidi
i2c_algo_bit 16384 1 radeon
fb_sys_fops 16384 1 drm_kms_helper
syscopyarea 16384 1 drm_kms_helper
serio_raw 20480 0
sysfillrect 16384 1 drm_kms_helper
sysimgblt 16384 1 drm_kms_helper
soundcore 16384 1 snd
mac_hid 16384 0
sch_fq_codel 20480 2
parport_pc 40960 0
ppdev 24576 0
lp 20480 0
parport 53248 3 parport_pc,lp,ppdev
ip_tables 28672 0
x_tables 40960 1 ip_tables
autofs4 45056 2
raid10 57344 0
raid456 155648 0
async_raid6_recov 24576 1 raid456
async_memcpy 20480 2 raid456,async_raid6_recov
async_pq 24576 2 raid456,async_raid6_recov
async_xor 20480 3 async_pq,raid456,async_raid6_recov
async_tx 20480 5 async_pq,async_memcpy,async_xor,raid456,async_raid6_re
cov
xor 24576 1 async_xor
raid6_pq 114688 3 async_pq,raid456,async_raid6_recov
libcrc32c 16384 1 raid456
raid1 45056 0
raid0 24576 0
multipath 20480 0
linear 20480 0
hid_generic 16384 0
psmouse 151552 0
i2c_i801 32768 0
pata_acpi 16384 0
lpc_ich 24576 0
usbhid 53248 0
hid 126976 2 usbhid,hid_generic
e1000e 245760 0
floppy 81920 0
#p#副标题#e#
你可以使用 modprobe
命令加载或卸载模块。使用下面这条命令,你可以找到特定模块关联的内核对象:
$ find /lib/modules/$(uname -r) -name floppy*
/lib/modules/5.0.0-13-generic/kernel/drivers/block/floppy.ko
如果你想要加载模块,你可以使用这个命令:
$ sudo modprobe floppy
总结
很明显,内核模块的加载和卸载非常重要。它使得 Linux 系统比使用通用内核运行时更加灵活和高效。这同样意味着你可以进行重大更改而无需重启,例如添加硬件。
【编辑推荐】
- 爬过这 6 个坡,你就能对 Linux 操作系统了如指掌
- 在Linux上为你的任务创建一个自定义的系统托盘指示器
- 何时需要关注Linux的内存用量?
- 如何在Linux中查找服务的端口号
- 在Linux上为你的任务创建一个自定义的系统托盘指示器
【责任编辑:庞桂玉 TEL:(010)68476606】
点赞 0