Newest NVidia Driver

If you are using an NVidia graphics card and are unfortunate enough to be trying to connect to a display that is not recognized by the NVidia driver, you will undoubtedly have problems configuring that display, since the shipping NVidia driver in many releases of Mythbuntu (e.g. 8.04LTS) does not recognize Modelines in the xorg.conf file. Before you can configure your display, using the information outlined below, you may have to install the newest NVidia driver (let the goat roping continue).

Firstly, since you are going to be messing with the X-Windows configuration and the display adapter, you must shutdown X. This pretty much means that you must first ensure that you have a working SSH connection to the machine in question, since shutting down X on the Mythbuntu distributions renders the machine useless (no, it does not revert to a console that you can enter commands into -- it just sits there in dumb-ass mode). So, get a copy of your favorite telnet, turn on SSH on the box and make sure you can talk to it that way. When you're happy that SSH works, shut down the X-Server:

     sudo /etc/init.d/gdm stop

From the telnet session, make sure you have the driver build environment (this is not necessarily the full kernel build environment). To verify that you do, try:

     ls -l /lib/modules/`uname -r`/build

If you have this directory installed, skip down to the libc step below (Ubuntu usually provides them in a typical installation or if you if you already did these steps in conjunction with compiling a NIC driver, above). Otherwise, you'll need to first get the build environment:

     sudo apt-get install build-essential

Then, you should make sure to install the latest headers for your kernel. When you enter the following command, be sure to use back-quotes:

     sudo apt-get install linux-headers-`uname -r`

Next, link the headers to the build folder in the proper place.

     sudo ln -s /usr/src/linux-headers-`uname -r` /lib/modules/`uname -r`/build

In addition to the driver build environment, you'll need the libc development package, the package configuration module, and the XOrg development package installed. Use the following command to get and install them:

     sudo apt-get install libc6-dev pkg-config xorg-dev

This should allow you to build the NVidia driver.

Create a new directory and download the latest NVidia driver for Linux from http://www.nvidia.com/object/unix.html:

     mkdir NVidia
     cd NVidia
     use your favorite browser to navigate through the NVidia pages and download
       the driver

Purge the NVidia restricted package, if installed, by doing:

     sudo dpkg --purge nvidia-glx-new

Run the NVidia installer:

     sudo sh NVIDIA-Linux-x86-173.14.05-pkg1.run

You can let the installer have a crack at finding a pre-compiled version on the NVidia Web site (but this didn't work for Mythbuntu 8.04LTS). If it doesn't find one, or you just want to compile it locally, skip that step. Allow the installer to build the driver locally. Then, allow it to update your xorg.conf file.

Note that the installer may whine about the compiler version not matching the one used to build the kernel. You've just got to love the guys who thought it would be a smooth idea to use compiled in kernel interfaces for all of the device drivers. Nothing like having to compile your device drivers every time you change kernels. So, if we're going that route, might as well build structures that depend on the compiler version for the interface to work. Why not? What a crock of shit....

Anyway, the warning is probably bogs, since different point releases of the compiler don't usually change the way structures are aligned. You can probably ignore it. But, if you're worried, you can try the following (it worked for me):

     sudo sh NVIDIA-Linux-x86-173.14.05-pkg1.run --add-this-kernel
     sudo sh NVIDIA-Linux-x86-173.14.05-pkg1-custom.run

This will build a custom install script especially for the currently-running kernel. You can then execute that script to build the NVidia driver especially for it. There shouldn't be any whining about the compiler version but, if you still have problems, here is the full story:

     If you know what you are doing and want to override this check, you can do
     so by setting the environment variable IGNORE_CC_MISMATCH, before doing the
     build.
     Otherwise, set the CC environment variable to the name of the compiler that
     was used to compile the kernel.
     The reason for compiling the NVIDIA kernel module with the same compiler
     version that was used to compile your kernel (as was noted above) is that
     some Linux kernel data structures are dependent on the version of gcc used
     to compile them; for example, in include/linux/spinlock.h:
     ...
     * Most gcc versions have a nasty bug with empty initializers.
     */
     #if (__GNUC__ > 2)
       typedef struct { } rwlock_t;
       #define RW_LOCK_UNLOCKED (rwlock_t) { }
     #else
       typedef struct { int gcc_is_buggy; } rwlock_t;
       #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
     #endif
     If the kernel is compiled with gcc 2.x, but gcc 3.x is used when the kernel
     interface is compiled (or vice versa), the size of rwlock_t will vary, and
     things like ioremap will fail.  To check what version of gcc was used to
     compile your kernel, you can examine the output of:
     cat /proc/version
     To check what version of gcc is currently in your $PATH, you can examine the
     output of:
     gcc -v

Oh, and one other little wrinkle. On some later versions of the OS (e.g. Mythbuntu 9.04), the geniuses at XOrg decided to add an irrelevant windge to the X command when "-showDefaultLibPath" is used. So, when the following command is run:

     /usr/bin/X -showDefaultLibPath

You see:

     X: warning; process set to priority -2 instead of requested priority 0
     /usr/lib

First of all, who gives a rat's butt what priority X runs at? And, certainly, who gives a rat's butt what priority it runs at when its echoing the default library path? Are these guys on some planet where stupidity is the norm? But, ranting aside, the windge comes as a huge surprise to the NVidia install script which is expecting the path name of a directory, not some meaningless bleating. The script gets all confused and complains about the fact that the directory "X: warning ... /usr/lib" doesn't exist. Duh! Fortunately, it picks /usr/lib by default and all is well, despite what could have been another blow for lack of upward compatibility.

Here are the instructions for the installer, just in case you need them. The complete instructions can be found in the README file on the NVidia Web site at: http://www.nvidia.com/object/unix.html.

     The .run file is a self-extracting archive. When executed, it extracts the
     contents of the archive and runs the contained nvidia-installer utility,
     which provides an interactive interface to walk you through the installation.
     nvidia-installer will also install itself to /usr/bin/nvidia-installer, which
     may be used at some later time to uninstall drivers, auto-download updated
     drivers, etc. The use of this utility is detailed later in this chapter.
     You may also supply command line options to the .run file. Some of the more
     common options are listed below.
     --info              Print embedded info about the .run file and exit.
     --check             Check integrity of the archive and exit.
     --extract-only      Extract the contents of NVIDIA-Linux-x86-173.14.05.run,
                         but do not run nvidia-installer.
     --help              Print usage information for the common commandline
                         options and exit.
     --advanced-options  Print usage information for common command line options
                         as well as the advanced options, and then exit.
     --uninstall         During installation, the installer will make backups of
                         any conflicting files and record the installation of
                         new files. The uninstall option undoes an install,
                         restoring the system to its pre-install state.
     --latest            Connect to NVIDIA's FTP site, and report the latest
                         driver version and the url to the latest driver file.
     --update            Connect to NVIDIA's FTP site, download the most recent
                         driver file, and install it.
     --ui=none           The installer uses an ncurses-based user interface if
                         it is able to locate the correct ncurses library.
                         Otherwise, it will fall back to a simple commandline
                         user interface. This option disables the use of the
                         ncurses library.

Black list the nv driver in the /etc/default/linux-restricted-modules-common file. Do so by editing the file with your favorite editor and changing the DISABLED_MODULES line to include "nv". For example:

     DISABLED_MODULES="nv"

Check that no prior installations of any versions of the NVidia driver have left crap-oh-la lying about to mess things up. In /etc/modprobe.d, you may find a module named "nvidia-kernel-nkc.conf". In it you may see something like:

     alias char-major-195* nvidia
     options nvidia NVreg_DeviceFileUID=0 NVreg_DeviceFileGID=44
                    NVreg_DeviceFileMode=0660

This will cause no end of grief by loading a copy of the NVidia kernel driver that is left over from the prior installation. When the newly-installed driver attempts to run, it will complain about the kernel driver API being wrong and quit, thereby causing XOrg not to start (you'll see this in /var/log/Xorg.0.log upon reboot). A sure test is to do "rmmod nvidia" and then restart gdm. If this causes gdm to start OK, you've got a conflicting module loaded.

Also, someone or something may have mistakenly tried to fix this situation by adding a blacklist for the nvidia driver to one of the blacklist files in /etc/modprobe.d. The most likely place is "blacklist-local.conf" but it may be somewhere else too. Look for any file containing:

     blacklist nvidia

Remove this line from the file. If it is the only line in the file, you may delete it too, if you wish.

Incidentally, some of the blogs or mail archives on the Internet suggest adding "rmmod nvidia" to /etc/init.d/gdm, right before gdm is started. If you fix the problem correctly, this should be completely unnecessary.

Start the gdm server back up:

     sudo /etc/init.d/gdm start

If you wish to use the NVidia-supplied configurator for the xorg.conf file, you can find the man page under:

     man nvidia-xconfig