Linux命令:modprobe insmod 和modprobe的区别 使用modprobe命令来添加、删除模块

简介

Linux命令:modprobe 。
功能说明:自动处理可载入模块。
语  法:modprobe [-acdlrtvV][--help][模块文件][符号名称 = 符号值]。
补充说明:modprobe可载入指定的个别模块,或是载入一组相依的模块。modprobe会根据depmod所产生的相依关系,决定要载入哪些模块。若在载入过程中发生错误,在modprobe会卸载整组的模块。

内容

1、modprobe 命令是根据depmod -a的输出/lib/modules/version/modules.dep来加载全部的所需要模块。
2、删除模块的命令是:modprobe -r filename。
3、系统启动后,正常工作的模块都在/proc/modules文件中列出。使用lsmod命令也可显示相同内容。
4、在内核中有一个“Automatic kernel module loading"功能被编译到了内核中。当用户尝试打开某类型的文件时,内核会根据需要尝试加载相应的模块。/etc/modules.conf或 /etc/modprobe.conf文件是一个自动处理内核模块的控制文件。

2相关信息编辑

参数

-a或--all  载入全部的模块。
-c或--show-conf  显示所有模块的设置信息。
-d或--debug  使用排错模式。
-l或--list  显示可用的模块。
-r或--remove  模块闲置不用时,即自动卸载模块。
-t或--type  指定模块类型。
-v或--verbose  执行时显示详细的信息。
-V或--version  显示版本信息。
-help  显示帮助。

操作

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 程式所建立。
The modprobe and depmod utilities are intended to make a Linux modular kernel more manageable for all users, administrators and distribution maintainers. Modprobe uses a "Makefile"-like dependency file, created by depmod, to automatically load the relevant module(s) from the set of modules available in predefined directory trees. Modprobe is used to load a single module, a stack of dependent modules, or all modules that are marked with a specified tag. Modprobewill automatically load all base modules needed in a module stack, as described by the dependency file modules.dep. If the loading of one of these modules fails, the whole current stack of modules loaded in the current session will be unloaded automatically. Modprobe has two ways of loading modules. One way (the probe mode) will try to load a module out of a list (defined by pattern). Modprobe stops loading as soon as one module loads successfully. This could be used to autoload one Ethernet driver out of a list. The other way modprobe can be used is to load all modules from a list. With the option -r, modprobe will automatically unload a stack of modules, similar to the way rmmod -r does. Note that using just modprobe -r will clean up unused autoloaded modules and also perform the pre-and post-remove commands in the configuration file /etc/modules, /etc/modprobe.d/*. Combining the options -l and -t lists all available modules of a certain type. Option -c will print the currently used configuration (default + configuration file). To do autoclean every 2 minutes:
'''/2 ''' * ''' ''' test -f /proc/modules && /sbin/modprobe -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 程式所建立。
 
 

使用modprobe命令来添加、删除模块

系统环境:Red Hat Enterprise Linux Server release 6.0

[root@localhost huage]# lsmod               //列出当前系统已加载的模块

Module                  Size  Used by

usb_storage            39114  0 

cdrom                  34035  1 sr_mod

。。。。。。

。。。。。。

。。。。。。

 

[root@localhost huage]# lsmod |grep usb

usb_storage            39114  0 

[root@localhost huage]# lsmod |grep usb_storage      

usb_storage            39114  0 

[root@localhost huage]# lsmod |grep usb-storage

//使用grep过滤输出时,下划线和中划线意义完全不一样

 

[root@localhost huage]# modprobe -r usb_storage     //删除模块;删除模块时需要加‘-r’参数

[root@localhost huage]# lsmod |grep usb

[root@localhost huage]# modprobe usb-storage          //添加模块;添加模块时,直接加模块名就可以了

[root@localhost huage]# lsmod |grep usb

usb_storage            39114  0 

//使用modprobe命令添加或删除模块时,‘_’‘-’没有区别,即下划线和中划线没有区别

 

[root@localhost huage]# man modprobe

DESCRIPTION(只节选了部分)

       modprobe intelligently adds or removes a module  from  the  Linux

       kernel: note that for convenience, there is no difference between

       _ and - in module names.  modprobe looks in the module  directory

       /lib/modules/?.name  -r?. for  all  the  modules and other files,

       except for the optional /etc/modprobe.conf configuration file and

       /etc/modprobe.d  directory  (see modprobe.conf(5)). modprobe will

       also use module options specified on the kernel command  line  in

       the form of <module>.<option>.

 

-r --remove

              This option causes modprobe to remove rather than insert a

              module. If the modules it depends on are also unused, mod-

              probe  will try to remove them too. Unlike insertion, more

              than one module can be specified on the command  line  (it

              does  not  make  sense  to  specify module parameters when

              removing modules).

 

              There is usually no reason to  remove  modules,  but  some

              buggy  modules  require  it.  Your  kernel may not support

              removal of modules.     
posted @ 2015-02-03 19:06  alxe_yu  阅读(809)  评论(0编辑  收藏  举报