Xorg-NVIDIA

NVIDIA Optimus is a technology that allows an Intel integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop. Getting Optimus graphics to work on Arch Linux requires a few somewhat complicated steps, explained below. There are several methods available:
disabling one of the devices in BIOS, which may result in improved battery life if the NVIDIA device is disabled, but may not be available with all BIOSes and does not allow GPU switching
using the official Optimus support included with the proprietary NVIDIA driver, which offers the best NVIDIA performance but does not allow GPU switching and can be more buggy than the open-source driver
using the PRIME functionality of the open-source nouveau driver, which allows GPU switching and powersaving but offers poor performance compared to the proprietary NVIDIA driver and may cause issues with sleep and hibernate
using the third-party Bumblebee program to implement Optimus-like functionality, which offers GPU switching and powersaving but requires extra configuration
using nvidia-xrun. Utility to run separate X with discrete nvidia graphics with full performance
These options are explained in detail below.
Contents
1 Disabling switchable graphics
2 Using nvidia
2.1 Display Managers
2.1.1 LightDM
2.1.2 SDDM
2.1.3 GDM
2.2 Checking 3D
2.3 Further Information
3 Troubleshooting
3.1 Tearing/Broken VSync
3.2 Failed to initialize the NVIDIA GPU at PCI:1:0:0 (GPU fallen off the bus / RmInitAdapter failed!)
3.3 Resolution, screen scan wrong. EDID errors in Xorg.log
3.4 Lockup issue (lspci hangs)
3.5 No screens found on a laptop/NVIDIA Optimus
4 Using nouveau
5 Using Bumblebee
6 Using nvidia-xrun
Disabling switchable graphics
If you only care to use a certain GPU without switching, check the options in your system’s BIOS. There should be an option to disable one of the cards. Some laptops only allow disabling of the discrete card, or vice-versa, but it is worth checking if you only plan to use one of the cards.
For another way see Hybrid graphics#Fully Power Down Discrete GPU.
If you want to use both cards, or cannot disable the card you do not want, see the options below.
Using nvidia
The proprietary NVIDIA driver does not support dynamic switching like the nouveau driver (meaning it can only use the NVIDIA device). It also has notable screen-tearing issues that NVIDIA recognizes but has not fixed. However, it does allow use of the discrete GPU and has (as of January 2017) a marked edge in performance over the nouveau driver.
First, install the NVIDIA driver and xorg-xrandr. Then, configure xorg.conf. You will need to know the PCI address of the NVIDIA card, which you can find by issuing
$ lspci | egrep ‘VGA|3D’
The PCI address is the first 7 characters of the line that mentions NVIDIA. It will look something like 01:00.0. In the xorg.conf, you will need to format it as #:#:#; e.g. 01:00.0 would be formatted as 1:0:0.
Note: On some setups this setup breaks automatic detection of the values of the display by the nvidia driver through the EDID file. As a work-around see #Resolution, screen scan wrong. EDID errors in Xorg.log.
If X.Org X server version 1.17.2 or higher is installed ([1])
/etc/X11/xorg.conf
Section “Module”
Load “modesetting”
EndSection

Section “Device”
Identifier “nvidia”
Driver “nvidia”
BusID “”
Option “AllowEmptyInitialConfiguration”
EndSection
Next, add the following two lines to the beginning of your ~/.xinitrc:
~/.xinitrc
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
Now reboot to load the drivers, and X should start.
If your display dpi is not correct add following line:
xrandr --dpi 96
If you get a black screen when starting X, make sure that there are no ampersands after the two xrandr commands in ~/.xinitrc. If there are ampersands, it seems that the window manager can run before the xrandr commands finish executing, leading to a black screen.
Display Managers
If you are using a display manager then you will need to create or edit a display setup script for your display manager instead of using ~/.xinitrc.
LightDM
For the LightDM display manager:
/etc/lightdm/display_setup.sh
#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
Make the script executable:

chmod +x /etc/lightdm/display_setup.sh

Now configure lightdm to run the script by editing the [Seat:] section in /etc/lightdm/lightdm.conf:
/etc/lightdm/lightdm.conf
[Seat:
]
display-setup-script=/etc/lightdm/display_setup.sh
Now reboot and your display manager should start.
SDDM
For the SDDM display manager:
/usr/share/sddm/scripts/Xsetup
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
GDM
For the GDM display manager create two new .desktop files:
/usr/share/gdm/greeter/autostart/optimus.desktop
/etc/xdg/autostart/optimus.desktop
[Desktop Entry]
Type=Application
Name=Optimus
Exec=sh -c “xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto”
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer
Make sure that GDM use X as default backend.
Checking 3D
You can check if the NVIDIA graphics are being used by installing mesa-demos and running
$ glxinfo | grep NVIDIA
Further Information
For more information, look at NVIDIA’s official page on the topic [2].
Troubleshooting
Tearing/Broken VSync
This requires xorg-server 1.19 or higher, linux kernel 4.5 or higher, and nvidia 370.23 or higher. Then enable DRM kernel mode setting, which will in turn enable the PRIME synchronization and fix the tearing.
You can read the official forum thread for details.
Failed to initialize the NVIDIA GPU at PCI:1:0:0 (GPU fallen off the bus / RmInitAdapter failed!)
Add rcutree.rcu_idle_gp_delay=1 to the kernel parameters. Original topic can be found here.
Resolution, screen scan wrong. EDID errors in Xorg.log
This is due to the NVIDIA driver not detecting the EDID for the display. You need to manually specify the path to an EDID file or provide the same information in a similar way.
To provide the path to the EDID file edit the Device Section for the NVIDIA card in Xorg.conf, adding these lines and changing parts to reflect your own system:
/etc/X11/xorg.conf
Section “Device”
Option “ConnectedMonitor” “CRT-0”
Option “CustomEDID” “CRT-0:/sys/class/drm/card0-LVDS-1/edid”
Option “IgnoreEDID” “false”
Option “UseEDID” “true”
EndSection
If Xorg wont start try swapping out all references of CRT to DFB. card0 is the identifier for the intel card to which the display is connected via LVDS. The edid binary is in this directory. If the hardware arrangement is different, the value for CustomEDID might vary but yet this has to be confirmed. The path will start in any case with /sys/class/drm.
Alternatively you can generate your edid with tools like read-edid and point the driver to this file. Even modelines can be used, but then be sure to change “UseEDID” and “IgnoreEDID”.
Lockup issue (lspci hangs)
Symptoms: lspci hangs, system suspend fails, shutdown hangs, optirun hangs.
Applies to: newer laptops with GTX 965M or alike when bbswitch (e.g. via Bumblebee) or nouveau is in use.
When the dGPU power resource is turned on, it may fail to do so and hang in ACPI code (kernel bug 156341).
For known model-specific workarounds, see this issue. In other cases you can try to boot with acpi_osi="!Windows 2015" or acpi_osi=! acpi_osi=“Windows 2009” added to your Kernel parameters. (Consider reporting your laptop to that issue.)
No screens found on a laptop/NVIDIA Optimus
Check if $ lspci | grep VGA outputs something similar to:
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)
NVIDIA drivers now offer Optimus support since 319.12 Beta [3] with kernels above and including 3.9.
Another solution is to install the Intel driver to handle the screens, then if you want 3D software you should run them through Bumblebee to tell them to use the NVIDIA card.
Using nouveau
The open-source nouveau driver (xf86-video-nouveau) can dynamically switch with the Intel driver (xf86-video-intel) using a technology called PRIME. For more information, see the wiki article on PRIME.
Using Bumblebee
If you wish to use Bumblebee, which will implement powersaving and some other useful features, see the wiki article on Bumblebee.

cvt calculates VESA CVT mode lines.
dmx* are various tools used for manipulating the dmx server.
gtf calculates VESA GTF mode lines.
vdltodmx is a tool used to convert VDL config files to DMX config files.
X is a symbolic link to Xorg.
Xdmx is a proxy X server that uses one or more other X servers as its display devices.
Xephyr is a nested X server which supports modern X extensions.
Xnest is a nested X server.
Xorg is the X11R7 X Server.
Xvfb is the virtual framebuffer X server for X Version 11.
xdmxconfig is a graphical configuration utility for the dmx server.
Xwayland allows the X server to run X clients under wayland (i.e. wayland provides the input devices and handles the presentation of the windows).
modesetting_drv.so provides a video driver for machines using Kernel Mode Setting (KMS). This will use glamor if that has been enabled and the hardware offers acceleration.

操作系统不同,硬件的驱动程序也不同。本节将介绍在Kali中安装NVIDIA显卡驱动的方法。
安装NVIDIA显卡驱动的具体操作步骤如下所示。
(1)将开源的NVIDIA驱动nouveau加入黑名单。方法如下所示:
root@kali:~# vi /etc/modprobe.d/blacklist.conf
blacklist nouveau
以上信息表示在blacklist.conf文件中添加了blacklist nouveau一行内容。
(2)查看当前的系统信息。执行命令如下所示:
root@kali:~# uname -a
Linux kali 3.12-kali1-kali-amd64 #1 SMP Debian 3.12.6-2kali1 (2014-01-06) x86_64 GNU/Linux
从输出的信息中可以看到当前系统安装的是Kali,其内核版本为3.12,系统架构是x86_64位。
(3)安装Linux头文件。执行命令如下所示:
root@kali:~# aptitude -r install linux-headers-$(uname -r)
下列“新”软件包将被安装。
linux-headers-3.12-kali1-686-pae linux-headers-3.12-kali1-common{a}
linux-kbuild-3.12{a}
下列软件包将被“删除”:
firmware-mod-kit{u} libadns1{u} libcrypto++9{u} liblzma-dev{u}
libsmi2-common{u} libwebkit-dev{u} msgpack-python{u} p7zip{u}
python-adns{u} python-bs4{u} python-easygui{u} python-ipy{u}
python-levenshtein{u} python-mechanize{u} python-metaconfig{u}
python-paramiko{u} python-pycryptopp{u} python-pysnmp4{u}
python-pysnmp4-apps{u} python-pysnmp4-mibs{u} sqlmap{u} unrar-free{u}
0 个软件包被升级,新安装 3 个,22 个将被删除, 同时 206 个将不升级。
需要获取 4,848 kB 的存档。解包后将释放 55.4 MB。
您要继续吗?[Y/n] y
以上输出信息显示了当前要安装的软件包数、将被删除的软件包和升级的软件包等。此时输入y,继续安装。
(4)安装NVIDIA内核。执行命令如下所示:
root@kali:~# apt-get install nvidia-kernel-3.12-kali1-adm64
执行以上命令后,将显示安装nvidia-kernel包的安装过程。此时不需要手动设置任何信息,将自动安装完成。
(5)安装NVIDIA驱动nvidia-kernel-dkms包。执行命令如下所示:
root@kali:~# aptitude install nvidia-kernel-dkms
下列“新”软件包将被安装。
dkms{a} glx-alternative-mesa{a} glx-alternative-nvidia{a}
glx-diversions{a} libgl1-nvidia-glx{a} libvdpau1{a}
linux-headers-3.12-kali1-686-pae{a} linux-headers-3.12-kali1-common{a}
linux-headers-686-pae{a} linux-kbuild-3.12{a} nvidia-alternative{a}
nvidia-driver{a} nvidia-installer-cleanup{a} nvidia-kernel-common{a}
nvidia-kernel-dkms nvidia-vdpau-driver{a} xserver-xorg-video-nvidia{a}
0 个软件包被升级,新安装 17 个,0 个将被删除, 同时 207 个将不升级。
需要获取 29.4 MB 的存档。解包后将要使用 108 MB。
您要继续吗?[Y/n] y
以上输出信息显示了将安装的软件包及软件包的大小。此时输入y,继续安装。在安装过程中,会出现如图2.1所示的界面。

图2.1 配置xserver-xorg
该界面提示需要配置xserver-xorg-video-nvidia。在该界面单击OK按钮,后面手动进行配置。
(6)安装NVIDIA显卡驱动应用程序nvidia-xconfig包。执行命令如下所示:
root@kali:~# aptitude install nvidia-xconfig
(7)生成Xorg服务配置文件。执行命令如下所示:
root@kali:~# nvidia-xconfig
执行以上命令后,将输出如下所示的信息。
WARNING: Unable to locate/open X configuration file.
New X configuration file written to ‘/etc/X11/xorg.conf’
输出的信息,表示重新生成了xorg.conf文件。然后,重新启动系统。
(8)检查NVIDIA显卡驱动是否成功安装。首先检查GLX模块,执行命令如下所示:
root@kali:~# glxinfo | grep -i “direct rendering”
direct rendering: Yes
检查NVIDIA驱动模块。执行命令如下所示:
root@kali:~# lsmod | grep nvidia
nvidia 9442880 29
i2c_core 24129 2 i2c_i801,nvidia
root@kali:~# lsmod | grep nouveau
通过查看以下文件的内容,确定开源的NVIDIA驱动nouveau是否被加入黑名单,如下所示:
root@kali:~# cat /etc/modprobe.d/nvidia.conf
alias nvidia nvidia-current
remove nvidia-current rmmod nvidia
root@kali:~# cat /etc/modprobe.d/nvidia-blacklists-nouveau.conf

You need to run “update-initramfs -u” after editing this file.

see #580894

blacklist nouveau
root@kali:~# cat /etc/modprobe.d/nvidia-kernel-common.conf
alias char-major-195* nvidia

options nvidia NVreg_DeviceFileUID=0 NVreg_DeviceFileGID=44 NVreg_Device FileMode=0660

To enable FastWrites and Sidebus addressing, uncomment these lines

options nvidia NVreg_EnableAGPSBA=1

options nvidia NVreg_EnableAGPFW=1

看到以上输出信息,就表示nouveau已被加入黑名单。
为了加快用户破解一些大数据文件,需要安装CUDA(Compute Unified Device Architecture)。CUDA是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。
安装NVIDIA CUDA工具集和NVIDIA openCL。执行命令如下所示:
root@kali:~# aptitude install nvidia-cuda-toolkit nvidia-opencl-icd
执行以上命令后,如果输出过程中没有出错的话,表示该软件包安装成功。以后就可以使用CUDA破解加密的大数据文件。

装kali去公司下载了最新的是2017。装好后准备装显卡去哦那个发现装不上,于是百度都没有2017的
折腾很很久终于折腾出来了现在发出来给需要的朋友;
对了提前说一下装这个东西还必须的有网,于是我只能把握手包给淘宝去跑了;
入正题
apt-get update
apt-get dist-upgrade
apt-get install -y linux-headers-$(uname -r)
去官网下载自己版本的驱动选择linux的点击显示所有系统里面会有linux
http://www.nvidia.cn/Download/index.aspx?lang=cn
chmod +x NVIDIA-Linux-x86_64-340.96.run
sed ‘s/quiet/quiet nouveau.modeset=0/g’ -i /etc/default/grub
update-grub
reboot
进入系统后打开终端直接运行
./NVIDIA-Linux-x86_64-340.96.run
提示你的话就一路同意 OK 下去,完成后重启,再次进入系统就已经安装好了显卡驱动
检查显卡去的是否已经安装好
root@files:~# glxinfo | grep -i “direct rendering”
direct rendering: Yes
表示已经安装好
查看安装的模块
root@files:~# lsmod | grep nvidia
nvidia_drm 45056 2
nvidia_modeset 790528 7 nvidia_drm
nvidia 12312576 127 nvidia_modeset
drm_kms_helper 155648 2 nouveau,nvidia_drm
drm 360448 7 nouveau,ttm,nvidia_drm,drm_kms_helper
驱动安装结束了,要跑包还的安装NVIDIA CUDA工具集和NVIDIA openCL
apt-get
install nvidia-cuda-toolkit nvidia-opencl-icd

如果 無法順利偵測類似nvidia的顯示卡,那麼參考下列的設定建立一個最基本的xorg.conf:
Section “ServerLayout”
Identifier “Layout0”
Screen 0 “Screen0” 0 0
EndSection

扫描二维码关注公众号,回复: 4865960 查看本文章

Section “Files”
FontPath “/usr/share/fonts/local/”
EndSection

Section “Device”
Identifier “Device0”
Driver “nvidia”
VendorName “NVIDIA Corporation”
BoardName “GeForce Go 7300”
EndSection

Section “Screen”
Identifier “Screen0”
Device “Device0”
EndSection

Wayland
Wayland 是2008年由 Intel 开放源代码技术中心 的成员 Kristian Høgsberg 所发起的一个桌面的显示服务器协议和在Linux上实现这个协议的软件库。它是一个自由软件专案,采用MIT许可证释出。作者声称“每一个显示画面皆是完美的,我的意思是应用程序将能充分地去控制图形的显示,使我们完全无法察觉任何的撕裂、延迟、重画及闪烁”。Wayland使得Compositor能够与应用程序和视频硬件直接交互。 应用程序在它们自己的缓冲区中进行图形渲染。这样一来,窗口管理器就变成了一个显示管理服务,专门负责渲染那些屏幕上的程序。这比X Window系统中的窗口管理器要更简单,高效。
设计
Wayland 运用既有的 Linux 核心技术,像是 Direct Rendering Manager (DRM), kernel mode-setting (KMS) 以及 Graphics Execution Manager (GEM) 以提供一个最小化的显示管理服务。Wayland 混合器 (compositor) 在 2010 年 6 月已从桌面常用的 OpenGL 改为 OpenGL ES。这个专案也开发支援 Wayland 显示的 Qt,而不需要 X。大部分应用程式都有望获得透过函式库,无需修改程式即可支援 Wayland。
近些年来,GNU/Linux 桌面图形开发者从X server中移除了一大堆的与渲染有关的接口到内核中。现在,已经有许多功能被移入内核(内存管理,任务调度,模式设置(KMS)等等)或是程序库(cario,pixman,freetype,fontconfig,pango等等),所以窗口系统需要做的事情大大减少了。但是 X11 协议十分巨大,庞杂,并且它包括了许多已经过时的模块。虽然开发者们为了使 X server 适应现代化的计算机体系结构而开发出了 XRandR,XRender,COMPOSITE等一些额外扩展,但这终究是治标不治本,同时这也会增加维护的难度。 Wayland也包括了一个协议(近乎完成),但与X server不同的是 Wayland只做它必须要做到事情。下面我们以"鼠标点击按钮引发按钮更新动作"来说明一下 Wayland 和 X server 的区别:
在 X 中:

内核捕获鼠标点击事件并发送给 X server。
X server 会计算该把这一事件发送给哪个窗口(事实上,窗口位置是由Compositor控制的,X server并不能够正确的计算Compositor做过特效变化之后的按钮的正确位置)。
应用程序对此事件进行处理(将引发按钮更新动作)。但是,在此之前它得向X server发送绘制请求。
X server接收到这条绘制请求,然后把它发给视频驱动来渲染。X 还计算了更新区域,并且这条"垃圾信息"发送给了Compositor。
这时,Compositor 知道它必须要重新合成屏幕上的一块区域。当然,这还是要向X server发送绘制请求的。
开始绘制。但是X server 还会去做一些不必要的本职工作(窗口重叠计算,窗口剪裁计算等)。
在 Wayland 中:

内核捕获鼠标点击事件并发送给 Wayland Compositor。
由于是直接发给Compositor的,所以Wayland会正确地计算出按钮的位置。同时它会把这一事件发送给按钮所在的应用程序来处理。
应用程序直接渲染,无需向Wayland请求。只需在绘制完成之后向Compositor 发送一条信息表明这块区域被更新了。
Compositor收到这条信息后,立即重新合成整个桌面而无需向Wayland请求。
目前,Wayland使用OpenGL ES而不是传统的OpenGL。“从长远来看,我们需要完整的OpenGL支持,但问题是 libGL 会带来X的依赖性…”另一方面,使用OpenGL ES会使得Wayland更容易支持移动设备。 Wayland 目前并不支持网络透明性,但未来可能会支持。
PS:
Canonical 创始人马克•沙特尔沃思于 2010 年 11 月 4 日宣布 Wayland 将作为 Ubuntu 未来某一未定版本 Unity 接口的显示服务器。但是,2013年3月份,Canonical 确认他们将开发一个新的显示服务 Mir 而不是使用 Wayland 来替代X。
X Window System
X窗口系统(X Window System,也常称为X11或X)是一种以位图方式显示的软件窗口系统。最初是1984年麻省理工学院的研究,之后变成UNIX、类UNIX、以及OpenVMS等操作系统所一致适用的标准化软件工具包及显示架构的运作协定。X窗口系统通过软件工具及架构协定来创建操作系统所用的图形用户界面,此后则逐渐扩展适用到各形各色的其他操作系统上。现在几乎所有的操作系统都能支持与使用X。更重要的是,今日知名的桌面环境——GNOME和KDE也都是以X窗口系统为基础建构成的。
由于X只是工具包及架构规范,本身并无实际参与运作的实体,所以必须有人依据此标准进行开发撰写。如此才有真正可用、可运行的实体,始可称为实现体。目前依据X的规范架构所开发撰写成的实现体中,以X.Org最为普遍且最受欢迎。X.Org所用的协定版本,X11,是在1987年9月所发布。而今最新的参考实现(参考性、示范性的实现体)版本则是X11 Release 7.6(简称:X11R7.6),而此专案由X.Org基金会所领导,且是以MIT授权和相似的授权许可的自由软件。

启动模块
• 你希望系统启动时自动加载你的模块,有两种方式:一种是将你的模块包含进initrd文件里,一般情况下不需要使用这种方式,除非不加载你的模块的话内核不能正常启动。参见initramfs-tools软件包的相关信息。另一种是通过配置文件完成的,主要的配置文件是/etc/modules。比如你的模块名字叫MyMod,加载参数是paraA=1,就在/etc/modules加入一行MyModparaA=1这样,系统启动时就自动以参数paraA=1加载MyMod模块。你还可以通过/et
• 如果你希望系统启动时自动加载你的模块,有两种方式:

一种是将你的模块包含进initrd文件里,一般情况下不需要使用这种方式,除非不加载你的模块的话内核不能正常启动。参见initramfs-tools软件包的相关信息。

另一种是通过配置文件完成的,主要的配置文件是/etc/modules 。
比如你的模块名字叫MyMod,加载参数是paraA=1,就在/etc/modules加入一行
MyMod paraA=1
这样,系统启动时就自动以参数paraA=1加载MyMod模块。

你还可以通过/etc/modprobe.d/目录下的配置文件进行进一步的配置,这个目录下的每个.conf文件都会被读取。具体用法请man modprobe.d。

/etc/moduels用于系统自动加载模块的配置。而/etc/modprob.d/目录下的配置文件在每次加载模块时(包括自动和手动)都会起作用,如下所示:

[email protected]:/etc/modprobe.d# catbpi-blacklist.conf

blacklist spi and i2c by default (manyusers don’t need them)

#blacklist spi-sun7i
blacklist i2c-sunxi

内核与内核模块
内核和内核模块存放位置:
内核:/boot/vmlinuz或/boot/vmlinuz-version
内核解压所需RAMDisk:/boot/initrd (/boot/initrd-version)
内核模块:/lib/modules/version/kernel或 /lib/modules/$(uname -r)/kernel
内核源码:/usr/src/linux 或/usr/src/kernels(要安装才会有,默认不安装)
内核版本:/proc/version
系统内核功能:/proc/sys/kernel

内核模块与依赖性:
/lib/modules/ ( u n a m e r ) / m o d u l e s . d e p a . k o 使 d e p m o d d e p m o d [ A n e ] c p a . k o / l i b / m o d u l e / (uname -r)/modules.dep文件记录了在内核支持的模块的各项依赖性 例如,做好的网卡驱动程序,文件名为a.ko,如何更新内核依赖性? 使用depmod命令就可以实现(depmod [-Ane]) cp a.ko /lib/module/ (uname -r)/kernel/driver/net
depmod

内核模块的查看:
lsmod
使用lsmod后,系统会显示出目前已存在与内核中的模块,显示包括:模块名称module、模块的大小size、此模块是否被其他模块所使用Used by
modinfo [-adln] [module_name|filename]
如:modinfo wmi

内核模块的加载与删除:
如果想要自行手动加载模块,最简单也建议使用modprobe命令来加载模块,因为modprobe会主动查找modules.dep的内容,先克服了模块的依赖性后,菜决定需要加载的模块有哪些。insmod则完全有用户加载一个完整文件名的模块,并不会主动分析模块依赖性
modprobe [-lcfr] module_name
insmod [/full/path/module_name] [parameters]
例如:尝试载入cifs.ko这个文件系统模块
insmod /lib/module/$(uname -r)/kernel/fs/cifs/cifs.ko
lsmod | grep cifs
删除模块:rmmod [-fw] module_name

整个开机流程是
(1) 载入BIOS的硬件信息,并取得第一个开机装置的代号
(2)读取第一个开机装置的MBR的boot Loader (grub)的开机信息
(3)载入OS Kernel信息,解压Kernel,尝试驱动硬件
(4) Kernel执行init程序并获得run-lebel信息(如3或5)
(5) init执行/etc/rc.d/rc.sysinit
(6)启动内核外挂模块(/etc/modprobe.conf)
(7) init执行run-level的各种Scripts,启动服务
(8) init执行/etc/rc.d/rc.local
(9)执行/bin/login,等待用户Login
(10)Login后进入Shell
看来正确的方式是把需要加载的模块放在(5)或(6),但正如网络上很多人的尝试,修改modprobe.conf都没有成功(例如在modprobe.conf中增加install ip_vs…)。于是我修改了/etc/rc.d/rc.sysinit就成功加载了。
初步尝试在rc.sysinit最后增加 modprobe.conf ip_vs,重启后lsmod | grep ip_vs,发现成功自动加载了。
于是仿效rc.sysinit中其他模块的加载方法,扩展改脚本文件,在最后增加下来一段:

load LVS IPVS modules

if [ -d /lib/modules/ u n a m e r / k e r n e l / n e t / i p v 4 / i p v s ] ; t h e n f o r m o d u l e i n / l i b / m o d u l e s / unamer/kernel/net/ipv4/ipvs ]; then for module in /lib/modules/ unamer/kernel/net/ipv4/ipvs/* ; do
module=KaTeX parse error: Expected '}', got '#' at position 8: {module#̲#*/} module={module%.ko}
modprobe KaTeX parse error: Expected 'EOF', got '&' at position 21: …e >/dev/null 2>&̲1 done fi 就把/li…{module##/} :其中##表示从前面删除字符,/表示删除到最后一个/,如果一个#就表示只删除到第一个/。如果变量后面接##,表示在##后面的字符串取最长的(一直到最后面),如果接#,表示取最小的一段。
module=${module%.ko}:表示从后面删除.ko。如果变量后面接%%,表示在%%后面的字符串取最长的(一直到最前面),如果接%,表示取最小的一段。
这样多module的两次修改就得到了模块名,就是文件名不带路径和.ko后缀。
modprobe $module >/dev/null 2>&1:加载模块,输出都指向空设备
这样重启后lsmod | grep ip_vs就会得到:
ip_vs_wrr 6977 0
ip_vs_wlc 6081 0
ip_vs_sh 6593 0
ip_vs_sed 6081 0
ip_vs_rr 6081 0
ip_vs_nq 5953 0
ip_vs_lc 5953 0
ip_vs_lblcr 10565 0
ip_vs_lblc 9797 0
ip_vs_ftp 10053 0
ip_vs_dh 6593 0
ip_vs 79425 22 ip_vs_wrr,ip_vs_wlc,ip_vs_sh,ip_vs_sed,ip_vs_rr,ip_vs_nq,ip_vs_lc,ip_vs_lblcr,ip_vs_lblc,ip_vs_ftp,ip_vs

猜你喜欢

转载自blog.csdn.net/seaship/article/details/86233544