3

如何加载linux kernel module

 2 years ago
source link: https://www.lujun9972.win/blog/2018/06/04/%E5%A6%82%E4%BD%95%E5%8A%A0%E8%BD%BDlinux-kernel-module/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何加载linux kernel module

kernel module存放在哪里

linux自带了很多kernel module文件, 这些文件一般以 .ko.ko.xz 文件结尾,存放在 /lib/module/$(uname -r) 目录中。

ls -l /lib/modules/$(uname -r)
总用量 5844
drwxr-xr-x  3 root root    4096 6月   1 12:04 build
lrwxrwxrwx  1 root root      25 5月  26 08:26 extramodules -> ../extramodules-4.16-ARCH
drwxr-xr-x 12 root root    4096 6月   1 12:04 kernel
-rw-r--r--  1 root root 1373746 6月   1 12:05 modules.alias
-rw-r--r--  1 root root 1351352 6月   1 12:05 modules.alias.bin
-rw-r--r--  1 root root    4820 5月  26 08:24 modules.builtin
-rw-r--r--  1 root root    6584 6月   1 12:05 modules.builtin.bin
-rw-r--r--  1 root root  708369 6月   1 12:05 modules.dep
-rw-r--r--  1 root root  939730 6月   1 12:05 modules.dep.bin
-rw-r--r--  1 root root     433 6月   1 12:05 modules.devname
-rw-r--r--  1 root root  210735 5月  26 08:24 modules.order
-rw-r--r--  1 root root     598 6月   1 12:05 modules.softdep
-rw-r--r--  1 root root  610067 6月   1 12:05 modules.symbols
-rw-r--r--  1 root root  746894 6月   1 12:05 modules.symbols.bin

大部分的module file都按类别分好类存放在其中的 kernel 目录中。

ls -l /lib/modules/$(uname -r)/kernel
总用量 40
drwxr-xr-x   3 root root 4096 6月   1 12:04 arch
drwxr-xr-x   3 root root 4096 6月   1 12:04 crypto
drwxr-xr-x 102 root root 4096 6月   1 12:04 drivers
drwxr-xr-x  48 root root 4096 6月   1 12:04 fs
drwxr-xr-x   6 root root 4096 6月   1 12:04 lib
drwxr-xr-x   2 root root 4096 6月   1 12:04 mm
drwxr-xr-x  52 root root 4096 6月   1 12:04 net
drwxr-xr-x   3 root root 4096 6月   1 12:04 security
drwxr-xr-x  14 root root 4096 6月   1 12:04 sound
drwxr-xr-x   3 root root 4096 6月   1 12:04 virt

linux当然不可能将所有的module都加载进kernel,要查看目前加载了哪些module,可以执行 lsmod 命令:

lsmod |head
Module                  Size  Used by
rfcomm                 86016  4
nls_iso8859_1          16384  0
nls_cp437              20480  0
vfat                   24576  0
fat                    81920  1 vfat
uas                    28672  0
usb_storage            69632  1 uas
fuse                  118784  3
ipt_MASQUERADE         16384  1

如何加载module

加载module特别简单,只需要使用 modprobe module名 就行了。

其中 module名 中无需带 .ko.ko.xz 的后缀名,也无需指定文件路径。

sudo modprobe vboxvideo

卸载module

卸载module也很简单,只需要使用 rmmod module名 就行了。

其中 module名 中也无需带 .ko.ko.xz 的后缀名,也无需指定文件路径。

sudo rmmod vboxvideo

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK