Suspend Troubles in Ubuntu 14.04

My laptop is a Vaio Z13 with an Nvidia GT330M discrete graphics card and an integrated Intel graphics controller. A physical switch above the keyboard is used to toggle the discrete card. The Nvidia card is useful for games and hooking an external monitor via the HDMI port, but is a battery hog. When the Nvidia card is off, the Intel controller is sufficient for everything else, and can also control an external monitor via the VGA port.

After a fresh install of Ubuntu 14.04, both graphics controllers are correctly detected, and everything looks like it is run by the Intel driver. But the Nvidia card is also turned on, eating away at the battery while I cannot use its benefits.

Since Ubuntu 12.10, I had been relying on Bumblebee to turn off the Nvidia card on boot, and use the optirun command to run GPU-hungry applications under the Nvidia card whenever I needed. It was a setup good enough for my needs.

Alas, under 14.04, installing Bumblebee only turned off the Nvidia card, without the ability to run it later using optirun. Also, the laptop would not suspend any more. Bummer.

After many hours of trying different Nvidia drivers and mucking with the Bumblebee configuration, I failed to find a way to get suspend to work.

Getting suspend to work with nvidia-prime

So I purged Bumblebee and the existing Nvidia drivers.

sudo ppa-purge ppa:bumblebee/stable
sudo apt-get purge 'bumblebee*'
sudo apt-get purge 'nvidia*'

Then tried the alternative that’s apparently officially supported in 14.04, nvidia-prime. All I needed was:

sudo apt-get install nvidia-331

On reboot, I was running under the Nvidia card, but the Intel controller was also correctly handling brightness controls. Suspend also worked. I went to the nvidia-settings panel to toggle the Nvidia card off, and logged out as requested to apply the change.

And then I was greeted by the “low-graphics mode” dialog, unable to get log back using only the Intel controller. As it turns out, it appears to be a race condition between the nvidia driver and lightdm, as logging into tty1 and restarting lightdm did the trick.

To make lightdm wait a bit longer on boot and on toggling, I added a sleep 2 just before the exec lightdm line in /etc/init/lightdm.conf.

Now the Nvidia card is turned off and can be turned on after logging out. More importantly, suspend worked correctly again. Though it now takes ~20 seconds to put the machine in sleep mode, I can live with this minor hassle.

Turning wifi on after resume

And then I wireless was turned off on resume. Toggling the physical switch did not help. Thankfully, the solution can easily be found by browsing the web.