Install Nvidia Driver in Hybrid Graphics Laptop on CentOS, RHEL7,8

This guide will show you how to install Nvidia driver in a hybrid graphics laptop on Linux. For this guide, we have a laptop with dual graphics adapters, or you can say (hybrid graphics), one is (intel integrated GPU), and other is (Nvidia GTX950M), and we are running CentOS 7 Linux on top of it. 
 

This guide requires "Secure Boot" to be turned off from BIOS (if exists) before proceeding with the following, or Nvidia driver loading will fail.
 
 

Add RPMFusion Repository

First, you need to add the RPMFusion repository in your system. To enable access to these repository, execute the following command, depending on what distribution you use and then follow the default options to install.

For CentOS, RHEL 7:
sudo yum -y install epel-release
sudo yum -y install https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
sudo yum -y install https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
For CentOS, RHEL 8:
sudo dnf -y install epel-release
sudo dnf -y install https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
sudo dnf -y install https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
RHEL 8 requires an additional step:
sudo subscription-manager repos --enable "codeready-builder-for-rhel-8-$(uname -m)-rpms"
CentOS Steam 8 requires an additional step:
sudo dnf config-manager --enable powertools
CentOS 8 (older version) used a case sensitive name for the PowerTools repository:
sudo dnf config-manager --enable PowerTools

Install NVIDIA Driver

Type below command to install latest available Nvidia driver on CentOS, RHEL 7
sudo yum -y install gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs xorg-x11-drv-nvidia-libs.i686 akmods
For CentOS, RHEL 8:
sudo dnf -y install gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs xorg-x11-drv-nvidia-libs.i686 akmods
You must wait 5-10 minutes for the kernel modules to load. Please do not proceed to the next steps immediately.

Execute following command to force the configuration to be read from the updated kernel modules which now have the latest Nvidia driver in them.
sudo akmods --force
sudo dracut --force
Wait for 3-5 minutes for the changes to take effect and then reboot your system.
sudo shutdown -r now
 

Install Bumblebee

Bumblebee providing an elegant and stable means of managing optimus hybrid graphics chipsets. A primary goal of this project is to not only enable use of the discrete GPU for rendering, but also to enable smart power management of the dGPU when it's not in use. 
 
For CentOS, RHEL 7:
sudo yum -y install elrepo-release
sudo yum -y install bumblebee
For CentOS, RHEL 8:
sudo dnf -y install elrepo-release
sudo dnf -y install bumblebee
 Type below command to add your username to bumblebee group:
sudo usermod -aG bumblebee root
sudo usermod -aG bumblebee your_username
Reboot your system to make changes to take effect:
sudo shutdown -r now
Once your system has started, edit bumblebee.conf with any of preferred text editor:
sudo vi /etc/bumblebee/bumblebee.conf
Make the following highlighted changes:
[bumblebeed]
VirtualDisplay=:8
KeepUnusedXServer=false
ServerGroup=bumblebee
TurnCardOffAtExit=false
NoEcoModeOverride=false
Driver=nvidia
XorgConfDir=/etc/bumblebee/xorg.conf.d

[optirun]
Bridge=auto
VGLTransport=proxy
PrimusLibraryPath=/usr/lib64/primus:/usr/lib32/primus
AllowFallbackToIGC=false

[driver-nvidia]
KernelDriver=nvidia-drm
PMMethod=auto
LibraryPath=
XorgModulePath=
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia

[driver-nouveau]
KernelDriver=nouveau
PMMethod=auto
XorgConfFile=/etc/bumblebee/xorg.conf.nouveau
Save and close the editor when you are finished.

Edit nvidia-settings.desktop with any of your preferred text editor:
sudo vi /usr/share/applications/nvidia-settings.desktop
Make the following highlighted changes:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=NVIDIA X Server Settings
Comment=Configure NVIDIA X Server Settings
Exec=optirun nvidia-settings -c :8.0
Icon=nvidia-settings
Categories=System;Settings;
Save and close the editor when you are finished.

Reboot your machine to take changes into effect:
sudo shutdown -r now
Once your system has booted, type below command to verify your Nvidia GPU rendering:
optirun glxinfo -display :8.0 | egrep "OpenGL vendor|OpenGL renderer"
It should show your NVIDIA GPU like below.
 

Type below command to clone screenfetch script from github:
cd ~
git clone https://github.com/KittyKatt/screenFetch.git
cd screenFetch/
chmod +x screenfetch-dev
sudo cp screenfetch-dev /usr/bin/screenfetch
Execute screenfetch
optirun screenfetch
It should show your NVIDIA GPU under the GPU name like below:
 
 
Type below command to open NVIDIA X Server Settings application.
optirun nvidia-settings -c :8.0
You can make other configuration changes using NVIDIA X Server Settings application. Also the GPU would show activity in its utilization percentage to signify that it is actually working.
 

 
Whenever you need to run an application to be rendered using Nvidia GPU, you should run it like example below:
optirun firefox
optirun -display :8.0 firefox
At this stage, your laptop is ready to be used with integrated GPU, and NVIDIA GPU at the same time depending on your applications requirements. If you don't need an application to be rendered using Nvidia GPU, run it without optirun, and it will automatically use intel integrated GPU.

In this guide you learn, how to install latest Nvidia driver on a hybrid graphics laptop running CentOS, RHEL or Oracle Linux on top of it. You also learn how to switch between integrated GPU and Nvidia GPU using bumblebee optirun.
 
 

Conclusion

Now that you have successfully installed latest NVIDIA driver on a CentOS, RHEL machine, you can begin testing your graphic adapter functionality with any of applications, tools, or games of your choice.

14 comments:

  1. Hello. Did what you said here and as a result there's no mouse or keyboard in GUI. Any suggestions?

    ReplyDelete
    Replies
    1. Solution to your problem is: yum -y install xorg-x11-drv-evdev xorg-x11-drv-synaptics

      Delete
  2. Hello. Followed your instructions to the letter and the result is an error: "Bumblebee Daemon has not been started yet or the socket path /bar/run/bumblebee.socket was incorrect." Any suggestions?

    ReplyDelete
    Replies
    1. You should check your problem here https://github.com/Bumblebee-Project/Bumblebee/wiki/Troubleshooting and here https://github.com/bumblebee-project/bumblebee/issues/227 and try to fix your issues as suggested.

      Delete
    2. Try this to fix your issue:

      yum -y install dkms-nvidia

      Delete
  3. AnonymousJuly 28, 2020

    Doesn't work on Centos 8 (64bit). Appears as thought the ELrepo 8 isn't as complete.

    ReplyDelete
  4. Hi, and then how do I launch applications with the GPU? I tried optirun firefox and when I do nvidia-smi it is not a process. Could you explain why to me? Thanks

    ReplyDelete
    Replies
    1. from a terminal, execute the following command to open NVIDIA control panel:

      optirun nvidia-settings -c :8.0

      Delete
  5. I did and it works. My issue is that NVIDIA settings does not recognize my internal screen and shows "X Screen 0 no scannout". I am on CentOS 8 and my settings shows exactly like on the article and I followed every steps correctly. Running "optirun nvidia-settings -c :8.0" show me that it uses the GPU in nvidia-smi but running optirun firefox for example does not create any process that are shown in nvidia-smi. If you have any idea what could be causing the issue, any help would be greatly appreciated, thank you.

    ReplyDelete
    Replies
    1. Your internal screen must be connected to builtin VGA card if your machine has dual graphic adapters for example, intel and your external screen is connected to your Nvidia. Try to execute firefox with GPU like below:

      optirun firefox http://google.com

      Delete
    2. Do you know how to uninstall Bumblebee?

      Delete
    3. You can execute "yum -y remove bumblebee" on a terminal to uninstall bumblebee package, and reboot your machine to take changes into effect.

      Delete
  6. Sorry, I found the problem. For some reason, the xorg.conf generated by elrepo has to be changed on a laptop. Thanks for the help

    ReplyDelete
    Replies
    1. Happy to hear that you fixed it. Would you mind if you share here the changes you made in xorg.conf that helped you fixing the issue?

      Delete

Comments with links will not be published.

Powered by Blogger.