Thursday, January 31, 2013

Nvidia and Debian Squeeze

So, using the Raspberry Pi as my Linux machine has spoiled me.  Because every RPi is the same there aren't the Driver issues that Linux often has.  If you have the drivers for one Raspberry Pi, you have them all (though the problem sometimes rears it's head with peripherals like wifi and bluetooth cards, you can avoid it by going to the Verified Peripherals page and selecting one known to work.

But blaming Linux for the lack of driver support is unfair.  It's not Linux fault that most parts manufacturers don't support Linux or won't even give the devs the info they need to support it.  It's amazing we have the support that we do have, and full credit to those masked men and women who spend hours trying (and mostly succeeding) to backwards engineer drivers for us.  Thank-you.  We've come a long way in the last 20 years.  However the sad truth is that drivers still cause issues, more often with laptops where you can't swap out video, wireless, or bluetooth cards that don't work (the main offenders).

Modern video cards are especially tricky to write drivers for, because they're just so complex.  In Nvidia's defence, they do release some closed source drivers for Linux (they got it half right), but it's not very high on their list of priorities, and support often breaks when the kernel is updated.  I'd tried all the methods on the official Debian wiki to try and get them working on Debian Squeeze (the stable, safe version of Debian)1.  No joy.  I googled for tutorials, followed them, still no joy.  As soon as they were installed I lost my graphical user interface.  If this happens to you the following command is your friend.  It will stop the computer using the (non-working) nvidia drivers by renaming the xorg.conf file.

cd /etc/X11/
mv xorg.conf xorg.conf.nvidia

Though I recommend making a copy of the original xorg.conf file before you start messing around with the image drivers, and then you can just (as root in recovery mode) move it back into the cd /etc/X11/ directory if something goes wrong.

cd into the folder where you saved the copy (with a sensibile name like xorg.conf.backup).  The ls command is helpful here, as it lists the contents of your current folder (the names of other folders will be in blue).  cd .. will make you go up a level.  When you're in the folder where you saved the backup type:

mv xorg.conf.backup /etc/X11/xorg.conf

Though even with the above knowledge this can be a risky business, and I recommend backing up everything before trying installing any new drivers.  Actually, I am assuming you know you have and nvidia card before coming here, you can check by typing:


My video card results look like this:

02:00.0 VGA compatible controller: nVidia Corporation GT216 [GeForce GT 320M] (rev a2)

If you don't have an nVidia card you will need to look somewhere else.  I recommend a google using the linux distribution you are using (in this case Debian Squeeze) and the name of the card (in my case GeForce 320M).  Good-luck.  For those of you who do have an nVidia card, let's continue :).

Firstly you will need to add the following repositories (where the software comes from) to your sources:
deb squeeze-backports main contrib non-free
deb-src squeeze-backports main contrib non-free
deb squeeze main contrib non-free

sudo gedit /etc/apt/sources.list

Then copy and paste the green writing into gedit, and save the file.

Install the following programs, and follow the instructions (click yes when asked a question)

apt-get install -t squeeze-backports dkms nvidia-kernel-dkms

Then you will need to run them with:

dpkg-reconfigure nvidia-kernal-dkms

Nearly there.  The next step is to update the xorg.conf file so that it says to use the new drivers.

sudo gedit /etc/X11/xorg.conf

You may need to change the Device Section so that it reads:

Section "Device"
    Identifier     "Video Card"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"

Finally you will need to add a Module Section just before it:

Section "Module"
    Load        "glx"

The final step is to reboot.  If you come come up with the black screen, then it means to nVidia driver install didn't work.  Just press CTRL+ALT+DEL and when you reboot choose the recovery version.  Enter you root password (you'll need to be root to make changes to the /etc/X11 folder) and follow the instructions for saving your xorg.conf.backup file as xorg.conf.  Hopefully, though, you get that interesting nVidia eye looking at you.  Good-luck!

1    Debian squeeze is the big brother of Raspbian, and so familiar to my fellow Raspberry Pi users.  This is why I chose it, though to be honest Xubuntu (a child of Debian) would be just as good a choice, and even runs the same Desktop (XFCE) and so may be a better choice for my fellow noobs.  This tutorial should work in Ubuntu as well.