As the title, how can I correctly setup nvidia-optimus technology on Ubuntu?
NB: this post is the result of many days spent reading various stuffs on the web, so take it at your own risk. It was tested on Ubuntu 12.04/12.10/13.04/13.10/14.04 (all 64bit) with nVidia GT650M graphic card. Feel free to add comments and suggestions
Install nVidia and bumblebee
1. First of all, we have to delete all the video drivers on the computer:
sudo apt-get remove --purge nvidia*
Then bumblebee in case if you have installed it previously:
sudo apt-get remove --purge bumblebee*
We have also to delete all the nouveau driver with:
sudo apt-get --purge remove xserver-xorg-video-nouveau
To be sure to have deleted the whole stuffs, try to type
dpkg -l | grep nvidia and
dpkg -l | grep bumblebee: it shouldn't return anything. For
dpkg -l | grep nouveau it is likely that it returns some lines saying
libdrm-nouveauXXXXX; for now, just ignore them.
2. Then, we have to assure to have all the headers typing:
sudo apt-get install linux-source && sudo apt-get install linux-headers-$(uname -r)
3. The next thing to do is to blacklist the remaining nouveau drivers and some other packages that could cause problems:
sudo cp /etc/modprobe.d/blacklist.conf /etc/modprobe.d/blacklist.conf.bak sudo gedit /etc/modprobe.d/blacklist.conf
Adding the following lines at the end of file:
# Necessary to install nvidia drivers blacklist nouveau blacklist lbm-nouveau blacklist nvidia-173 blacklist nvidia-96 blacklist nvidia-current blacklist nvidia-173-updates blacklist nvidia-96-updates alias nvidia nvidia_current_updates alias nouveau off alias lbm-nouveau off options nouveau modeset=0
Just save and exit.
4. Now, run the best knows ubuntu commands
sudo apt-get update && sudo apt-get dist-upgrade -y
5. From now, we works on tty. Open the tty1 console with CTRL+ALT+F1 and login with your username and password. Then execute:
sudo service lightdm stop
Now we will install the drivers. Execute:
sudo apt-get install nvidia-XXX-updates nvidia-settings
where XXX is the latest stable drivers. I'm using the 331 drivers, but I've read somewhere that the 343 are available to download (don't know if they are stable).
N.B: With the latest driver versions, it also install
nvidia-prime by default. This technology is intended to automatically switch between Intel and nVidia graphic card without user intervention. To do this, it leaves both the cards turned on. Optimus, on the other hand, turn on the nVidia graphic card only with explicit user request; it translates in significantly less power consumption respect to prime.
I personally prefer optimus over prime, but if you don't bother on the enormous waste of energy, stop here. Otherwise, you have two options:
completely delete prime (
sudo apt-get remove --purge nvidia-prime);
leave prime there; in section "Prime with optimus" we will see how to make optirun work also with prime installed
6. Now, we have to install bumblebee and the virtualgl packages with
sudo apt-get install bumblebee bumblebee-nvidia virtualgl virtualgl-libs virtualgl-libs-ia32:i386 virtualgl-libs:i386
Then, we have to add our user in the bumblebee group with:
sudo usermod -a -G bumblebee $USER
And then reboot the pc.
7. Login on your user account, open a new terminal window and type:
cd /etc/bumblebee ls -Al
Among the various listed files, there should be two in particular:
xorg.nvidia.conf. Let's make a backup copy of both with:
sudo cp FILE_NAME FILE_NAME.bak
You should replace FILE_NAME with the actual name of the file. Then, let's go to modify the first file with
sudo gedit bumblebee.conf, adding (all without quotes)
- [bumblebeed] section: after "Driver=" insert "nvidia"
- [nvidia-driver] section: after "KernelDriver=" insert "nvidia-XXX-updates"
- [nvidia-driver] section: after "LibraryPath=" insert "/usr/lib/nvidia-XXX-updates, /usr/lib/nvidia-331-updates:/usr/lib32/nvidia-XXX-updates"
- [nvidia-driver] section: after "XorgModulePath=" insert "/usr/lib/nvidia-XXX-updates/xorg,/usr/lib/xorg/modules"
Assure that the "XorgConfFile" under [nvidia-driver] is equal to "/etc/bumblebee/xorg.conf.nvidia" (again, without quotes), then save and close gedit.
Now we have to edit the other file with
sudo gedit xorg.conf.nvidia (in this case we have to insert the quotes also!!). Replace
Option "ConnectedMonitor" "DFP" with
Option "UseDisplayDevice" "none", save and exit.
gedit /etc/modprobe.d/bumblebee.conf and make sure that all the lines containing
blacklist <something> are not commented (i.e. they don't start with
9. At this point, run the following command
sudo service bumblebeed start
If it returns an error, try to run again the command with restart rather than start. If you have still errors, something like:
restart: Unknown job: bumblebeed
It's probably something wrong in the bumblebee.conf file; so, recheck step 7.
If instead the result is similar to:
bumblebeed start/running, process XXXXX
You're soon done setting up bumblebee!
Now we can simply run
optirun glxspheres or
optirun glxspheres64. If all work as expected, you have an output like this:
$ optirun glxspheres64 Polygons in scene: 62464 Visual ID of window: 0x20 Context is Direct OpenGL Renderer: GeForce GT 650M/PCIe/SSE2 182.253407 frames/sec - 203.394802 Mpixels/sec 182.940725 frames/sec - 204.161849 Mpixels/sec ....
To double-check that we are actually using nvidia-drivers, open another terminal while
optirun <application> is running, then type
sudo lshw -c display | grep driver. The result should be something like that.
configuration: driver=nvidia latency=0 configuration: driver=i915 latency=0
If, on the other hand, you close all the application started with
optirun it should show only the intel driver. That's it!!
Install Bumblebee UI
Thanks to this answer from Pavak Paul, here is the instructions to add the bumblebee user interface on Ubuntu 14.04 to manage apps to be opened using nVidia.
1. Install Python App Indicator:
sudo apt-get install python-appindicator
2. Install Git:
sudo apt-get install git
3. Make a directory for git:
mkdir git && cd git
4. Check out the repository:
git clone https://github.com/Bumblebee-Project/bumblebee-ui.git cd bumblebee-ui sudo ./INSTALL
Go to Startup Applications and add bumblebee-indicator [click on Add, then insert the Name and comment that you want; insert
bumblebee-indicator in the command box and click on Add).
Prime with optimus
If you want to have the option to also use
nvidia-prime sometimes, try to follow the instructions below.
bumblebeed from starting at boot-time, execute:
echo "manual" | sudo tee /etc/init/bumblebeed.override
2. This point is the most problematic; it prevents bumblebee to blacklist nVidia drivers and should result in graphic session freeze. Try it at your own risk! Run:
sudo gedit /etc/modprobe.d/bumblebee.conf
And comment the line containing your nVidia XXX drivers. It should result in something like that.
# XXX #blacklist nvidia-XXX #blacklist nvidia-XXX-updates blacklist nvidia-experimental-XXX
Reboot the system and launch
nvidia-settings. The final situation is this:
If you select "Intel (Power save)" in nvidia-settings, you have only the Intel graphic card turned on by default. You still have to run an application with
optirun to use the nVidia graphic card
sudo service bumblebeed start optirun <application>
If instead you want to use the "Nvidia (Performance)" profile, select it from nvidia-settings, then login/logout and all should work automatically. The only thing is that you don't have to launch
bumblebeed daemon with this profile selected because it could cause troubles.
In case you have problems:
If you want to use only
sudo apt-get --purge remove bumblebee*
2. If you want to use only optimus without removing nvidia-prime, edit again the previous file:
sudo gedit /etc/modprobe.d/bumblebee.conf
Uncommenting (removing the # character) from the lines previously modified:
# XXX blacklist nvidia-XXX blacklist nvidia-XXX-updates blacklist nvidia-experimental-XXX
And rebooting. In this case, you can leave bumblebeed run at boot-time:
sudo rm /etc/init/bumbebeed.override