Sunday, 10 June 2012

Centos 6/RHEL Install Genuine Nvidia Drivers

There are two ways to install drivers for Nvidia cards on Centos 6/RHEL, one is to use the Kmod from the repo and the other, slightly more involved, is to use the driver direct from Nvidias site.

This tutorial is to install the Nvidia drivers from Nvidia's site
and although the Kmod packages are the Nvidia drivers repackaged, you may still have some reason to use Nvidia's Linux drivers. You can accomplish this task using the Kmod drivers also.
 
We will not be using any repositories and if you have installed your Centos 6 as per this tutorial and set up the kernel correctly you should not get any errors about the wrong compiler.

We are changing the defaults in /etc/inittab because 'telinit 3' and 'Ctl+Alt+F4" do not always disable X server properly and the Nvidia script complains.

I have also put the section on kernels at the bottom of this page so you can fix them, if necessary, before proceeding. It is not difficult to do, simply a matter of removing the out of date ones and updating/installing the matching kernel-headers/kernel-devel files.

You will need

  • The Genuine Nvidia Driver/Script from Nvidia
  • A disable-nouveau.conf file  (which you will create)
  • A line in /etc/grub.conf to disable nouveau from loading.
2 commands to check your kernels match.


$ uname -r                                

$ rpm -qa kernel-devel     

If the numbers don't match scroll down to the bottom of this page to the kernels section, follow it and return here.

Install compile tools if not already installed.

$ sudo yum -y install gcc gcc-c++ automake autoconf make         

Getting the Nvidia Driver

Go to http://www.nvidia.com/Download/index.aspx?lang=en-us and select your driver, it will have a .run or .sh extension, download to your home directory. The one I used is NVIDIA-Linux-x86-295.49.run      

$ chmod u+x NVIDIA-Linux-x86-295.49.run    make it executable

(substitute the above file for your version of it)

Leave it in your home directory.

Blacklisting nouveau driver.           

$ sudo vi /etc/modprobe.d/disable-nouveau.conf   enter

blacklist nouveau options nouveau modeset=0

and save the file 

See Vim Editor for vi commands                                 

$ sudo cp /etc/grub.conf /etc/grub.conf.bak    

Backup grub.conf  
                                       
$ sudo vi /etc/grub.conf                

Find this section

  kernel /vmlinuz-2.6.32-220.el6.i686 ro root=/dev/mapper/vg_centos-lv_root rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=uk LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT=latarcyrheb-sun16 rhgb quiet crashkernel=auto rd_LVM_LV=vg_centos/lv_root rd_NO_DM
initrd /initramfs-2.6.32-220.el6.i686.img

After the line rhgb or somewhere appropriate enter this line

rdblacklist=nouveau nouveau.modeset=0    

Save the file. Now change the run level 

$ sudo vi /etc/inittab       

Scroll down and change default to '3'   

Save, exit & reboot. 

Login as root in console mode.                       

Installing the driver

Go to the Nvidia script in your home directory.

# cd /home/<user_name>        

# ./NVIDIA-Linux-x86-295.49.run     hit enter to run it

Substitute the above file for your version of it.

Follow the dialogue box, largely 'accept' and 'write to xorg.conf' at the end, and your drivers are installed. If you get an error message about the wrong compiler version then scroll down to the bottom of this page and follow the section on how to update the kernel in Centos6/RHEL

# vi /etc/inittab           change back to '5'

Reboot (Not telinit 5)

Log on as a normal user and open up this tutorial to finish off your settings.

$ lspci | grep VGA           shows current video hardware

Setting up with Nvidia settings

Open a terminal

$ su -c 'nvidia-settings'              enter password

The Nvidia settings dialogue box will open so you can adjust resolutions and refresh rates etc in the 'X Server Configurations' tab and save everything to xorg.conf to make it permanent and keep the same setup on reboot.

A thread on Nouveau & Modeset in Slackware.

To reverse the procedure if you have to use a different graphics card then just

$ sudo rm /etc/X11/xorg.conf /etc/modprobe.d/disable-nouveau.conf 

$ sudo cp /etc/grub.conf.bak /etc/grub.conf

Check screen resolution

If it is not obvious and you want to check resolution

$ xdpyinfo | grep 'dimensions'


dimensions:    1024x768 pixels (413x260 millimeters)

$ xrandr | grep '*'

1024x768       75.0*    60.0
 

Switch cards on a Laptop.

If using a laptop with both onboard and dedicated cards then you can use Bumblebee, which enables you to switch between them.
Bumblebee is in both Elrepo & Atrpms repos as 'bbswitch', so install one of them and issue the command

$ sudo yum -y --enablerepo=elrepo install bbswitch 

Atrpms repo may also add a new kernel so you can either keep it and remove old/update to new as below, or just remove it and keep your current ones.

If you don't wish to install the repos you can just download the package from either one, in Elrepo it is listed as 'bumblebee'.

Kernels

To ensure smooth compiling set up the the supporting  kernel files, you should do this before you install Nvidia drivers.

Reinstall Nvidia Drivers after a kernel upgrade

It does not involve much after a kernel upgrade to re install the drivers, because the files /etc/modprobe.d/disable-nouveau.conf & /etc/grub.conf keep their lines intact, so all you need to do is re run the Nvidia driver (old one or download a new one)

Provided that you have set up the new kernel wih matching devel, firmware and headers as above then the steps would be similar to below.

Remove xorg.conf  (or you can't boot to graphical interface)

$ sudo rm -rf /etc/X11/xorg.conf   

Get your driver in place and chmod it as above

$ sudo vi /etc/inittab        (set to 3)

Reboot, login as root, cd to home directory and run the driver package again, it will remove the old driver and write a new xorg.conf file. Then set inittab back to 5, reboot and run

$ su -c 'nvidia-settings'

Remove driver completely 

Run the driver again as above but pass the --uninstall flag to it

$ rm -rf /etc/modprobe.d/disable-nouveau.con

& take out the blacklist-nouveau lines in /etc/grub.conf
         








3 comments:

  1. Thank you for this article. Very helpfull.
    I have a comment to make. I think it is safer to modify/backup the file /boot/grub/grub.conf instead of /etc/grub.conf. The last file is a link to the first one. Μodifying /etc/grub.conf it is possible to lose this link. This happened to me and caused me problems...

    ReplyDelete
  2. Hi, yes you are probably right, Thanks.

    ReplyDelete