**2018/06/30更新:如果你只想用独显,不需要安装Bumblebee进行双显卡切换,请移步此文[Install Nvidia driver, CUDA 9.1 and Tensorflow 1.5 on Fedora 27/28](http://blog.leanote.com/post/gaunthan/Install-CUDA-9.1-and-Tensorflow-1.5-on-Fedora-27),安装更省心。**
## Overview
闭源驱动和开源驱动哪个更好?在文章[《开源、闭源大不同,Linux 下 AMD、NVIDIA 显卡驱动对比》](http://www.expreview.com/25231.html)中的实验表明,闭源驱动的性能表现优于开源驱动。这是自然的,显卡设备厂家掌握更多的设备信息,因此编写驱动时更能发挥设备的特性。
虽然开源是个好东西,但作为开发者来说,效率可能更为关注。因此安装闭源驱动有一定必要性。在 Linux 下安装闭源驱动比较麻烦,不同的笔记本安装方式可能大相径庭。本文主要是做一个安装的导引作用,由于网上已经有很多这类教程了,因此对于安装过程的详细信息就不多言了。请各位根据自己设备的情况选择相应的教程。
## Check video cards
在 Linux 中查看显卡设备很简单,运行下面这条命令即可:
lspci -vnn | grep -E "VGA|3D"
如对于运行 Fedora 25 的 Acer V3 572G 笔记本来说,结果如下:
![](https://leanote.com/api/file/getImage?fileId=5aa0a3d2ab64411766000560)
如果想把具体的信息输出,可以使用 `grep` 命令的输出下文选项 -A,如:
![](https://leanote.com/api/file/getImage?fileId=5aa0a3d3ab64411766000563)
可以发现 Fedora 25 默认为 N 卡安装 nouveau 闭源驱动。
## Check if has Nvidia Optimus
如果你的运行结果类似于下面的输出:
```bash
00:02.0 VGA compatible controller: Intel Corporation 2n Generation Core Processor Family Integrated Graphics Controller (rev 09)
01:00.0 VGA compatible controller: nVidia Corporation GF106 [GeForce GT 555M SDDR3] (rev a1)
```
或
```bash
00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
01:00.0 3D controller: NVIDIA Corporation GK107M [GeForce GT 750M] (rev a1)
```
那么你的电脑很可能拥有 NVIDIA Optimus Technology。
## Without NVIDIA Optimus
如果确定没有 NVIDIA Optimus Technology,那么可以按照[Fedora 25/24/23 nVidia Drivers Install Guide](https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide/)教程进行安装。
## With NVIDIA Optimus
### Install Bumblebee
如果有这项技术,则上面的教程不适用,需要转而安装 Bumblebee。安装教程见:[Fedora - Bumblebee](https://fedoraproject.org/wiki/Bumblebee)。
如果你的机器拥有 Intel + Nvidia 双显卡,系统是 Fedora 25 based on x86_64,那么可以运行下述命令进行安装,安装完需要重启系统:
```sh
sudo su
# Add bumblebee repo
dnf -y --nogpgcheck install http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee/fedora$(rpm -E %fedora)/noarch/bumblebee-release-1.2-1.noarch.rpm
# Managed NVidia repo
dnf -y --nogpgcheck install http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee-nonfree/fedora$(rpm -E %fedora)/noarch/bumblebee-nonfree-release-1.2-1.noarch.rpm
# Multilib on a 64 bit install fedora 23+
dnf install bumblebee-nvidia bbswitch-dkms VirtualGL.x86_64 VirtualGL.i686 primus.x86_64 primus.i686 kernel-devel -y
```
### Install Bumblebee Indicator
Bumblebee安装完成后,如果是Gnome桌面环境,可以安装Bumblebee Indicator插件。这个Shell插件会在通知栏上显示一个小黄蜂,当Bumblebee运行时,它会以黄色显示:
![](https://leanote.com/api/file/getImage?fileId=5aa0a3d2ab6441176600055e)
### Test Bumblebee
Bumblebee提供了两种运行方式:
- `primusrun `:以集显运行命令command
- `optirun `:以独显运行命令command
默认情况下,应用程序都是用集显运行的,这能有效降低机器的功耗。可以使用命令`glxgears`测试显卡,它会在屏幕上显示一张3D动画,同时在终端中输出渲染帧率:
![](https://leanote.com/api/file/getImage?fileId=5aa0a3d2ab6441176600055f)
![](https://leanote.com/api/file/getImage?fileId=5aa0a3d2ab64411766000561)
下图展示了分别以两种方式运行该命令的结果:
![](https://leanote.com/api/file/getImage?fileId=5aa0a3d2ab64411766000562)
可见,在独显模式下程序的图形渲染能力远远高于集显。因此,运行对图形性能要求高的程序时,以`optirun`方式运行程序会获得更好的表现。
## Problem Solving
### Cannot login to xorg
如果安装 Bumblebee 后无法从 xorg 登录系统,每次输入密码回车后都跳回到登录界面,但使用 Wayland 却可以登录。可以尝试将 /etc/X11/xorg.conf 文件删除。**删除前记得备份文件。**
## References
- [Linux 中如何查看显卡硬件信息](http://os.51cto.com/art/201512/501857.htm)
- [开源、闭源大不同,Linux 下 AMD、NVIDIA 显卡驱动对比
](http://www.expreview.com/25231.html)
- [Fedora 25/24/23 nVidia Drivers Install Guide](https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide/)
- [Fedora - Bumblebee](https://fedoraproject.org/wiki/Bumblebee)
- [Fedora 25 下双显卡安装 Bumblebee + CUDA](https://semsevens.com/2016/12/21/fedora-25-bumblebee-nvidia-cuda/)
- [cannot login to gnome xorg](https://forum.antergos.com/topic/5691/cannot-login-to-gnome-xorg)
- [Ubuntu 16.04 下 CUDA8 环境配置的 2 种方法](http://notes.maxwi.com/2017/02/26/ubuntu-cuda8-env-set/)
- [Installing Nvidia’s CUDA 8.0 on Fedora 25](https://davidwpearson.wordpress.com/2017/01/12/installing-nvidias-cuda-8-0-on-fedora-25/)
- [Can't locate InstallUtils.pm in @INC](https://devtalk.nvidia.com/default/topic/983777/cuda-setup-and-installation/can-t-locate-installutils-pm-in-inc/)