Nvidia Optimus on Linux

Discussion in 'X org / Desktop' started by ryanvade, Aug 9, 2013.

  1. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    My history with Bumblebee and Optimus on Linux.
    I have been using Bumblebee with Optimus on my HP Dv6t-7000 CTO laptop since February 2013. My laptop has a Nvidia GT 630M that I use primarily for gaming on Windows 7. My first thought when I got this laptop was of course "How am I going to get my Nvidia card to work on Linux?". I spent a couple of months trying to figure this out. I first started using Arch to test Bumblebee, I could install different Kernels and test suites easier with Arch than any other distribution. Later Oz Unity Black Opal was tested on my system, but do to kernel issues (the default kernel for Black Opal is not supported on Intel CORE class processors) I upgraded to Diamond II-B when it was released. While I primarily game with Windows, Steam for Linux is running fine with Bumblebee on my laptop.

    What is Nvidia Optimus? Why do many Linux users not like it?

    Nvidia Optimus is an computer graphics hardware power/performance optimization technology created by Nvidia which, depending on the resource load generated by client software applications, will transparently and seamlessly switch between two graphics adapters within a computer system in order to provide either maximum performance or minimum power draw from the system's graphics rendering hardware. Specifically, Optimus is a particular implementation of what is commonly known as "switchable graphics" or, more generically, as GPU switching.


    What does all that mean? Well, with Nvidia Optimus you can choose when to use the more powerful and battery consuming Nvidia graphics card or to use the integrated power saving Intel or ATI graphics. This allows you to improve your battery life while also giving you access to more powerful graphics when needed. So why do many Linux users not like the idea of Nvidia Optimus? Because Nvidia has not released a driver for Linux that provides native Optimus support. Hence the need for this tutorial.

    What is this article for?
    The goal of this article is to show how easy it can be to setup Nvidia Optimus graphics on Linux systems. I want this tutorial to show not only how to automatically turn off the Nvidia graphics when the computer turns on but also how to put them to good use. I will try to include screenshots and sample files for everyone's convenience.

    What is Bumblee?
    Bumblebee is a effort to make Nvidia Optimus enabled laptops work in GNU/Linux systems. Such feature involves two graphics cards with two different power consumption profiles plugged in a layered way sharing a single framebuffer.

    The project has been fully rewritten in the C programming language, providing increased performance and reliability, mostly thanks to a new developer in the project, Jaron Viëtor (a.k.a. Thulinma). That bring the number of main developers to 4, the three other ones being Peter Wu (a.k.a. Lekensteyn), Joaquín Ignacio Aramendía (a.k.a. Samsagax) and Bruno Pagani (a.k.a. ArchangeGabriel). The most important new feature is automatic power management support. Yes, since Bumblebee 3.0 "Tumbleweed", you've got Power Management working out of the box, without any manual configuration needed. That's not the only one though, the full changelog could be found at http://bumblebee-project.org/release-notes-3.0
    More here: Bumblebee - NVIDIA Optimus support for Linux!
    How to install bumblebee? (Assuming that the Nvidia drivers are installed)
    I am assuming that you have installed the Nvidia Graphics drivers according to your distributions specific instructions. I would recommend using a driver of at least 319. I personally always use the very latest, this allows me to test how the latest drivers will work with Bumblebee. So at the time of this writing I am using nvidia-325 on Diamond II-B with the xorg edgers PPA. Also, it helps to have a newer Kernel. I would use at least kernel (at the time of this writing) 3.10 . I am using kernel 3.11-rc4 due to my wireless card.

    Ubuntu:
    Code:
    sudo add-apt-repository ppa:bumblebee/stable
    This adds the Bumblebee project's repository to your system.
    Code:
    sudo apt-get update && sudo apt-get install bumblebee virtualgl linux-headers-`uname -r` mesa-utils 
    This will update and install all the required packages for Bumblebee
    Code:
    sudo su -c "useradd -G bumblebee USERNAME"
    This will add your user to the bumblebee group which controls Bumblebee and the optimus card.


    Fedora 18:
    Code:
    su -c "yum install -y libbsd-devel libbsd glibc-devel libX11-devel help2man autoconf git tar glib2 glib2-devel kernel-devel kernel-headers automake gcc gtk2-devel VirtualGL VirtualGL.i686 "
    This will install all the dependencies.
    Code:
    su -c "yum -y --nogpgcheck install http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee-nonfree/fedora18/noarch/bumblebee-nonfree-release-1.0-1.noarch.rpm"
    This will actually install bumblebee.

    " 'bumblebee-nvidia' is both a rpm package and a shell script. The "bumblebee-nvidia" package contains the shell "wrapper" script, init scripts to run it at bootup, and a SELinux security policy, and lastly a copy of the NVidia Linux binary driver "blob" downloaded from NVidia's UNIX drivers page. This is why the packages are so large compared to the bumblebee package" (Nothing else needed for Fefora).
    Code:
    su -c  "yum install glibc-devel bumblebee-nvidia"
    This can install a special Bumblebee utilities, as described above, for your system.
    Code:
    su -c "useradd -G bumblebee USERNAME"
    This will add your user to the bumblebee group.



    Madriva:
    Code:
     urpmi bumblebee 
    This installs bumblee.
    Code:
    sudo su -c "useradd -G bumblebee USERNAME"
    This will add your user to the bumblebee group.
    Code:
    sudo su- c "systemctl enable bumblebeed.service"
    This makes sure bumblebee starts at boot time.

    Arch (intel/Nvidia)
    Arch has two varieties of Bumblebee. One for Intel/Nvidia and one for ATI/Nvidia. I am focusing on Intel/Nvidia.
    Code:
     sudo pacman -S intel-dri xf86-video-intel bumblebee bbswitch-dkms nvidia 
    This installs Bumblebee, the dependencies, and bbswitch in DKMS form.

    If you want to run 32-bit applications (like games with wine) on a 64-bit system you need the lib32-nvidia-utils package too.
    Code:
    sudo su -c "gpasswd -a $USER bumblebee"
    This will add your user to the bumblebee group.
    Code:
    sudo systemctl enable bumblebeed
    This makes sure bumblebee starts at boot time.

    Gentoo

    Code:
    su -c "layman -a mva" 
    This adds the appropriate repository.
    Code:
    su -c "emerge -j2 bumblebee"
    This installs Bumblebee
    Code:
    su -c "gpasswd -a $USER bumblebee"
    This will add your user to the bumblebee group.

    System dependent, for other systems:
    Build from Source

    At this point you should restart your computer and test to see if everything works. A basic test would be the following:
    Code:
     optirun -vvv glxspheres 
    Bumblebee-inuse.png
    If everything is working fine, you can continue to the section called "Install the Bumblebee Indicator"
    If you run into issues manual configuration may be needed.

    How to manually configure Bumblebee.
    ******* Check in /lib/nvidia-*
    The bumblee configuration file is located at /etc/bumblebee/bumblebee.conf. I am using Nano to edit the file:

    Code:
    sudo nano /etc/bumblebee/bumblebee.conf 
    - on line 22, make sure "Driver=" is set to "nvidia", like this:
    Code:
    Driver=nvidia
    This will make sure the Nvidia driver is used when Bumblebee is on.

    - change the "KernelDriver=" (on line 47) to "nvidia-*", for example:
    Code:
    KernelDriver=nvidia-325
    This is used to make sure the correct driver is used. For this example, I installed nvidia-325 with apt-get so I am using nvidia-325 for the driver version.

    - change "LibraryPath=" (on line 51) to "/usr/lib/nvidia-325:/usr/lib32/nvidia-325", so it looks like this:
    Code:
    LibraryPath=/usr/lib/nvidia-325:/usr/lib32/nvidia-325
    Bumblebee has to know where the Nvidia library is located. This also depends on the distribution and driver name. I am using my driver name as an example.

    - change the "XorgModulePath=" (line 54) to "XorgModulePath=/usr/lib/nvidia-325-/xorg,/usr/lib/xorg/modules" so it looks like this:
    Code:
    XorgModulePath=/usr/lib/nvidia-325/xorg,/usr/lib/xorg/modules
    This tells Bumblebee where the Xorg server module is located.

    How to configure the Nvidia Xorg settings.
    The Xorg configuration for Bumblebee is different than the default configuration for the Intel graphics. Again I am using Nano to edit the file.
    Code:
     sudo nano /etc/bumblebee/xorg.conf.nvidia
    This part can be very tricky. You will want to make sure the following is in the correct sections:

    Code:
     Section "ServerLayout"
    Identifier "Layout0"
    Option "AutoAddDevices" "true"
    Option "AutoAddGPU" "false"
    EndSection
    Section "Device"
    Identifier "DiscreteNvidia"
    Driver "nvidia"
    VendorName "NVIDIA Corporation"
    Option "ProbeAllGpus" "false"
    BusID "PCI:01:00:0"
    Option "NoLogo" "false"
    Option "UseEDID" "true"
    Option "UseDisplayDevice" "none"
    Option "ConnectedMonitor" "DFP"
    EndSection
    
    The most important part of this section is the "BusID". The BusID is the physical Bus location that the Nvidia card is located. Bumblebee may need to know its location so it can properly start and stop it. The BusID can be discovered using the following command:
    Code:
    lspci | grep NVIDIA
    The command should give output similar to this:
    Code:
    01:00.0 VGA compatible controller: NVIDIA Corporation GF108M [GeForce GT 630M] (rev a1)
    The "01:00.0" is the BusID and should be placed in the BusID option.

    With the configuration done reboot the system and try to test Bumblebee again. Another examle of how to test Bumblebee (mesa-utils must be installed for this test)
    Code:
    optirun -vvv glxgears
    How to use Bumblebee.
    I have given multiple examples of how to use Bumblebee but I am going to talk about it a bit more. The command to run a program with the Nvidia card is optirun. This command enables Bumblebee, and runs the command with the Nvidia card. Which means that the Nvidia card is "Woken up". When you stop the program the Nvidia card is "Put to sleep" and Bumblebee is turned off.

    If you need to setup the Nvidia driver settings, like you would on a normal Nvidia card, you can use the bellow command:
    Code:
    optirun -b none nvidia-settings -c :8
    To explain this command, the -b stands for:
    Code:
    -b, --bridge METHOD
      acceleration/displaying  bridge  to  use.  Valid  values  are  auto,  virtualgl  and  primus. The --vgl-* options only make sense when using the virtualgl bridge, while the
      --primus-* options apply only when using the primus bridge.  Additionally, value none is recognized, and its effect is to add paths to driver libraries  to  LD_LIBRARY_PATH
      (useful for nvidia-settings and CUDA applications)
    the -c means:
    Code:
    -c, --vgl-compress METHOD
      image  compression or transport to use with VirtualGL. Valid values for METHOD are proxy, jpeg, rgb, xv and yuv. Changing this setting may affect performance, CPU usage and
      image quality 
    and the :8 says which server to use.
    Bumblebee-nvidia-settings.png

    How to install the Bumblebee Indicator.
    The Bumblebee indicator is a graphical control system for Bumblebee as well as an applet which can tell you if Bumblebee is in use. To install the indicator, please make sure git is installed.
    Code:
    git clone https://github.com/Bumblebee-Project/bumblebee-ui.git && cd bumblebee-ui
    This downloads the Indicator and moves the working directory to the indicator source directory.
    Code:
     cd icons && cp ./*.svg ~/.icons 
    If ~/.icons does not exist
    Code:
    mkdir ~/.icons 
    then rerun the cp ./*.svg ~/.icons
    Code:
    cd ..
    Code:
     chmod +x ./INSTALL
    This makes sure the install script is executable.
    Code:
    sudo ./INSTALL
    This command will start the install script.
    To start the indicator, run the following command:
    Code:
    /usr/local/bin/bumblebee-indicator
    The install script should also place launchers and icons for use. The .desktop files should be in the /usr/share/applications/ folder.
    If you want to have the indicator running at startup, which is highly recommended, place the full location to the indicator in a desktop startup application. For example in Starup Applications in Unity.

    When the Bumblebee indicator is running, you should see an applet in your Desktop Environment "task bar". This applet can tell you if Bumblebee is running and can be used to start certain programs with Bumblebee enabled.

    How to configure the Bumblebee Indicator.
    With the Bumblebee indicator running, right click the applet and click "Configure apps".
    Bumblebee-configuration.png
    A window will open with a list of Programs that have .desktop files. Check any programs you want Bumblebee to run with and click Apply. If you wish to adjust advanced settings for the selected applications click the "Configure applications" tab. Once you are done, close the window and right click the applet again. Now in the "Preferred Apps" menu a list of applications appears. If you click on any of those applications from THAT menu, it will be started with the Nvidia card. You should also get an indication that Bumblebee is in use.
    Bumblebee-programs.png


    ryanvade....

    Attached Files:

    • slide.jpg
      slide.jpg
      File size:
      69.3 KB
      Views:
      104,436
    Last edited: Sep 17, 2013
    Rob and DevynCJohnson like this.
  2. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    184
    Trophy Points:
    43
    ryanvade likes this.
  3. publicanpete

    publicanpete New Member

    Messages:
    1
    Likes Received:
    2
    Trophy Points:
    3
    I can't thank you enough...I have been put off moving to Linux for years as support for hi end laptops seemed vague at best. I have finally made the switch from windows as windows 8 was the final straw for me - You have helped a frustrated newbie move a step closer to enlightenment - Thank you

    One point I can't get right is I followed your instructions to get Bumblebee to load on startup however this doesn't appear to work - any suggestions would be helpfull
    Last edited: Sep 16, 2013
    ryanvade and Rob like this.
  4. flunwyc

    flunwyc Member

    Messages:
    99
    Likes Received:
    60
    Trophy Points:
    18
    ryanvade and Rob like this.
  5. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    It seems that when trying to get the Bumblebee indicator to load at startup it is unable to load the icon for it...so you do not see it. To fix this copy the bumblebee.svg icons in bumblebee-ui/icons to ~/.icons

    So,
    Code:
    cd /path/to/bumblebee-ui
    Code:
    cd icons && cp ./*.svg ~/.icons
    logout/login and start the bumblebee indicator.
    publicanpete likes this.
  6. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    Currently testing nvidia-331 on kernel 3.11.3...
    nvidia-313-optirun.png
    Last edited: Oct 6, 2013
    DevynCJohnson likes this.
  7. Ciprian Tomoiaga

    Ciprian Tomoiaga New Member

    Messages:
    1
    Likes Received:
    1
    Trophy Points:
    3
    Hi! Great article. Bumblebee is doing great at automatically switching my NVidia GPU.

    However, I encounter a small problem: I cannot connect any external display on the HDMI port, which is linked to NVidia. Do you know any good solution to that?

    Many thanks for your efforts!
    ryanvade likes this.
  8. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    Glad bumblebee is (mostly) working well for you. My laptop uses the Intel graphics when I connect anything to the HDMI. Not sure why... I am unsure what could cause the HDMI to not work. Maybe this line is causing the issue:
    Option "ConnectedMonitor" "DFP"
    Another option may be to use XRANDR to setup another view mode. Something like this maybe?

    Code:
        #!/bin/bash
    
        # V-1.0 by Hanynowsky - April 2012.
        # I am a very basic script that works around bug 874241 repprted in launchpad.
    
        XCOM0=`xrandr -q | grep 'HDMI1 connected'`
        XCOM1=`xrandr --output HDMI1 --primary --mode 1920x1080 --output LVDS1 --mode 1366x768 --below HDMI1`
        XCOM2=`xrandr --output LVDS1 --mode 1366x768`
        # if the external monitor is connected, then we tell XRANDR to set up an extended desktop
        if [ -n "$XCOM0" ] || [ ! "$XCOM0" = "" ]; then echo $XCOM1
        # if the external monitor is disconnected, then we tell XRANDR to output only to the laptop screen
        else echo $XCOM2
        fi
        exit 0;
    Maybe this page:
    https://github.com/Bumblebee-Project/Bumblebee/wiki/Multi-monitor-setup

    I would ask the Bumblebee developers. This is even more technical than what I can handle.

  9. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    22K+ views. Wow. Thanks everyone. :D
    Next article will be out soon. And it will be a fun one. :rolleyes:

    EDIT: this article has almost 48K+ views. WOAH.
    Last edited: Jun 12, 2014
    Rob likes this.
  10. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    184
    Trophy Points:
    43
    You mean 47k views ;)
    ryanvade likes this.
  11. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    where does it say 47K? I have only seen 22K.
  12. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    184
    Trophy Points:
    43
    ryanvade likes this.
  13. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
  14. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,139
    Likes Received:
    385
    Trophy Points:
    83
    Still works with 14.04 LTS. Even better with steam: (using primus libraries)
    bumblebee_1404.png

Share This Page