rmmod
功能:删除内核中的一模块
用法:rmmod [ -f ] [ -w ] [ -s ] [ -v ] [ modulename ]
描述:
rmmod是一个可以从内核中删除模块的小程序,大多数用户使用modprobe -r去删除模块。
选项:
-v –verbose 显示程序正在做些什么,一般只显示执行时的错误信息。
-f –force 该选项是非常危险:除非编译内核时,CONFIG_MODULE_FORCE_UNLOAD被设置该命令才有效果,否则没效果。用该选项可以删除正在被使用的模块,设计为不能删除的模块,或者标记为unsafe的模块。
-w –wait 通常,rmmod拒绝删除正在被使用的模块。使用该选项后,指定的模块会被孤立起来,直到不被使用。
-s –syslog 将错误信息写入syslog,而不是标准错误(stderr)。
-V –version 版本信息
以上内容是参考man翻译的,若有疑问请用man …查看原始文档,翻译可能有误。
其它:
(1)lsmod 显示当前加载的所有模块,相当于cat /proc/modules,
假设你没有设定开机加载某个模块,比如ntfs,那么开机后执行lsmod,列表里不会有ntfs这个模块的,
这时你再执行 mount -t ntfs xxx后,执行lsmod后列表里就会有ntfs这个模块了。
还要注意的是lsmod显示的是模块名,而不是别名(alias)。
(2) modprobe与insmod
modprobe -l #显示当前可以加载的模块
modprobe xxx.ko #加载某个模块
modprobe -r xxx.ko #卸载某个模块
通过了解modprobe的manpage我们知道,我可以通过modprobe -l来显示可以当前可以加载的模块,所谓当前可以加载的模块,
实际上就是modules.dep文件中包含的那些模块,而不是manpage里说的modprobe会加载/lib/modules/`uname -r`下的所有模块(也许是我理解错误),下面我们将会证明这一点.
insmod 与 modprobe 都是载入 kernel module,不过一般差别于 modprobe 能够处理 module 载入的相依问题。
比方你要载入 a module,但是 a module 要求系统先载入 b module 时,直接用 insmod 挂入通常都会出现错误讯息,不过 modprobe 倒是能够知道先载入 b module 后才载入 a module,如此相依性就会满足。
不过 modprobe 并不是大神,不会厉害到知道 module 之间的相依性为何,该程式是读取 /lib/modules/2.6.xx/modules.dep 档案得知相依性的。而该档案是透过 depmod 程式所建立。
(3)上面(1)中提到modprobe加载某个模块是根据/lib/modules/`uname -r`目录下的modules.dep文件中的模块列表,这个文件中有的模块modprobe会正确加载,否则就会出错。
我们还拿ntfs这个模块来举例:
vi /lib/modules/`uname -r`/modules.dep
注释掉/lib/modules/2.6.18-4-k7/kernel/fs/ntfs/ntfs.ko这一行,就是加个#号.
这个修改是即使生效的。
modinfo ntfs
modinfo: could not find module ntfs
modprobe ntfs
FATAL: Module ntfs not found.
重启机器,执行同样的命令会得到同样的结果,说明开机不会自动执行depmod的,而
locate ntfs.ko
/lib/modules/2.6.18-4-k7/kernel/fs/ntfs/ntfs.ko
证明我们并没有转移ntfs模块。
注意如果重启机器之前进行mount还是可以的,重启之后就会报错了,而上边的都是即时生效的。
还有如果modules.dep里注释掉了ntfs,那么在/etc/modules里写上也是不起作用的,说明这个和mount一样都是依赖 modprobe来完成加载模块命令的。而insmod是可以的,因为insmod后面跟的是绝对路径,它和modules.dep没什么关系。 insmod比较重要的用途是用来测试模块的正确性,加载一般都是依靠modprobe。(这个可能也不起作用了,都用modprobe吧)
这一切只是因为我们注释掉了modules.dep中关于ntfs.ko的那一行,而模块并没有删除或转移。既然modules.dep文件如此重要,那么它是怎么生成的呢?这就和下一个命令有关了,depmod。
(4)depmod
man depmod
depmod -- program to generate modules.dep and map files. Blank lines, and lines starting with a '#' (ignoring spaces) are ignored in modules.dep.
depmod是一个用来产生modules.dep和map文件的程序。在modules.dep文件中空白行和以'#'开头的行将被忽略.
Linux kernel modules can provide services (called "symbols") for other
modules to use (using EXPORT_SYMBOL in the code).
linux核心模块可以提供服务给其他模块,称之为"symbols"
depmod creates a list of module dependencies, by reading each module
under /lib/modules/version and determining what symbols it exports, and
what symbols it needs.
depmod通过读取/lib/modules/version目录下的每一个模块来创建一个记录模块相依性
的列表。这个列表就是/lib/modules/version目录下的modules.dep。
If a version is provided, then that kernel version's module directory
is used, rather than the current kernel version (as returned by "uname
-r").
如果给定version的话,那么depmod会检查这个version对应的modules目录而不是
当前运行的kernel对应的modules目录。
depmod will also generate various map files in this directory, for use
by the hotplug infrastructure.
depmod也会在/lib/modules/version目录下创建许多map文件,这些文件将会被hotplug用到。
OPTIONS:
-a --all Probe all modules. This option is enabled by default if no
file names are given in the command-line.
检查所有的模块,这个命令是默认的如果你没有指定模块名字的话。
-A --quick This option scans to see if any modules are newer than the
modules.dep file before any work is done%3
推荐阅读
-
深入解析Linux内核模块管理命令:lsmod、insmod、rmmod、modinfo、modprobe、depmod
-
【linux】内核模块管理:深入探索lsmod、insmod、rmmod、modinfo、modprobe、depmod命令
-
对Linux内核模块进行管理的详解:lsmod、insmod、rmmod、modinfo、modprobe、depmod命令解析
-
使用说明:探究linux内核模块相关命令的用法:lsmod, depmod, modprobe, modinfo, insmod, rmmod
-
Linux驱动模块相关命令:insmod/rmmod/lsmod (第10部分)
-
使用insmod、lsmod和rmmod在Linux下操作模块
-
linux内核模块相关命令:lsmod,depmod,modprobe,modinfo,insmod,rmmod 使用说明
-
完整介绍Linux驱动模块命令insmod/rmmod/modprobe/depmod/lsmod
-
内核模块操纵命令: lsmod, rmmod, modinfo, modprobe
-
深入了解内核和内核模块:depmod, lsmod, modinfo, insmod, rmmod, mdprobe