modprobe 及 配置文件 /etc/modprobe.conf

modprobe -- program to add and remove modules from the Linux Kernel
从linux核心中添加或删除模块。

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/`uname -r` for all the modules and  other  files,  except  for  the  optional  /etc/mod probe.conf configuration file and /etc/modprobe.d directory (see modprobe.conf(5)).  All files in the /etc/modprobe.d/arch/ directory are ignored.

为了一致性,模块名字中包含的_和-是没有任何区别的。modprobe会检查/lib/modules/`uname -r`下的所有模块, 除了/etc/modprobe.conf配置文件和/etc/modprobe.d目录以外。所有/etc/modprobe.d/arch/目录下的文件将被忽略。

Note that this version of modprobe does not do anything to the module itself: the work  of  resolving symbols  and  understanding  parameters  is  done  inside the kernel.  So module failure is sometimes accompanied by a kernel message: see dmesg(8).

值得注意的是现在modprobe不会对模块本身进行操作,解析symbols和理解参数的工作都交由kernel来作,所以模块 加载等错误有时将会包含在内核信息中,利用dmesg可以查看到。

modprobe expects an up-to-date modules.dep file, as generated by depmod (see depmod(8)).   This  file
lists  what  other  modules each module needs (if any), and modprobe uses this to add or remove these
dependencies automatically.  See modules.dep(5)).

modprobe会根据modules.dep来添加或者删除模块。

If any arguments are given after the modulename, they are passed to the kernel (in  addition  to  any
options listed in the configuration file).
如果指定模块名称的话,这些模块将会被传到核心中,当然还有它们对应的参数(记录在配置文件中).

OPTIONS
-l --list List all modules matching the given wildcard (or "*" if no wildcard is given).  This option
                 is provided for backwards compatibility: see find(1) and basename(1) for  a  more  flexible
                 alternative.
用来列出所有模块或者符合指定条件的所有模块,可以使用wildcard。

-r --remove
删除模块。

BACKWARDS COMPATIBILITY(向下兼容性)
This  version  of  modprobe is for kernels 2.5.48 and above.  If it detects a kernel with support for old-style modules (for which much of the work was done in userspace), it will  attempt  to  run  mod probe.modutils in its place, so it is completely transparent to the user.

现在版本的modprobe只支持2.5.48及以上的内核,如果它发现内核支持老的模块或者内核本身就低于2.5.48, 它将尝试运行modprobe.modutils来代替自己。

通过了解modprobe的manpage我们知道,我可以通过modprobe -l来显示可以当前可以加载的模块,所谓
当前可以加载的模块,实际上就是modules.dep文件中包含的那些模块,而不是manpage里说的modprobe会加载 /lib/modules/`uname -r`下的所有模块(也许是我理解错误),下面我们将会证明这一点.
modprobe xxx.ko        #加载某个模块
modprobe -r xxx.ko     #卸载某个模块
上面提到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。

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: if not, it silently
                 exits rather than regenerating the files.
只检查那些比modules.dep文件里记录新的模块的相依性,如果没有则退出,并不重建modules.dep.

-e --errsyms
                 When  combined  with  the -F option, this reports any symbols
                 which a module needs which are not supplied by other  modules
                 or the kernel.  Normally, any symbols not provided by modules
                 are assumed to be provided by the  kernel  (which  should  be
                 true in a perfect world).
如果和下面的-F选项合用的话,将会报告模块需要却又不存在的symbols。通常,模块不提供的symbols
会由kernel来提供。

-F --filesyms System.map
                 Supplied  with  the  System.map  produced when the kernel was
                 built, this allows the -e option to  report  unresolved  sym-
                 bols.
System.map是在kernel被创建的时候建立的,-F选项可以利用System.map文件,这时-e选项才可以使用。

-n --dry-run
                 This  sends  the  resulting modules.dep, then the various map
                 files, to standard output, rather than writing them into  the
                 module directory.
只把结果显示在屏幕上而不是写到modules.dep中。

BACKWARDS COMPATIBILITY(向下兼容性)

This version of depmod is for kernels 2.5.48 and above.  If it detects a kernel with support for old style modules, or the version specified is before 2.5.48, it will attempt to run  depmod.modutils  in its place, so it is completely transparent to the user.

现在版本的depmod只支持2.5.48及以上的内核,如果它发现内核支持老的模块或者内核本身就低于2.5.48,
它将尝试运行depmod.modutils来代替自己。

通常我们安装一个新的模块,先是编译出相应的ko文件,然后移动/lib/modules/`uname -r`/目录或者某个子
目录下,locate xxx.ko确定该模块确实在上面提到的目录下面,执行depmod -aeF,depmod将会检查
/lib/modules/`uname -r`/目录及其子目录中的所有模块文件,并根据相依性生成新的modules.dep文件,这时我们执行modprobe xxx.ko,该模块就会被正常加载了。
所以这时我们重新执行depmod -aeF会生成新的modules.dep,刚才注释掉了的那个#也消失了。
这里我们还要提两个文件:
1./etc/modules
vi /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

loop

说明我们如果在这里写上模块名字,比如ntfs(注意不要写ntfs或者ntfs对应的alias),开机时就会自动加载,
即开机后lsmod后就会看到ntfs而不用等mount或者modprobe ntfs等命令。
man modprobe.conf
modprobe.conf -- Configuration file/directory for modprobe
modprobe.conf 传递给modprobe的配置文件或目录。

Because  the  modprobe  command can add or remove extra more than one module, due to module dependen-
cies, we need a method of specifying what options are to  be  used  with  those  modules.   /etc/mod-
probe.conf  (or,  if  that  does  not exist, all files under the /etc/modprobe.d directory) specifies
those options, as required.  It can also be used to create convenient aliases: alternate names for  a
module.   Finally,  it can override the normal modprobe behavior altogether, for those with very spe-
cial requirements (such as inserting more than one module).
modprobe可以根据相依性来添加或删除模块,所以我们需要一种方法来指定特殊的选项给特定的某些模块。
/etc/modprobe.conf(如果不存在就是在/etc/modprobe.d目录下的所有文件)将会指定这些需要的选项。也可以
指定别名给一个模块。

The  format  of  modprobe.conf and files under modprobe.d is simple: one command per line, with blank
lines and lines starting with # ignored (useful for adding comments).  A  at the end of a line causes
it to continue on the next line, which makes the file a bit neater.
格式:每行一个命令,空白行和行首有‘#’的将被忽略。行尾有A代表下一行是这行的继续。

The syntax is a simplification of modules.conf, used in 2.4 kernels and earlier.
modules.conf只被2.4或更早的内核使用。


alias wildcard modulename
                 This  allows  you  to  give  alternate  names  for  a  module.   For example: "alias my-mod
                 really_long_modulename"  means  you  can  use  "modprobe  my-mod"  instead   of   "modprobe
                 really_long_modulename".   You  can  also  use  shell-style  wildcards,  so  "alias my-mod*
                 really_long_modulename" means that "modprobe my-mod-something" has the  same  effect.   You
                 can't  have aliases to other aliases (that way lies madness), but aliases can have options,
                 which will be added to any other options.
指定别名,也可以利用shell中的wildcard来指定。例子:
alias my-mod really_long_modulename
这意味着你可以用modprobe  my-mod"来代替"modprobe really_long_modulename.
不可以给别名指定别名。但是别名可以有选项。

Note that modules can also contain their own aliases, which  you  can  see  using  modinfo.
These  aliases  are used as a last resort (ie. if there is no real module, install, remove,
or alias       command in the configuration).

模块可以有它们自带的别名,你可以利用modinfo看到。这些别名将被作为最后一着。配置文件里的别名优先,如果
没有指定的话,这些自带的别名将被用到。

options modulename option...
                 This command allows you to add options to the module modulename (which might be  an  alias)
                 every  time it is inserted into the kernel: whether directly (using modprobe modulename, or
                 because the module being inserted depends on this module.

                 All options are added together: they can come from an option for the module itself, for  an
                 alias, and on the command line.


这个命令允许你加一些条件给模块(模块名或者是别名),当模块被加载到内核中时。所有的条件选项可以被叠加。

install modulename command...
                 This is the most powerful primitive in modprobe.conf: it tells modprobe to run your command
                 instead of inserting the module in the kernel as normal.  The command can be any shell com-
                 mand: this allows you to do any kind of complex processing you might wish.  For example, if
                 the module "fred" worked better with the module "barney" already installed (but  it  didn't
                 depend  on  it,  so  modprobe  won't  automatically  load  it), you could say "install fred
                 /sbin/modprobe barney; /sbin/modprobe --ignore-install  fred",  which  would  do  what  you
                 wanted.   Note  the  --ignore-install,  which stops the second modprobe from re-running the
                 same install command.  See also remove below.
这是modprobe.conf中最原始最有效的命令:它告诉modprobe运行你的命令来取代modprobe通常的行为(加载一个模块到内核中)。
这个命令可以是shell命令,这将允许你做任何你西王做的复杂的事情。例子:
假定fred模块和barney模块一起工作时效果比较好,但是由于fred并不依赖于barney模块,所以加载fred时并不会加载barney。
这是我们可以加如下的命令到配置文件中去。
install fred /sbin/modprobe barney; /sbin/modprobe --ignore-install  fred.
install fred 是指定modprobe在加载fred这个模块之前要运行后面的这个命令来替代本来的动作(modprobe fred)。也就是:
/sbin/modprobe barney; /sbin/modprobe --ignore-install  fred 代替了modprobe fred
这里--ignore-install表示加载时不要考虑配置文件中install选项,这是为了避免又运行一遍同样的shell命令。

                 You can also use install to make up modules which  don't  otherwise  exist.   For  example:
                 "install  probe-ethernet  /sbin/modprobe  e100  || /sbin/modprobe eepro100", which will try
                 first the e100 driver, then the eepro100 driver, when you do "modprobe probe-ethernet".
你可以组合模块。例子:
install  probe-ethernet  /sbin/modprobe  e100  || /sbin/modprobe eepro100
当你下达modprobe probe-ethernet的命令时,将会先尝试加载e100driver,如果不行再加载eepro100driver。

                 If you use the string "$CMDLINE_OPTS" in the command, it will be replaced  by  any  options
                 specified  on the modprobe command line.  This can be useful because users expect "modprobe
                 fred opt=1" to pass the "opt=1" arg to the module, even if there's an  install  command  in
                 the  configuration file.  So our above example becomes "install fred /sbin/modprobe barney;
                 /sbin/modprobe --ignore-install fred $CMDLINE_OPTS"

如果你在配置文件中的命令行里使用了$CMDLINE_OPTS这个字符串,那么你可以从shell命令行里直接下达你希望传递给模块
的条件,这个条件将取代配置文件中的这个$CMDLINE_OPTS.例子:
如果上边的例子改为:
install fred /sbin/modprobe barney;/sbin/modprobe --ignore-install fred $CMDLINE_OPTS
那么当你下达modprobe fred opt=1时,这个opt=1参数将被传递给模块,它将取代$CMDLINE_OPTS.

remove modulename command...
                 This is similar to the install command above, except it is invoked when  "modprobe  -r"  is
                 run.   The removal counterparts to the two examples above would be: "remove fred /sbin/mod-
                 probe -r --ignore-remove fred && /sbin/modprobe  -r  barney",  and  "remove  probe-ethernet
                 /sbin/modprobe -r eepro100 || /sbin/modprobe -r e100".
这个命令和install类似,只不过它只在modprobe -r时才起作用。上边的例子对应:
"remove fred /sbin/modprobe -r --ignore-remove fred && /sbin/modprobe  -r  barney",  and
"remove  probe-ethernet/sbin/modprobe -r eepro100 || /sbin/modprobe -r e100".

blacklist modulename
                 Modules  can  contain  their  own aliases: usually these are aliases describing the devices
                 they support, such as "pci:123...".  These "internal" aliases can be overridden  by  normal
                 "alias"  keywords,  but  there  are  cases  where two or more modules both support the same
                 devices, or a module invalidly claims to support a device: the blacklist keyword  indicates
                 that all of that particular module's internal aliases are to be ignored.

模块可以有自己的别名。通常这些别名描述了它们支持的设备,比如:pci:123...
这些内部别名会被通常我们指定的别名推翻。但是有些情况下,两个或更多的模块同时支持同一个设备,或者模块实际不能支持它宣称支持的设备:这时黑名单上的模块意味着这些特殊模块的内部别名将会被忽略。

Backwards Compatibility
       Although the syntax is similar to the older  /etc/modules.conf,  there  are  many  features  missing.
       There  are two reasons for this: firstly, install and remove commands can do just about anything, and secondly, the module-init-tools modprobe is designed to be  simple  enough  that  it  can  be  easily replaced.
虽然和老的/etc/modules.conf很像,但是老的/etc/modules.conf还是缺少很多的特性.
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
回答: 在执行命令 "sudo gedit /etc/modprobe.d/blacklist.conf" 之前,你需要先卸载原有的N卡驱动。如果你是通过apt-get安装的原始驱动,可以使用以下命令卸载: "sudo apt-get remove --purge nvidia*"; 如果你是通过运行文件安装的原始驱动,可以使用以下命令卸载: "sudo chmod +x *.run" 和 "sudo ./NVIDIA-Linux-x86_64-384.59.run --uninstall"。在编辑blacklist.conf文件之前,你可能还需要修改GRUB配置文件,以确保nvidia驱动正确加载。你可以在GRUB配置文件中添加 "nvidia-drm.modeset=1" 或者 "nomodeset",具体的修改方式可能因电脑而异。你可以尝试编辑以下配置项: GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nvidia-drm.modeset=1" GRUB_CMDLINE_LINUX=""。最后,你可以安装nvidia驱动,但在安装之前请确保你有足够的权限。你可以使用以下命令赋予权限: "sudo ./Linux-x86_64-396.18.run -no-x-check -no-nouveau-check -no-opengl-files"。这样安装后就不会出现循环登录的问题了。 #### 引用[.reference_title] - *1* [Ubuntu18.04英伟达驱动的安装](https://blog.csdn.net/srf_code/article/details/87260820)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Ubuntu18.04或20.04系统安装NVIDIA显卡驱动](https://blog.csdn.net/herocheney/article/details/123658573)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Ubuntu安装显卡驱动(避免循环启动问题)](https://blog.csdn.net/u013406197/article/details/103868234)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值