Linux内核动态加载模块(2)

二:安装完成以后,我们就可以加载模块了:

和linux中加载模块有关的几个命令分别如下:
depmod, modprobe, lsmod

先来看看depmod命令:

depmod是一个用来产生modules.dep和map文件的程序。在modules.dep文件中空白行和以'#'开头的行将被忽略.depmod通过读取/lib /modules/version目录下的每一个模块来创建一个记录模块相依性的列表。这个列表就是/lib/modules/version目录下的 modules.dep。depmod也会在/lib/modules/version目录下创建许多map文件,例如 modules.dep,modules.isapnpmap,modules.pcimap,modules.alias这些文件将会被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

再来看看modprobe命令:

modprobe 命令是根据depmod -a的输出/lib/modules/version/modules.dep来加载全部的所需要模块。可以通过modprobe -l来显示可以当前可以加载的模块。modprobe 在挂载模块是不用指定模块文件的路径,也不用带文件的后缀.o 或.ko, 而insmod 需要的是模块的所在目录的绝对路径,并且一定要带有模块文件名后缀的(modulefile.o 或modulesfile.ko )。 insmod比较重要的用途是用来测试模块的正确性,加载一般都是依靠modprobe。

用法:modprobe xxx.ko        #加载某个模块
modprobe -r xxx.ko     #卸载某个模块

lsmod:

lsmod 显示当前加载的所有 模块,相当于cat /proc/modules,假设你没有设定开机加载某个模块,比如ntfs,那么开机后执行lsmod,列表里不会有ntfs这个模块的,这时你再执行 mount -t ntfs xxx后,执行lsmod后列表里就会有ntfs这个模块了。
还要注意的是lsmod显示的是模块名,而不是别名(alias)。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpdfp.html