linux内核模块相关命令:lsmod,depmod,modprobe,modinfo,insmod,rmmod 使用说明
加载内核驱动的通常流程:
1.先将.ko文件拷贝到/lib/module/`uname -r`(内核版本号)/kernel/driver/...目录下,
根据具体用途的区别分为net、ide、scsi、usb、video、parport、md、block、ata等等。
2.运行depmod -a,更新模块依赖新,主要是更新modules.dep文件
3.运行modprobe加载内核模块
lsmod
depmod
modprobe
modinfo
insmod
rmmod
以上内容是参考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,depmod,modprobe,modinfo,insmod,rmmod 使用说明的更多相关文章
- Linux文件管理相关命令
Linux文件管理相关命令 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在了解了Linux文件管理背景知识之后, 我们可以 ...
- Linux进程相关命令使用场景
Linux进程相关命令使用场景 在Linux系统上工作时,我们常常会碰到很多和进程相关的查询场景,今天在这里进行详细的讲解,进程相关的对象包括以下几个: 端口:Port 进程号:PId 执行文件所在路 ...
- Linux 网络相关命令 Cheat Sheet
以下漫画形式呈现的常用 Linux 网络相关命令速查表来自 twitter -
- Linux性能相关命令
Linux性能相关命令 目录 Linux性能相关命令 1. 查看硬盘相关信息 2. 查看CPU相关信息 3. 查看内存相关信息 4. 查看进程运行的信息 1. 查看硬盘相关信息 cat /proc/s ...
- Linux解压缩相关命令
Linux解压缩相关命令 运行级别: 0:关机 1:单用户 2:多用户无网络连接 3:多用户有网络连接 4:系统保留 5:图形界面 6:系统重启 通过init[0123456]来切换不同的运行级别 g ...
- Linux 文本相关命令(1)
Linux 文本相关命令(1) 前言 最近线上环境(Windows Server)出现了一些问题,需要分析一下日志.感觉 Windows 下缺少了一些 Linux 系统中的小工具,像在这波操作中用到的 ...
- Linux文本相关命令
Linux文本相关命令 目录 Linux文本相关命令 文本排序命令 文本去重命令 基础命令cut 文本三剑客 sed awk grep 文本排序命令 sort 常用参数: -n:以数值大小进行排序 - ...
- Linux内核模块管理命令
1.insmod命令 在Linux系统下,insmod命令用于将给定的模块加载到内核中去,Linux系统有许多功能是通过模块的方式,在需要时才载入kernel,这样做可以使kernel较为精简,进而提 ...
- linux:相关命令以及笔记
首先,在linux 或者 unix里没有任何的反馈就叫成功,例如: (1)命令执行成功的样子:返回了登录用户信息 (2)命令执行失败的样子:没有返回任何东西 1.按键出现状况 解决:可以使用ctrl+ ...
随机推荐
- C++STL库之set的用法
/*set意为集合,是一个内部自动排序不含重复元素的容器*/#include<stdio.h>#include<set>using namespace std;int main ...
- code::blocks(版本10.05) 配置opencv2.4.3
(1)首先下载opencv2.4.3, 解压缩到D:下: (2)配置code::blocks, 具体操作如下: 第一步, 配置compiler, 操作步骤为Settings -> Compil ...
- Base适配器
package com.baidu.base; import java.util.List; import com.baidu.vo.Mydata;import com.bwie.yd.R;impor ...
- php部分---函数、四类常用函数、例子(下拉菜单添加内容);
1.简单函数 四要素:返回类型,函数名,参数列表,函数体 function Show() { echo "hello"; } Show(); 2.有返回值的函数 function ...
- leetcode 127. Word Ladder ----- java
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...
- leetcode 115 Distinct Subsequences ----- java
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- <老友记>学习笔记
这是六个人的故事,从不服输而又有强烈控制欲的monica,未经世事的千金大小姐rachel,正直又专情的ross,幽默风趣的chandle,古怪迷人的phoebe,花心天真的joey——六个好友之间的 ...
- javascrip中的confirm小技巧
jsp页面中的一个标签: <a href="javascript:void(0)" onclick="confirmDelete('<%=request.ge ...
- centos 编译swoole
/usr/include/php/ext/pcre/php_pcre.h:45: error: expected '=', ',', ';', 'asm' or '__attribute__' bef ...
- Spark 优化器 ML的论文
http://people.csail.mit.edu/matei/papers/2015/sigmod_spark_sql.pdf http://www.vldb.org/pvldb/vol4/p5 ...