转自 http://blog.csdn.net/hobohero/article/details/54381738
参考文献
安装elrepo库
查看新版本
yum install lynx
安装
查看显卡型号是否支持双显卡
lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 520 (rev 07)
lspci | grep 3D
01:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 940MX] (rev a2)
安装nvidia-detect检查显卡型号
yum install nvidia-detect
Installed:
nvidia-detect.x86_64 0:384.90-1.el7.elrepo
nvidia-detect -v
Probing for supported NVIDIA devices...
[10de:134d] NVIDIA Corporation
GM108M [GeForce 940MX]
This device requires the current
384.98 NVIDIA driver kmod-nvidia
[8086:1916] Intel Corporation
HD Graphics 520
An Intel display controller was also detected
更新最新内核和内核开发文件
yum update kernel kernel-devel
Installed:
kernel.x86_64 0:3.10.0-514.21.1.el7 kernel-devel.x86_64 0:3.10.0-514.21.1.el7
rpm -qa
kernel*
kernel-tools-3.10.0-693.5.2.el7.x86_64
kernel-3.10.0-693.5.2.el7.x86_64
kernel-devel-3.10.0-693.5.2.el7.x86_64
kernel-headers-3.10.0-693.5.2.el7.x86_64
kernel-tools-libs-3.10.0-693.5.2.el7.x86_64
删除多余的内核开发文件
yum remove --nodeps
*****
启用默认版本内核
首先查看默认启动内核版本
uname -a
Linux THTF
3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
cat /boot/grub2/grub.cfg | grep
3.10.0-693.5.2.el7.x86_64
menuentry 'CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-e7d7b9e7-f593-4c29-b5db-4ccd7a7dc0d6' {
linux16 /vmlinuz-
3.10.0-693.5.2.el7.x86_64 root=/dev/mapper/vg_centos-lv_root ro rd.lvm.lv=vg_centos/lv_root rd.lvm.lv=vg_centos/lv_swap rhgb quietLANG=en_US.UTF-8
initrd16 /initramfs-
3.10.0-693.5.2.el7.x86_64.img
设置默认内核(如果有多个内核)
grub2-set-default "CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)
"
验证是否成功
grub2-editenv list
禁用nouveau驱动
lsmod | grep nouveau
nouveau 1527946 0
mxm_wmi 13021 1 nouveau
ttm 93908 1 nouveau
i2c_algo_bit 13413 2 i915,nouveau
drm_kms_helper 146456 2 i915,nouveau
drm 372540 8 ttm,i915,drm_kms_helper,nouveau
wmi 19070 2 mxm_wmi,nouveau
video 24400 2 i915,nouveau
i2c_core 40756 8 drm,i915,i2c_i801,i2c_hid,drm_kms_helper,i2c_algo_bit,nouveau,videodev
vi /lib/modprobe.d/dist-blacklist.conf
#blacklist nvidiafb
blacklist nouveau options nouveau modeset=0
更改grub2配置禁用nouveau
vi /etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=vg_centos/lv_root rd.lvm.lv=vg_centos/lv_swap rhgb quiet rdblacklist=nouveau"
重新生成grub.cfg
grub2-mkconfig -o /boot/grub2/grub.cfg
设置为文本模式启动
systemctl set-default multi-user.target
reboot
查看nouveau是否被禁用
lsmod | grep nouveau
输出空白,说明禁用成功
安装kmod-nvidia驱动
yum -y install kmod-nvidia
kmod-nvidia.x86_64 0:
384.98
-1.el7_4.elrepo
nvidia-x11-drv.x86_64 0:
384.98
-1.el7.elrepo
yum-plugin-nvidia.noarch 0:1.0.2-1.el7.elrepo
*如果安装不成功,有可能是没有配置/etc/X11/xorg.conf
nvidia-xconfig
重建内核initramfs image
备份initramfs image
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
重建initramfs image
dracut /boot/initramfs-$(uname -r).img $(uname -r)
yum -y install bumblebee
bumblebee.x86_64 0:3.2.1-10.el7.elrepo
VirtualGL.x86_64 0:2.3.3-4.el7.elrepo
bumblebee-selinux.x86_64 0:1.0-1.el7.elrepo
fltk.x86_64 0:1.3.4-1.el7
kmod-bbswitch.x86_64 0:0.8-5.el7_4.elrepo
libbsd.x86_64 0:0.6.0-3.el7.elrepo
turbojpeg.x86_64 0:1.2.90-5.el7
把用户添加到 bumblee组
cat /etc/group | grep bumblebee
bumblebee:x:1001:
usermod -a root -G bumblebee
usermod -a david -G bumblebee
cat /etc/group | grep bumblebee
bumblebee:x:1001:root,david
配置bumblebee.conf
vi /etc/bumblebee/bumblebee.conf
[bumblebeed]
Driver
=
nvidia
[optirun]
Bridge=
auto
[driver-nvidia]
KernelDriver=
nvidia
PMMethod=
bbswitch
LibraryPath=
/usr/lib64/nvidia:/usr/lib64/vdpau:/usr/lib/nvidia:/usr/lib/vdpau
XorgModulePath=
/usr/lib64/xorg/modules/extensions/nvidia,/usr/lib64/xorg/modules/drivers,/usr/lib64/xorg/modules
编辑nvidia-settings.desktop
vi /usr/share/applications/nvidia-settings.desktop
Exec=optirun nvidia-settings -c :8.0
设置图形模式启动
systemctl set-default
graphical.target
reboot
选择kmod-nvidia驱动关联的内核版本启动
测试是否安装成功
optirun
glxgears
需要注意的是,在安装nvidia驱动前,需要将系统置为文本模式;否则会因为xorg.conf问题无法进入到桌面系统。
另外,在桌面启动后,会出现 Cannot access secondary GPU错误,需要修改 /etc/bumblebee/xorg.conf.nvidia
将BusID "PCI:*" 前面的 # 去掉 ,然后保存即可。
想要弄清楚到底是Intel还是NVIDIA在运行?打开你的终端,运行
optirun /usr/bin/glxspheres64 &
和
glxspheres64 & #不要optirun