August 4th, 2012

Thinkpad W520 Multi-Monitor nVidia Optimus with Bumblebee on Ubuntu 12.04

Last night I decided to upgrade from Ubuntu 11.10 to 12.04 on my Thinkpad W520. The main reason for this was that my current setup was making suboptimal use of the hardware, and due to recent advances which I found documented in several blog posts, it seemed I could improve this situation. The goal of this post is then to document I hoped to achieve, and how I arrive there, so that in the future I’ll be able to remember what the heck I did to set this all up.

Project Goals

I purchased the Thinkpad W520 back in November, because my fanless Mini Inspiron netbook kept overheating when I left it to run performance benchmarks related to my research. Ubuntu 11.10 worked pretty well on the W520 out of the box, but there were two major outstanding compatibility issues.

First, the W520 comes with nVidia Optimus graphics. In this setup, the laptop has a discrete nVidia card and an on-board Intel graphics card, and the operating system is able to enable and disable the nVidia card in software in order to save power. nVidia has explicitly stated that they will not support Optimus in Linux, which six months ago meant that there were only two options for Linux users: enable only discrete graphics or integrated graphics in the BIOS.

When the Intel graphics were enabled in the BIOS, the open source Intel integrated graphics drivers worked like a dream – 3D acceleration, flawless suspend/resume support, and everything was just a superb, rock-solid experience. The battery life was also excellent. For someone like me who mostly uses the laptop to write software and does not care about 3D acceleration, this would have been an ideal choice, except for one major flaw, which is that the external display ports on the W520 (VGA and DisplayPort) hardwired to the nVidia card, so using an external monitor is impossible when only Intel Graphics are enabled in the BIOS. I use an external monitor at home, and so this meant Intel graphics were a nonstarter for me.

As it was not possible to use Optimus or Intel graphics, this left me with only one choice, which was to use the nVidia graphics. This process went something like this:

  1. Tried the nouveau driver. This worked pretty well, but would hang X on suspend/resume. Solid suspend/resume support is a must-have, so I eliminate this option
  2. Tried to install the nVidia binary driver in Ubuntu using the nice graphical interface (jockey-gtk). Ultimately, this did not work. Uninstalled the binary driver using jockey-gtk.
  3. Tried to install the nVidia binary driver by running the Linux installer shell script from nVidia. This felt evil, because you have no idea what the script is doing to your system, but everything installed correctly, and after a reboot, the laptop finally had working graphics.

The binary nVidia drivers were pretty solid: 3D acceleration, multi-monitor support, suspend/resume, and VDPAU video acceleration all worked great. My laptop had an uptime of several months under this configuration. Unfortunately, however, battery life was pretty poor, clocking in at about 3 hours.

Furthermore, and more seriously, the laptop firmware has a bug where Linux would hang at boot when both VT-x (Intel hardware vitalization technology) and nVidia graphics were enabled in the BIOS. This was pretty annoying, as I tend to run Windows in a VM in Virtualbox on Linux for testing compatibility with different versions of Internet Explorer. I believe this bug is now being tracked by Linux kernel developers, who are working around this issue by disabling X2APIC on boot, but Lenovo has refused to fix this bug, or acknowledge its existence. Not cool, Lenovo.

This meant that it would not be possible to have both working multi-head support, and reasonable battery life and VT-x support. Not optimal.


Bumblebee is a project to bring support for nVidia Optimus to Linux. It basically renders a virtual X server on the nVidia card, and then passes the buffer to the Intel card which dumps it to the screen. Apparently, this is pretty much how Optimus works on Windows as well.

The advantage to using Bumblebee is that, theoretically, you would be able to have the excellent battery life of the Intel graphics, but also have 3D acceleration and multi-monitor support from the nVidia graphics.

I tried bumblebee 6 months ago, but was unable to get it to work. The project had also been forked around that time, and it wasn’t clear which fork to follow.

However, the following blog posts led me to believe that the situation had changed, and a multi-monitor setup could be achieved using Ubuntu 12.04 and Bumblebee:

I decided to see if I could get this to work myself, and ultimately I was successful. My current setup is now as follows:

  • Ubuntu 12.04 x64
  • Optimus Graphics and VT-x enabled in BIOS
  • External monitor, which can be enabled or disabled on-demand, and works consistently after suspend/resume
  • Bumblebee set to use automatic power switching, so the nVidia card is disabled when not in use.
  • Xmonad and Unity2D desktop environment

The remainder of the blog post documents the process I went through in order to obtain this optimal setup.

Multi-Monitor Support with Optimus and Bumblebee on Ubuntu 12.04

I primarily followed the process described on Sagar Karandikar’s blog, up to, but not including, his changes to /etc/bumblebee/bumblebee.conf.

Sagar says to set the following parameters in /etc/bumblebee/bumblebee.conf

And then enable the external monitor as follows:

As far as I understand it, these parameters set in /etc/bumblebee/bumblebee.conf tell Bumblebee to use the nVidia proprietary driver (Driver=nVidia), keep the nVidia card turned on (PMMethod=none disables bumblebee power management), and perpetually run an X server (KeepUnusedXServer=true). Clearly this setup would have negative implications for battery life, as the nVidia card is kept on and active.

optirun true then should turn on the nVidia card and output to the external monitor. xrandr tells the X server where to put the virtual display, and screenclone clones the X server running on display :8 (the X server being run by Bumblebee on the nVidia card) to the Intel virtual display.

I found that this technique was really finicky. optirun true would enable the external display right after rebooting, but would often not enable the display in other situations, such as after a suspend/resume cycle. It wasn’t clear how to bring the nVidia card back into a good state where it could output to an external monitor.

At this point, I read a comment by Gordin on Sagar’s blog, and his blog post. In this post, he describes using bbswitch for power management in bumblebee.conf, and running the second display using optirun screenclone -d :8 -x 1. This has the advantage of: a) enabling power management on the nVidia card, so it is turned off when not in use, and b) seemingly increased reliability, as the nVidia card will be enabled when screenclone is run, and disabled when the screenclone process is terminated. Based on these instructions, I came up with the following adapted solution.

Set the following settings in /etc/bumblebee/bumblebee.conf:

The following shell script will enable the external monitor. ^C will disable the external monitor:

This setup now works great, although screenclone does behave a bit strangely sometimes. For example, when switching workspaces, screenclone may require you to click in the workspace on the second desktop before it updates its graphics there. There were a few other minor quirks I found, but ultimately it seems like a solid and reliable solution.

Desktop Environment: Xmonad and Unity2D

I like Unity mostly because it provides a good global menu, but I find most other parts of it, including window management and the launcher, to be clunky or not very useful. Furthermore, certain Ubuntu compiz plugins that would improve the window management, such as the Put plugin, seem to be completely broken on Ubuntu out of the box:

I therefore set up my desktop environment to use the Unity2D panel and the Xmonad window manager. I primarily followed this guide to set this up:

The only change I made was to /usr/bin/gnome-session-xmonad. I’m not sure why, but xmonad was not getting started with the desktop session. I therefore started it in the background in the /usr/bin/gnome-session-xmonad, along with xcompmgr, a program which provides compositing when running non-compositing window managers like Xmonad. xcompmgr allows things like notification windows to appear translucent.

For a launcher, I’m now trying out synapse, which can be set to run when the gnome session is started.

May 7th, 2009

GNU/Linux Desktop Distress

Right now, I’m running Kubuntu 8.04, which uses the very excellent KDE 3.5.10 desktop environment. Unfortunately, Kubuntu 8.04, unlike its close cousin Ubuntu 8.04, is not an LTS (Long-Term Support) release. This means that, instead of support being discontinued in April 2011, it will be discontinued in October of this year. I suppose this makes sense, as KDE technology has moved on to the 4.* branch. The KDE developers apparently no longer even fix bugs in KDE3 apps. This makes me sad, because I’m totally happy with my current setup. I really don’t want to change my system when everything is working so nicely, but I’m afraid I’m just going to have to bite the bullet and do it. The question is, what should I change to? It seems like my main options are to either upgrade to Kubuntu 9.10 (which will be out in October), which should ship with the KDE 4.3 desktop; or, I stay in 8.04, but step over to the Ubuntu desktop.

One reason I’ve been avoiding using GNOME/Ubuntu is that by using Kubuntu 8.04, I’ve been able to avoid PulseAudio. I have had terrible experiences with PulseAudio so far. It is really not ready for normal users. My roommate Chris has discreetly switched back to using Windows because we couldn’t adequately resolve his audio problems. I don’t blame him; PulseAudio is not ready to go. Neither is Phonon (the KDE4 media backend) for that matter.

BUT, I have used PulseAudio enough to apprehend the vision behind it, and I like it. I like the idea of having audio sources, sinks and streams; having the ability to redirect those streams arbitrarily, even across a network. It’s a lovely, simple vision. I would love to write a beautiful, graph-like UI on top of it. I want to believe in PulseAudio. I want it to work. So, if I can get the minimum apps that I need to work, including the proprietary ones (Flash and Skype, although I’m hoping to finally begin to migrate rapidly away from Skype very soon), given my very minimal hardware requirements, and have it work reliably, then I will be a happy camper. Anyways, I’ve sudo apt-get installed ubuntu-desktop, and I’m going to try it and see what the state of things are.

The other reason why I’ve been hesitant to switch to GNOME/Ubuntu is because of GNOME’s use of Mono. I’m in the camp that says that relying on Mono is bad. Microsoft is litigious and Mono is patent-encumbered. It should therefore be avoided; it’s as simple as that. What that ultimately means in terms of how I use my desktop, though, is not clear. The only applications that come bundled with Ubuntu that use Mono appear to be FSpot and Tomboy. That’s not so bad; these are two apps I can live without. But I was hoping to try out Gnome-Do, which is also based on Mono. It’s tempting to just ignore the issues surrounding it, and just install the app, but it feels dirty and wrong, so I just won’t do it.

There are certain KDE apps that I would miss if I used GNOME: Amarok is a big one. Konqueror is another. KDESVN rocks my socks. Of course, I can use all of these apps in GNOME as well, but then it pulls in all of the KDE libraries.

In any case, these are all KDE3 apps running on top of KDE3. From what I’ve seen, the KDE4 apps are often radically different. One reason I’m even engaging in this discussion is because my experience of KDE4 has so far been quite bad. On every platform I’ve used it, KDE4 has felt slow and buggy. I got a chance to really sink my teeth into it in Kubuntu 9.04 (the last *buntu I installed on my roommate Chris’s computer before he finally gave up on it), and everything regarding usability was just awful. For just an example, look at what they did to the available apt front-ends. Kubuntu 8.04 shipped with aptitude_manager. It was fast, had a fast incremental search, a simple direct UI. I never once had a problem with it. Not a single instance of it not being able to install packages correctly or crashing. Even slightly weird packages like the java-sun* packages that require you to agree a special license installed easily and reliably. In KDE4, on the other hand, you have KPackageKit. The app feels slow, the UI is terrible, and it choked multiple times when trying to install software. In particular, it choked on java-sun, and actually asked me to try using a better apt front-end. Ridiculous. There is also a version of Aptitude for KDE4, although though it doesn’t ship by default, but the UI is also very different from the KDE3 version, and, in my opinion, is not very usable.

My experience of KDE4 was like this constantly while I was setting Chris up with Kubuntu 9.04. So I feel I may not be very happy in KDE4. Too much has changed, most of it for the worse.

So where does that leave me as a full-time GNU/Linux user, looking toward the future of my OS of choice?

Probably GNOME, sans Mono. Although I keep waffling about this. Hopefully, in six months Kubuntu will have turned things around, and I can reassess my decision. But who knows, by that time I might be a happy GNOME user.

This work is licensed under GPL - 2009 | Powered by Wordpress using the theme aav1