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 特别简单,只需要使用 modprobe module名 就行了。
其中 module 名 中无需带 .ko 或 .ko.xz 的后缀名,也无需指定文件路径。
像这样:
sudo modprobe vboxvideo
卸载 module 也很简单,只需要使用 rmmod module名 就行了。
其中 module名 中也无需带 .ko 或 .ko.xz 的后缀名,也无需指定文件路径。
像这样:
sudo rmmod vboxvideo
