Ubuntu Natty vs. nVidia

Despite all the problems I had with Ubuntu updates over the last couple of years, I decided to update my work machine to Ubuntu 11.04 ("Natty Narwhal"). I expected problems and I wasn't disappointed, after the upgrade I was left standing in the dark, without X.

Fortunately, the rest of the system worked, so I was able to log into the system via console. The log file in /var/log/Xorg.0.log showed the following error message:

[   161.049] (II) LoadModule: "nvidia"
[   161.049] (II) Loading /usr/lib/xorg/extra-modules/nvidia_drv.so
[   161.049] (II) Module nvidia: vendor="NVIDIA Corporation"
[   161.049]    compiled for 4.0.2, module version = 1.0.0
[   161.049]    Module class: X.Org Video Driver
[   161.052] (EE) NVIDIA: Failed to load the NVIDIA kernel module. Please check
[   161.052] (EE) NVIDIA:     system's kernel log for additional error messages.
[   161.052] (II) UnloadModule: "nvidia"
[   161.052] (II) Unloading nvidia
[   161.052] (EE) Failed to load module "nvidia" (module-specific error, 0)
[   161.052] (EE) No drivers available.
[   161.052]
Fatal server error:
[   161.052] no screens found
[   161.052]

After a bit of pondering I remembered that I was using a graphics driver from Ubuntu's "restricted" repository for my nVidia 9500 GT. The upgrade process installed a new kernel (package linux-image-2.6.38-8-generic-pae, check uname -r to see which kernel you're running) but wasn't able to rebuild the graphics driver kernel module because it neglected to install the matching header files (package linux-headers-2.6.38-8-generic-pae).

Here's what I did:

sudo apt-get install linux-headers-2.6.38-8-generic-pae
sudo dpkg-reconfigure nvidia-current

The nvidia-current package recompiled the kernel module and after a reboot (just in case), my graphical login was back and things worked normally. At some point I also removed my /etc/X11/xorg.conf and recreated it from scratch using sudo nvidia-settings, but I don't think this step was necessary.

The next problem I encountered was with my dual monitor setup (I'm using two monitors with a single graphics card). Unity didn't let me place windows on the second screen for some stupid reason. Using the nvidia-xconfig tool, I switched from "Separate X screen" configuration to "TwinView" and things worked again.