Hemen's Notepad2017-02-24T13:47:34+05:30https://hemenkapadia.github.ioHemen Kapadiahemen.kapadia@gmail.comNvidia, CUDA and Bumblebee with Linux (Ubuntu) on Optimus laptop2016-11-11T00:00:00+05:30https://hemenkapadia.github.io/blog/2016/11/11/Ubuntu-with-Nvidia-CUDA-Bumblebee<p>In this guide, I list the procedure to get proprietary <a href="http://www.nvidia.com/Download/index.aspx?lang=en-us">Nvidia driver</a>, <a href="https://developer.nvidia.com/cuda-zone">CUDA</a> and <a href="https://wiki.archlinux.org/index.php/bumblebee">Bumblebee</a> working on <a href="http://www.dell.com/en-us/shop/productdetails/inspiron-15-7559-laptop/dncwpw5722b">Dell 7559</a>.</p>
<p>My aim is to get the benefits of power management provided by <a href="http://www.nvidia.com/object/optimus_technology.html">Optimus</a> technology at the same time having the flexibility to use the Nvidia GPU features on demand without requiring to logout/login each time a GPU change is needed. In this configuration, integrated Intel GPU will be the primary display driver and Nvidia GPU will be powered up on need basis.</p>
<p>This guide is opinionated and much of the choices I make are based on my requirements below</p>
<ol>
<li>Stability over cutting edge features.</li>
<li>Ubuntu LTS version supported for next couple years.</li>
<li>System update should be seamless using <code class="highlighter-rouge">apt-get upgrade</code></li>
<li>System updates should not break the system, mainly the Xserver and CUDA install.</li>
<li>Use Proprietary Nvidia drivers.</li>
<li>Integrated Intel GPU to be primary display driver.</li>
<li>Nvidia GPU switched off by default.</li>
<li>Power up Nvidia GPU on demand, without requiring and configuration changes, logout or restarts.</li>
</ol>
<h3 id="select-ubuntu-version">Select Ubuntu version</h3>
<p>These steps are confirmed to work with <a href="https://wiki.ubuntu.com/TrustyTahr/ReleaseNotes/14.04.4#Updated_Packages">kernel v4.2</a>. I was not able to get this working on any other kernel, Xserver combination or LTS version other than <a href="https://wiki.ubuntu.com/TrustyTahr/ReleaseNotes/14.04.4">LTS 14.04.4</a>.</p>
<p><a href="http://old-releases.ubuntu.com/releases/14.04.4/">Download Ubuntu LTS 14.04.4</a> iso and <a href="https://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows">create a bootable USB</a>.</p>
<h3 id="install-ubuntu">Install Ubuntu</h3>
<p>You can follow the <a href="http://www.everydaylinuxuser.com/2013/09/install-ubuntu-linux-alongside-windows.html">guide to install Windows and Ubuntu in dual boot mode</a>. Make note of the below points and the GRUB settings discussed in the next section before you start the installation.</p>
<blockquote>
<p>Ensure point 4 <em>Tun OFF Fastboot (in Windows) and disable Secure boot (in BIOS)</em> is completed exactly as mentioned.</p>
</blockquote>
<p>I had disabled Secure Boot in BIOS, but did not disable Fastboot in Windows. As a result I was having a hard time installing 14.04, and the installer would fail each time with the error <code class="highlighter-rouge">grub-efi-amd64-signed failed to install into /target/. Without GRUB boot loader, the installed system will not boot</code>.</p>
<blockquote>
<p>During installation I did not connect to the network/internet. This was to prevent any unwanted kernel or Xserver updates during installation.</p>
</blockquote>
<blockquote>
<p>Additionally, I selected the option to install third party software.</p>
</blockquote>
<h3 id="grub-settings-for-ubuntu-live-usb">GRUB settings for Ubuntu Live USB</h3>
<p>When you boot from the live USB, you will be presented with the GRUB screen allowing you to try Ubuntu before installing.</p>
<p>Select the <code class="highlighter-rouge">Install Ubuntu</code> option and press <code class="highlighter-rouge">e</code> which will open the menu edit screen. Add the following kernel parameters just before <code class="highlighter-rouge">quiet splash</code> in the line that starts with <code class="highlighter-rouge">linux /boot/vmlinuz-linux .....</code></p>
<div class="highlighter-rouge"><pre class="highlight"><code>nomodeset i915.modeset=1
</code></pre>
</div>
<p>Press <code class="highlighter-rouge">F10</code> and complete the installation as per <a href="http://www.everydaylinuxuser.com/2013/09/install-ubuntu-linux-alongside-windows.html">guide to install Windows and Ubuntu in dual boot mode</a></p>
<p>Once the installation is complete, you will be presented with the GRUB menu, follow the above procedure to edit the kernel parameters and boot into Ubuntu. Next we will make these kernel parameters persistent.</p>
<h3 id="persist-grub-settings">Persist GRUB settings</h3>
<p>To avoid updating the kernel options each time the system is booted, update below GRUB settings using <code class="highlighter-rouge">sudo vi /etc/default/grub</code></p>
<div class="highlighter-rouge"><pre class="highlight"><code>GRUB_CMDLINE_LINUX_DEFAULT="nomodeset i915.modeset=1 quiet splash"
</code></pre>
</div>
<p>Optionally, for High DPI or Retina displays, GRUB boot menu options are not readable as the font size is too small. It can be fixed by the below two options</p>
<div class="highlighter-rouge"><pre class="highlight"><code>GRUB_GFXMODE=1280x1024
GRUB_GFXPAYLOAD_LINUX=keep
</code></pre>
</div>
<p>Optionally, set Windows as the default system to boot</p>
<div class="highlighter-rouge"><pre class="highlight"><code>GRUB_DEFAULT="Windows Boot Manager (on /dev/sda1)"
</code></pre>
</div>
<blockquote>
<p>Above label is specific to my laptop, replace accordingly with the Windows label for your system.</p>
</blockquote>
<p>Update GRUB with these modified settings using the command <code class="highlighter-rouge">sudo update-grub2</code></p>
<h3 id="upgrade-the-system">Upgrade the system</h3>
<p>During installation we did not connect the system to internet. This is the time to update the system. Setup the internet connection.</p>
<p>We will select the best Ubuntu update server based on our location,</p>
<ul>
<li>Select Software and Updates.</li>
<li>In the tab “Ubuntu Software” select Other in the dropdown for Download Server.</li>
<li>Select your country name and then select best server.</li>
<li>Select the server identified as best and close.</li>
</ul>
<p>With the best Ubuntu update server selected, open a terminal and enter the below commands to update the system</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get autoremove
</code></pre>
</div>
<blockquote>
<p>In the upgrade step, when prompted to select the GRUB file, select to keep the local version currently installed.</p>
</blockquote>
<h3 id="optional---highdpi-settings">Optional - HighDPI settings</h3>
<p>This is an optional step, but highly recommended if you have a HighDPI or Retina display. Apply the HighDPI configuration discussed in <a href="/blog/2016/05/06/Configuring-Ubuntu-for-highDPI-and-Retina-displays.html">Configuring Ubuntu for HighDPI and Retina displays</a></p>
<h3 id="restart-and-test">Restart and Test</h3>
<p>Restart the machine and test that it is working as expected, especially the Xserver and graphical display.</p>
<h3 id="remove-nvidia-and-nouveau-and-disable-services">Remove Nvidia and Nouveau, and disable services</h3>
<p>Now we start the process to get Nvidia drivers installed on the system, but before we do that, we need to remove all possible conflicting drivers</p>
<p>Switch to Virtual Console (Atl + Ctrl + F1). You can have 6 virtual consoles F1 to F6.</p>
<p>Stop the Xserver and remove any existing installs of Nvidia, nouveau etc.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo service lightdm stop
sudo apt-get remove --purge nvidia*
sudo apt-get remove --purge bumblebee*
sudo apt-get --purge remove xserver-xorg-video-nouveau*
</code></pre>
</div>
<p>Blacklist nouveau, add the following lines to <code class="highlighter-rouge">/etc/modprobe.d/blacklist.conf</code></p>
<div class="highlighter-rouge"><pre class="highlight"><code># Blacklisting nouveau to get nvidia running with bumblebee
blacklist nouveau
blacklist lbm-nouveau
alias nouveau off
alias lbm-nouveau off
options nouveau modeset=0
</code></pre>
</div>
<p>Disable gpu-manager.service, as it has a tendency to overwrite xorg.conf and result in black screen on boot.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo vi /etc/init/gpu-manager.conf
# Comment these start on settings ; GPU Manager ruins our work
#start on (starting lightdm
# or starting kdm
# or starting xdm
# or starting lxdm)
task
exec gpu-manager --log /var/log/gpu-manager.log
</code></pre>
</div>
<p>Create initramfs <code class="highlighter-rouge">sudo update-initramfs -u -k all</code></p>
<h3 id="restart-and-test-1">Restart and Test</h3>
<p>Reboot the system and ensure that xserver is running fine - i.e. GUI is working properly</p>
<p>Verify that nouveau is successfully blacklisted. The command <code class="highlighter-rouge">lsmod | grep nouveau</code> should not return any lines with the word nouveau in it.</p>
<p>Ensure gpu-manager.service is disabled <code class="highlighter-rouge">sudo service gpu-manager status</code>. If not, disable as mentioned above.</p>
<h3 id="download-cuda-toolkit">Download CUDA toolkit</h3>
<p>We will install Nvidia drivers as part of the CUDA toolkit installation.</p>
<p>From <a href="https://developer.nvidia.com/cuda-downloads">CUDA Toolkit download</a> page, download the <code class="highlighter-rouge">deb(network)</code> file for Linux, x86_64, Ubuntu, 14.04 to your <code class="highlighter-rouge">$HOME</code> directory. The filename, as of this writing, is <code class="highlighter-rouge">cuda-repo-ubuntu1404_8.0.44-1_amd64.deb</code>.</p>
<h3 id="install-cuda-toolkit-and-nvidia-drivers">Install CUDA toolkit and Nvidia drivers</h3>
<p>CUDA Toolkit installation can be done by installing any of the <a href="http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#package-manager-metas">CUDA Toolkit Meta Packages</a>.</p>
<p>We will install the <code class="highlighter-rouge">cuda-8-0</code> meta package to install both the CUDA Toolkit and the Nvidia driver and ensure that they will need to be explicitly upgraded when needed. The <code class="highlighter-rouge">cuda</code> meta package can get updated as part of system upgrade and may break our working Xserver and other configuration, which we do not want.</p>
<p>The below steps are to be performed in Virtual Console (Ctrl + Alt + F1), as it requires stopping the graphical interface.</p>
<p>Switch to Virtual Console and disable lightdm. <code class="highlighter-rouge">sudo service lightdm stop</code></p>
<p>Now we install CUDA toolkit</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-get install linux-headers-$(uname -r)
sudo apt-get install mesa-utils
sudo dpkg -i $HOME/cuda-repo-ubuntu1404_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda-8-0
sudo apt-get autoremove
</code></pre>
</div>
<p>In <code class="highlighter-rouge">autoremove</code> step a whole lot of needless xservers are removed. Ensure <code class="highlighter-rouge">xserver-xorg-video-intel-lts-wiley</code> is in the list.</p>
<h3 id="restart-and-test-2">Restart and Test</h3>
<p>Reboot the system and ensure that xserver is running fine - i.e. GUI is working properly</p>
<blockquote>
<p>Caveat - At this step, the first time I restart the machine, lightdm login screen appeared twice. After the second login, I was at the desktop screen. I restarted the machine once again. That resolved the issue.</p>
</blockquote>
<p>Ensure lsmod shows both nvidia and i915 drivers loaded in the kernel.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ lsmod | grep nvidia
nvidia_uvm 729088 0
nvidia_modeset 749568 2
nvidia 10223616 64 nvidia_modeset,nvidia_uvm
drm 360448 8 i915,drm_kms_helper,nvidia
hemen@hemen-Inspiron-7559:~$ lsmod | grep i915
i915 1130496 3
drm_kms_helper 126976 1 i915
drm 360448 8 i915,drm_kms_helper,nvidia
i2c_algo_bit 16384 1 i915
video 40960 3 i915,dell_wmi,dell_laptop
hemen@hemen-Inspiron-7559:~$ glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 960M/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 361.93.02
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 361.93.02
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
hemen@hemen-Inspiron-7559:~$ glxgears -info
Running synchronized to the vertical refresh. The framerate should be
approximately the same as the monitor refresh rate.
GL_RENDERER = GeForce GTX 960M/PCIe/SSE2
GL_VERSION = 4.5.0 NVIDIA 361.93.02
GL_VENDOR = NVIDIA Corporation
GL_EXTENSIONS = .... DELETED LOT OF TEXT HERE ...
67692 frames in 5.0 seconds = 13537.328 FPS
68586 frames in 5.0 seconds = 13717.179 FPS
69667 frames in 5.0 seconds = 13932.193 FPS
69390 frames in 5.0 seconds = 13877.986 FPS
hemen@hemen-Inspiron-7559:~$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 361.93.02 Wed Sep 21 16:32:29 PDT 2016
GCC version: gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
hemen@hemen-Inspiron-7559:~$ ls -l /dev/nvi*
crw-rw-rw- 1 root root 195, 0 Oct 4 22:23 /dev/nvidia0
crw-rw-rw- 1 root root 195, 255 Oct 4 22:23 /dev/nvidiactl
crw-rw-rw- 1 root root 195, 254 Oct 4 22:23 /dev/nvidia-modeset
crw-rw-rw- 1 root root 244, 0 Oct 4 22:23 /dev/nvidia-uvm
hemen@hemen-Inspiron-7559:~$
</code></pre>
</div>
<p>At this step we have ensured that Nvidia and i915 drivers can both coexist in the kernel. This is an important checkpoint to ensure that we are on the right track so far. The output of <code class="highlighter-rouge">glxinfo</code> shows that Nvidia is currently the main display driver.</p>
<h3 id="install-bumblebee">Install Bumblebee</h3>
<p>Next we install <a href="https://wiki.archlinux.org/index.php/bumblebee">Bumblebee</a> to get the ability to power up Nvidia GPU on demand basis. We will also set Intel as the primary display driver and ensure the Nvidia GPU is powered OFF by default.</p>
<blockquote>
<p>All steps below need to be performed in Virtual Console, and Xserver should not be running. Perfom all the steps in one shot, till you reach the restart and test step below.</p>
</blockquote>
<p>Switch to virtual console <code class="highlighter-rouge">(Alt + Ctrl + F1)</code> and stop lightdm.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo service lightdm stop
sudo apt-get install --no-install-recommends bumblebee
sudo apt-get install bumblebee-nvidia primus
</code></pre>
</div>
<h3 id="bumblebee-configuration">Bumblebee configuration</h3>
<p>Add the following two lines to <code class="highlighter-rouge">/etc/modules</code></p>
<div class="highlighter-rouge"><pre class="highlight"><code>i915
bbswitch
</code></pre>
</div>
<p>Create a softlink <code class="highlighter-rouge">/etc/modules-load.d/modules.conf</code> to <code class="highlighter-rouge">/etc/modules</code></p>
<div class="highlighter-rouge"><pre class="highlight"><code>cd /etc/modules-load.d
sudo ln -s ../modules modules.conf
</code></pre>
</div>
<p>Blacklist nvidia from loading, its insertion and removal from the kernel will be handled by <a href="https://github.com/Bumblebee-Project/bbswitch">bbswitch</a>. Add the following lines to <code class="highlighter-rouge">/etc/modprobe.d/bumblebee.conf</code>.</p>
<div class="highlighter-rouge"><pre class="highlight"><code># 361
blacklist nvidia-361
blacklist nvidia-361-updates
blacklist nvidia-experimental-361
blacklist nvidia_361
blacklist nvidia_361_uvm
blacklist nvidia_361_modeset
alias nvidia nvidia_361
alias nvidia-uvm nvidia_361_uvm
alias nvidia-modeset nvidia_361_modeset
</code></pre>
</div>
<p>The value of BusID to be used in the below configuration files may be different on your system. You can get those details using <code class="highlighter-rouge">lspci</code> command. Make note of the numbers to the extreme left for both Intel and Nvidia controllers.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>lspci | egrep -i "VGA|3D"
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
02:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 960M] (rev ff)
</code></pre>
</div>
<p>Update Bumblebee and Xserver configuration files as shown below</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo vi /etc/bumblebee/bumblebee.conf
## Configuration file for Bumblebee. Values should **not** be put between quotes
[bumblebeed]
VirtualDisplay=:8
KeepUnusedXServer=false
ServerGroup=bumblebee
TurnCardOffAtExit=false
NoEcoModeOverride=false
Driver=nvidia
XorgConfDir=/etc/bumblebee/xorg.conf.d
## Client options. Will take effect on the next optirun executed.
[optirun]
Bridge=primus
VGLTransport=proxy
PrimusLibraryPath=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
AllowFallbackToIGC=false
## Section with nvidia driver specific options, only parsed if Driver=nvidia
[driver-nvidia]
KernelDriver=nvidia_361
PMMethod=bbswitch
LibraryPath=/usr/lib/nvidia-361:/usr/lib32/nvidia-361
XorgModulePath=/usr/lib/nvidia-361/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia
## Section with nouveau driver specific options, only parsed if Driver=nouveau
# [driver-nouveau]
# KernelDriver=nouveau
# PMMethod=auto
# XorgConfFile=/etc/bumblebee/xorg.conf.nouveau
</code></pre>
</div>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo vi /etc/bumblebee/xorg.conf.nvidia
Section "ServerLayout"
Identifier "Layout0"
Option "AutoAddDevices" "false"
Option "AutoAddGPU" "false"
EndSection
Section "Device"
Identifier "DiscreteNvidia"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:02:00:0"
Option "ProbeAllGpus" "false"
Option "NoLogo" "true"
Option "UseEDID" "false"
Option "UseDisplayDevice" "none"
EndSection
</code></pre>
</div>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo vi /etc/X11/xorg.conf
Section "ServerLayout"
Identifier "layout"
Screen 0 "intel"
Inactive "nvidia"
EndSection
Section "Device"
Identifier "intel"
Driver "intel"
BusID "PCI:00:02:0"
Option "AccelMethod" "SNA"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:02:00:0"
Option "ConstrainCursor" "off"
EndSection
Section "Screen"
Identifier "nvidia"
Device "nvidia"
Option "AllowEmptyInitialConfiguration" "on"
Option "IgnoreDisplayDevices" "CRT"
EndSection
</code></pre>
</div>
<h3 id="update-alternatives">Update alternatives</h3>
<p>Update alternatives to ensure proper library paths are configured.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo update-alternatives --config x86_64-linux-gnu_gl_conf
There are 3 choices for the alternative x86_64-linux-gnu_gl_conf (providing /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/nvidia-361/ld.so.conf 8604 auto mode
1 /usr/lib/nvidia-361-prime/ld.so.conf 8603 manual mode
2 /usr/lib/nvidia-361/ld.so.conf 8604 manual mode
* 3 /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf 500 manual mode
Press enter to keep the current choice[*], or type selection number:
</code></pre>
</div>
<p>Select the mesa option where available, if not available, keep existing setting.</p>
<p>As done above for <code class="highlighter-rouge">x86_64-linux-gnu_gl_conf</code> update alternatives for below settings. For the i386 options we do not have mesa showing in the list. So keep as is to <code class="highlighter-rouge">/usr/lib/nvidia-361/alt_ld.so.conf</code></p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo update-alternatives --config x86_64-linux-gnu_egl_conf
sudo update-alternatives --config i386-linux-gnu_gl_conf
sudo update-alternatives --config i386-linux-gnu_egl_conf
sync
sudo ldconfig
</code></pre>
</div>
<p>Perform required miscellaneous tasks by executing the commands mentioned below</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo update-initramfs -u -k all
sudo usermod -a -G bumblebee $USER
sudo apt-get remove nvidia-prime
</code></pre>
</div>
<p>That’s it. You are done with all the required configurations. Now we will test if everything is working as expected.</p>
<h3 id="restart-and-test-3">Restart and Test</h3>
<p>Restart the machine and ensure that the Xserver / graphical display is working correctly.</p>
<p>Check GPU modules loaded into the kernel. Nvidia should not be loaded, <a href="https://wiki.archlinux.org/index.php/bumblebee">Bumblebee</a> will load and unload it on demand. Intel should be loaded.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ lsmod | grep nvidia
hemen@hemen-Inspiron-7559:~$ lsmod | grep i915
i915 1130496 82
drm_kms_helper 126976 1 i915
drm 360448 5 i915,drm_kms_helper
video 40960 3 i915,dell_wmi,dell_laptop
i2c_algo_bit 16384 1 i915
</code></pre>
</div>
<p>Ensure Nvidia GPU is powered OFF by default and Intel is default display / OpenGL driver.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ cat /proc/acpi/bbswitch
0000:02:00.0 OFF
hemen@hemen-Inspiron-7559:~$ glxinfo | grep OpenGL
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Skylake Halo GT2
OpenGL version string: 3.0 Mesa 11.0.2
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
</code></pre>
</div>
<p>Check <a href="https://wiki.archlinux.org/index.php/bumblebee">Bumblebee</a> is able to switch to Nvidia GPU on demand. Note the <code class="highlighter-rouge">OpenGL vendor string</code> in the output below which is different than the one above.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ optirun -vv glxinfo | grep OpenGL
[ 146.851152] [DEBUG]Reading file: /etc/bumblebee/bumblebee.conf
[ 146.851729] [INFO]Configured driver: nvidia
[ 146.852116] [DEBUG]optirun version 3.2.1 starting...
[ 146.852165] [DEBUG]Active configuration:
[ 146.852183] [DEBUG] bumblebeed config file: /etc/bumblebee/bumblebee.conf
[ 146.852200] [DEBUG] X display: :8
[ 146.852217] [DEBUG] LD_LIBRARY_PATH: /usr/lib/nvidia-361:/usr/lib32/nvidia-361
[ 146.852258] [DEBUG] Socket path: /var/run/bumblebee.socket
[ 146.852296] [DEBUG] Accel/display bridge: primus
[ 146.852328] [DEBUG] VGL Compression: proxy
[ 146.852345] [DEBUG] VGLrun extra options:
[ 146.852361] [DEBUG] Primus LD Path: /usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
[ 148.118143] [INFO]Response: Yes. X is active.
[ 148.118160] [INFO]Running application using primus.
[ 148.118277] [DEBUG]Process glxinfo started, PID 2508.
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 960M/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 361.93.02
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 361.93.02
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
[ 148.223795] [DEBUG]SIGCHILD received, but wait failed with No child processes
[ 148.223836] [DEBUG]Socket closed.
[ 148.223846] [DEBUG]Killing all remaining processes
</code></pre>
</div>
<p>Check the working of <code class="highlighter-rouge">bbswitch</code> using <code class="highlighter-rouge">glxgears</code>. Open an additional terminal and check the initial state of Nvidia GPU.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ cat /proc/acpi/bbswitch
0000:02:00.0 OFF
</code></pre>
</div>
<p>In the original terminal, execute <code class="highlighter-rouge">optirun -vv glxgears -info</code>. While <code class="highlighter-rouge">glxgears</code> is still running, come back to the other terminal and check the status of bbswitch and modules loaded in the kernel. Note that Nvidia GPU is powered ON and nvidia modules are loaded in the kernel.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ cat /proc/acpi/bbswitch
0000:02:00.0 ON
hemen@hemen-Inspiron-7559:~$ lsmod | grep nvidia
nvidia 10223616 52
drm 360448 10 i915,drm_kms_helper,nvidia
</code></pre>
</div>
<p>Terminate <code class="highlighter-rouge">glxgears</code> and check again.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ cat /proc/acpi/bbswitch
0000:02:00.0 OFF
hemen@hemen-Inspiron-7559:~$ lsmod | grep nvidia
hemen@hemen-Inspiron-7559:~$
</code></pre>
</div>
<p>At this point, we have Nvidia drivers, Bumblebee and Xserver configured properly.</p>
<p>Restart two to three times and perform these same testing steps on each restart. This is to ensure that our configuration is persistent.</p>
<p>If all is OK after multiple restarts, then we proceed to configure CUDA.</p>
<h3 id="configuring-cuda">Configuring CUDA</h3>
<p>Edit <code class="highlighter-rouge">~/.bashrc</code> and setup/update the <code class="highlighter-rouge">$PATH</code> and <code class="highlighter-rouge">$LD_LIBRARY_PATH</code> environment variables as shown below</p>
<div class="highlighter-rouge"><pre class="highlight"><code>export PATH="$PATH:/usr/local/cuda-8.0/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib"
</code></pre>
</div>
<h3 id="install-and-build-cuda-samples">Install and Build CUDA samples</h3>
<p>Install CUDA samples in home directory and build the deviceQuery example.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>$ cd /usr/local/cuda-8.0/bin
$ ./cuda-install-samples-8.0.sh ~
$ cd ~
$ cd NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery
$ make
$ ls -l
total 628
-rwxrwxr-x 1 hemen hemen 582882 Oct 5 00:08 deviceQuery
-rw-r--r-- 1 hemen hemen 12174 Oct 5 00:07 deviceQuery.cpp
-rw-rw-r-- 1 hemen hemen 21128 Oct 5 00:08 deviceQuery.o
-rw-r--r-- 1 hemen hemen 9075 Oct 5 00:07 Makefile
-rw-r--r-- 1 hemen hemen 1737 Oct 5 00:07 NsightEclipse.xml
-rw-r--r-- 1 hemen hemen 168 Oct 5 00:07 readme.txt
</code></pre>
</div>
<p>This should create deviceQuery executable as shown above.</p>
<h3 id="execute-cuda-example">Execute CUDA example</h3>
<p>Executing the CUDA example is the tricky part, and involves the following steps in order</p>
<ol>
<li>Power ON Nvidia GPU using <code class="highlighter-rouge">bbswitch</code></li>
<li>Load nvidia and nvidia_uvm kernel modules manually</li>
<li>Use optirun to execute the required CUDA executable. This is required to set proper library paths.</li>
<li>Unload the nvidia and nvidia_uvm modules</li>
<li>Power OFF the Nvidia GPU using <code class="highlighter-rouge">bbswitch</code></li>
</ol>
<p>This complete process is outlined below</p>
<p>Initial State</p>
<div class="highlighter-rouge"><pre class="highlight"><code>$ lsmod | grep nvidia
$ ls -l /dev/nvid*
crw-rw-rw- 1 root root 195, 254 Oct 4 23:46 /dev/nvidia-modeset
$ cat /proc/acpi/bbswitch
0000:02:00.0 OFF
</code></pre>
</div>
<p>Power ON Nvidia GPU and load required kernel modules manually</p>
<div class="highlighter-rouge"><pre class="highlight"><code>$ sudo tee /proc/acpi/bbswitch <<< ON
ON
$ cat /proc/acpi/bbswitch
0000:02:00.0 ON
$ sudo modprobe nvidia_361
$ sudo modprobe nvidia_361_uvm
$ lsmod | grep nvidia
nvidia_uvm 729088 0
nvidia 10223616 1 nvidia_uvm
drm 360448 6 i915,drm_kms_helper,nvidia
</code></pre>
</div>
<p>Our system is now in a state where we can execute CUDA programs. Optirun is required, or else we get the below error message if not used.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>$ ./deviceQuery
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
cudaGetDeviceCount returned 35
-> CUDA driver version is insufficient for CUDA runtime version
Result = FAIL
# Notice the difference when using optirun to execute deviceQuery
$ optirun ./deviceQuery
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 960M"
CUDA Driver Version / Runtime Version 8.0 / 8.0
CUDA Capability Major/Minor version number: 5.0
Total amount of global memory: 4046 MBytes (4242014208 bytes)
( 5) Multiprocessors, (128) CUDA Cores/MP: 640 CUDA Cores
GPU Max Clock rate: 1176 MHz (1.18 GHz)
Memory Clock rate: 2505 Mhz
Memory Bus Width: 128-bit
L2 Cache Size: 2097152 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 1 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 2 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 960M
Result = PASS
</code></pre>
</div>
<p>Once done, unload the modules (in order as shown below) and then power OFF the GPU</p>
<div class="highlighter-rouge"><pre class="highlight"><code>$ sudo rmmod nvidia_uvm
$ sudo rmmod nvidia
$ lsmod | grep nvidia
$ cat /proc/acpi/bbswitch
0000:02:00.0 ON
sudo tee /proc/acpi/bbswitch <<< OFF
OFF
$ cat /proc/acpi/bbswitch
0000:02:00.0 OFF
$
</code></pre>
</div>
<h3 id="restart-and-test-4">Restart and Test</h3>
<p>Restart your machine and ensure that X server, GUI as well as all the tests mentioned above are working as expected.</p>
<h3 id="caution-with-system-update">Caution with System Update</h3>
<p>Since you are on Ubuntu LTS 14.04.4 you will occasionally get a message to upgrade to the latest LTS version 14.04.5 or 16.04.</p>
<blockquote>
<p>Do not automatically upgrade as it will upgrade the kernel and Xserver and will break everything.</p>
</blockquote>
<p>However we do want to keep our system updated for any security issues and updates available to the installed applications. It is possible and recommended to use <code class="highlighter-rouge">apt-get</code> to get the same done. I have done this multiple times and it is perfectly safe.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
</code></pre>
</div>
<blockquote>
<p>If you see the dist-upgrade changing kernel version to anything other than v4.2 then there is a possibility that the display will not work post upgrade, so check which packages are being upgraded with <code class="highlighter-rouge">dist-upgrade</code> before you proceed.</p>
</blockquote>
<h3 id="thats-it">That’s it</h3>
<p>So, that it. I spent countless hours figuring this out. Hope this helps you. If it does drop a comment below. If you find something missing or erroneous, drop a comment in that case too.</p>
Nvidia + Bumblebee (Optimus) on Ubuntu2016-05-07T00:00:00+05:30https://hemenkapadia.github.io/blog/2016/05/07/Ubuntu-with-Nvidia-Bumblebee<blockquote>
<p>An updated version of this guide is available at <a href="/blog/2016/11/11/Ubuntu-with-Nvidia-CUDA-Bumblebee.html">Ubuntu with Nvidia, CUDA and Bumblebee</a>.
It is recommended to follow that procedure as it provides ability to upgrade Nvidia drivers using apt-get as well as configure CUDA, which is not handled in the below guide.</p>
</blockquote>
<p>This guide lists the procedure of installing Nvidia proprietary drivers on <a href="http://www.dell.com/us/p/inspiron-15-7559-laptop/pd?oc=dncwpw5724s&model_id=inspiron-15-7559-laptop">Dell 7559</a> along with Bumblebee to get the benefits of power management provided by the Optimus technology at the same time having the flexibility to use the Nvidia GPU features without requiring to logout/login each time a configuration change is needed.</p>
<p>This guide is based on the capabilities I desired in my laptop, and much of the choice I made are guided by these principals.</p>
<ol>
<li>Stable Ubuntu version, to be supported for next 3 years.</li>
<li>Stability over cutting edge features.</li>
<li>Integrated Intel card to be my primary display driver.</li>
<li>Use proprietary Nvidia drivers (vs Nouveau) to get maximum benefit of the GPU.</li>
<li>Nvidia GPU needs to be switched off when not in use, to save power.</li>
<li>Turn on Nvidia GPU on demand for specific applications, without requiring configuration changes, logout or restarts.</li>
</ol>
<blockquote>
<p>From the Ubuntu LTS version perspective, I had option to choose 14.04 or 16.04. I tired to install Nvidia drivers on 16.04 but was never successful. After spending numerous hours figuring things out, I decided to go with version 14.04.4 which had an updated kernel and Xserver based on 15.10 as part of <a href="https://wiki.ubuntu.com/TrustyTahr/ReleaseNotes#LTS_Hardware_Enablement_Stack">LTS Hardware Enablement Stack</a>.</p>
</blockquote>
<h3 id="configure-bios-and-windows">Configure BIOS and Windows</h3>
<p>I am assuming that you would be installing Ubuntu in Dual boot mode (along with Windows) and that Windows is booting in UEFI mode. As a result, we will need to install Ubuntu in UEFI mode only.</p>
<p>If you are not sure how to <a href="www.everydaylinuxuser.com/2013/09/install-ubuntu-linux-alongside-windows.html">install Windows and Ubuntu in dual boot mode</a>, refer to the linked guide. I would like to stress on point 4 <em>Disable Fastboot (in Windows) and Secure boot (in BIOS)</em>, as those steps are super critical to follow exactly as mentioned.</p>
<p>I had disabled Secure Boot in BIOS, but did not disable Fastboot in Windows. As a result I was having a hard time installing 14.04, and the installer would fail each time with the error <code class="highlighter-rouge">grub-efi-amd64-signed failed to install into /target/. Without GRUB boot loader, the installed system will not boot</code>.</p>
<h3 id="grub-settings-for-ubuntu-live-usb">GRUB settings for Ubuntu Live USB</h3>
<p>When you start installing using a live USB, you will be presented with the GRUB screen that lets you try Ubuntu without installing as well as install Ubuntu.</p>
<p>Select the <code class="highlighter-rouge">Install Ubuntu</code> option and press <code class="highlighter-rouge">e</code> which will open the menu edit screen. Add the following kernel parameters just before <code class="highlighter-rouge">quiet splash</code> in the line that starts with <code class="highlighter-rouge">linux /boot/vmlinuz-linux .....</code></p>
<blockquote>
<p>for kernel 4.2 intel driver is i915, for kernel 4.4 it is i915_bpo. Replace accordingly.</p>
</blockquote>
<div class="highlighter-rouge"><pre class="highlight"><code>nomodeset i915.modeset=1
</code></pre>
</div>
<p>Press <code class="highlighter-rouge">F10</code> and complete the installation as per <a href="www.everydaylinuxuser.com/2013/09/install-ubuntu-linux-alongside-windows.html">install Windows and Ubuntu in dual boot mode</a></p>
<p>Once the installation is complete, you will be presented with the GRUB menu, follow the above procedure to edit the kernel parameters and boot. We will make these kernel parameters permanent in the next step.</p>
<h3 id="persist-grub-settings">Persist GRUB settings</h3>
<p>To avoid updating the kernel options each time the system is booted, update the GRUB settings <code class="highlighter-rouge">sudo vi /etc/default/grub</code> and chnage as below</p>
<div class="highlighter-rouge"><pre class="highlight"><code>GRUB_CMDLINE_LINUX_DEFAULT="nomodeset i915.modeset=1 quiet splash"
</code></pre>
</div>
<p>For High DPI or Retina displays, GRUB boot menu options are not readable as the font size is too small. It can be fixed by the below two options</p>
<div class="highlighter-rouge"><pre class="highlight"><code>GRUB_GFXMODE=1280x1024
GRUB_GFXPAYLOAD_LINUX=keep
</code></pre>
</div>
<p>Set Windows as the default system to boot</p>
<blockquote>
<p>This setting specific to my laptop, replace accordingly with the Windows label for your
system</p>
</blockquote>
<div class="highlighter-rouge"><pre class="highlight"><code>GRUB_DEFAULT="Windows Boot Manager (on /dev/sda1)"
</code></pre>
</div>
<p>To apply the changes, issue the command <code class="highlighter-rouge">sudo update-grub2</code></p>
<h3 id="optional---highdpi-settings">Optional - HighDPI settings</h3>
<p>This is an optional step, but highly recommended if you have a HighDPI or Retina display. Apply the HighDPI configuration discussed in <a href="/blog/2016/05/06/Configuring-Ubuntu-for-highDPI-and-Retina-displays.html">Configuring Ubuntu for HighDPI and Retina displays</a></p>
<h3 id="remove-nvidia-and-nouveau-and-disable-services">Remove Nvidia and Nouveau, and disable services</h3>
<ul>
<li>Restart the machine and ensure that all setttings applied so far are working as expected.</li>
<li>Switch to Virtual Console (Atl + Ctrl + F1 .. F6)</li>
<li>Stop the xserver <code class="highlighter-rouge">sudo service lightdm stop</code> (for init) or <code class="highlighter-rouge">sudo systemctl stop lightdm.service</code> (for systemctl)</li>
<li>Remove any existing installs of nvidia, nouveau etc.</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-get remove --purge nvidia*
sudo apt-get remove --purge bumblebee*
sudo apt-get --purge remove xserver-xorg-video-nouveau*
</code></pre>
</div>
<ul>
<li>To blacklist nouveau add the following lines to <code class="highlighter-rouge">/etc/modprobe.d/blacklist.conf</code></li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code># Blacklisting nouveau to get nvidia running with bumblebee
blacklist nouveau
blacklist lbm-nouveau
alias nouveau off
alias lbm-nouveau off
options nouveau modeset=0
</code></pre>
</div>
<ul>
<li>Disable gpu-manager.service for both systemctl as well as init</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo systemctl mask gpu-manager.service
sudo vi /etc/init/gpu-manager.conf
# Comment these start on settings ; GPU Manager ruins our work
#start on (starting lightdm
# or starting kdm
# or starting xdm
# or starting lxdm)
task
exec gpu-manager --log /var/log/gpu-manager.log
</code></pre>
</div>
<ul>
<li>Create initramfs <code class="highlighter-rouge">sudo update-initramfs -u -k all</code></li>
<li>Reboot the system and ensure that xserver is running fine - i.e. GUI is working properly</li>
<li>Verify that nouveau is successfully blacklisted. The command <code class="highlighter-rouge">lsmod | grep nouveau</code> should not return any lines with the word nouveau in it.</li>
<li>Check if gpu-manager.service is disabled <code class="highlighter-rouge">sudo systemctl status gpu-manager.service</code> or <code class="highlighter-rouge">sudo service gpu-manager status</code>. If not, disable as mentioned above.</li>
</ul>
<h3 id="install--nvidia-and-bumblebee">Install Nvidia and Bumblebee</h3>
<ul>
<li>
<p>Switch to Virtual Console and disable lightdm <code class="highlighter-rouge">sudo service lightdm stop</code> (for init) or <code class="highlighter-rouge">sudo systemctl stop lightdm.service</code> (for systemctl). Everything below will happen in a Virtual Console and not the X terminal. Do not restart the machine unless you complete all the configuration steps mentioned below. Everything should happen in one shot, in a Virtual Console.</p>
</li>
<li>
<p>Nvidia-352.63 is the most stable driver i have noticed. Let us see if that is the version that will get installed</p>
</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-get update
sudo apt-cache policy nvidia-352
# Output
hemen@hemen-Inspiron-7559:~$ sudo apt-cache policy nvidia-352
nvidia-352:
Installed:
Candidate: 352.63-0ubuntu0.14.04.1
Version table:
*** 352.63-0ubuntu0.14.04.1 0
500 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/restricted amd64 Packages
500 http://security.ubuntu.com/ubuntu/ trusty-security/restricted amd64 Packages
100 /var/lib/dpkg/status
</code></pre>
</div>
<p>Notice the Candidate, which says <code class="highlighter-rouge">nvidia-352.63</code>, great. Also it is available in standard Ubuntu repo, based on the link <code class="highlighter-rouge">us.archive.ubuntu.com</code>. So we are good to proceed.</p>
<ul>
<li>Install the required drivers</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-get install --no-install-recommends nvidia-352
sudo apt-get install libcuda1-352 nvidia-opencl-icd-352
sudo apt-get install --no-install-recommends bumblebee
sudo apt-get install bumblebee-nvidia primus
sudo apt-get install mesa-utils
sudo apt-get install xserver-xorg-video-intel-lts-wiley
</code></pre>
</div>
<h3 id="bumblebee-configuration">Bumblebee configuration</h3>
<ul>
<li>Add the following two lines to the <code class="highlighter-rouge">/etc/modules-load.d/modules.conf</code> file</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>i915
bbswitch
</code></pre>
</div>
<ul>
<li>Blacklist nvidia from loading, its insertion and removal from the kernel will be handled by bbswitch. Add the following lines to <code class="highlighter-rouge">/etc/modprobe.d/bumblebee.conf</code>.</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code># 352
blacklist nvidia-352
blacklist nvidia-352-updates
blacklist nvidia-experimental-352
</code></pre>
</div>
<ul>
<li>Bumblebee configuration</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo vi /etc/bumblebee/bumblebee.conf
## Configuration file for Bumblebee. Values should **not** be put between quotes
[bumblebeed]
VirtualDisplay=:8
KeepUnusedXServer=false
ServerGroup=bumblebee
TurnCardOffAtExit=false
NoEcoModeOverride=false
Driver=nvidia
XorgConfDir=/etc/bumblebee/xorg.conf.d
## Client options. Will take effect on the next optirun executed.
[optirun]
Bridge=primus
VGLTransport=proxy
PrimusLibraryPath=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
AllowFallbackToIGC=false
## Section with nvidia driver specific options, only parsed if Driver=nvidia
[driver-nvidia]
KernelDriver=nvidia-352
PMMethod=bbswitch
LibraryPath=/usr/lib/nvidia-352:/usr/lib32/nvidia-352
XorgModulePath=/usr/lib/nvidia-352/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia
## Section with nouveau driver specific options, only parsed if Driver=nouveau
# [driver-nouveau]
# KernelDriver=nouveau
# PMMethod=auto
# XorgConfFile=/etc/bumblebee/xorg.conf.nouveau
</code></pre>
</div>
<p>The value of BusID in the below files would be different for your system. You can get the value for your system as shown below.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>lspci | egrep -i "VGA|3D"
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
02:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 960M] (rev ff)
sudo vi /etc/bumblebee/xorg.conf.nvidia
Section "ServerLayout"
Identifier "Layout0"
Option "AutoAddDevices" "false"
Option "AutoAddGPU" "false"
EndSection
Section "Device"
Identifier "DiscreteNvidia"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:02:00:0"
Option "ProbeAllGpus" "false"
Option "NoLogo" "true"
Option "UseEDID" "false"
Option "UseDisplayDevice" "none"
EndSection
</code></pre>
</div>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo vi /etc/X11/xorg.conf
Section "ServerLayout"
Identifier "layout"
Screen 0 "intel"
Inactive "nvidia"
EndSection
Section "Device"
Identifier "intel"
Driver "intel"
BusID "PCI:00:02:0"
Option "AccelMethod" "SNA"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:02:00:0"
Option "ConstrainCursor" "off"
EndSection
Section "Screen"
Identifier "nvidia"
Device "nvidia"
Option "AllowEmptyInitialConfiguration" "no"
Option "IgnoreDisplayDevices" "CRT"
EndSection
</code></pre>
</div>
<ul>
<li>Update alternatives</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo update-alternatives --config x86_64-linux-gnu_gl_conf
There are 3 choices for the alternative x86_64-linux-gnu_gl_conf (providing /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/nvidia-352/ld.so.conf 8604 auto mode
1 /usr/lib/nvidia-352-prime/ld.so.conf 8603 manual mode
2 /usr/lib/nvidia-352/ld.so.conf 8604 manual mode
* 3 /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf 500 manual mode
Press enter to keep the current choice[*], or type selection number:
Select the mesa option where available, and make the below configurations similarly
sudo update-alternatives --config x86_64-linux-gnu_egl_conf
sudo update-alternatives --config i386-linux-gnu_gl_conf
sudo update-alternatives --config i386-linux-gnu_egl_conf
sync
sudo ldconfig
sudo update-initramfs -u -k all
sudo usermod -a -G bumblebee $USER
</code></pre>
</div>
<ul>
<li>Start bumblebeed</li>
</ul>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo service bumblebeed start
</code></pre>
</div>
<h3 id="testing">Testing</h3>
<p>Run the following commands and ensure that you get appropriate response as mentioned here.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>hemen@hemen-Inspiron-7559:~$ sudo service bumblebeed status
bumblebeed start/running, process 1327
hemen@hemen-Inspiron-7559:~$ cat /proc/acpi/bbswitch
0000:02:00.0 OFF
hemen@hemen-Inspiron-7559:~$ primusrun glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 960M/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 352.63
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 352.63
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
hemen@hemen-Inspiron-7559:~$ glxinfo | grep OpenGL
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Skylake Halo GT2
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.0.2
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 11.0.2
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
</code></pre>
</div>
<h3 id="restart">Restart</h3>
<p>Restart your machine and ensure that X server, GUI as well as the tests mentioned above are working as expected.</p>
Ubuntu with HighDPI or Retina displays2016-05-06T00:00:00+05:30https://hemenkapadia.github.io/blog/2016/05/06/Configuring-Ubuntu-for-highDPI-and-Retina-displays<p>I recently purchased a new laptop, <a href="http://www.dell.com/us/p/inspiron-15-7559-laptop/pd?oc=dncwpw5724s&model_id=inspiron-15-7559-laptop">Dell 7559</a>, and it came with an Ultra HD display also known as a High DPI or Retina display, and I am immensely impressed with it. The display looks good even on Windows, an OS I do not appreciate for its font rendering engine. So I installed Ubuntu on the machine, hoping to get a Mac like experience, but was shocked with the default experience as it did not cater very well to the High DPI display.</p>
<p>I have been using Linux for at least 20 years now and I am amazed that even now the installation does not fall short in throwing up challenges, which is what makes using Linux exciting. After all what is life without some challenge.</p>
<p>This blog post is a list of configurations I find useful to make Ubuntu display usable on Retina displays.</p>
<h3 id="scaling-of-the-unity-ui">Scaling of the Unity UI</h3>
<p>This issue was observed in 14.04, 15.10 but seems to have been taken care of in 16.04. The window experience with the default scaling of 1 renders the text so small that it is a challenge to read anything. I notice that the scaling factor of 2 works best as compared to any setting between 1 and 2</p>
<p>To change the scaling, in Unity search for Display and open it. Drag the slider for <code class="highlighter-rouge">Scale for menu and title bars:</code> to 2 (or any other depending in your display).</p>
<h3 id="scaling-of-virtual-console-fonts">Scaling of Virtual Console fonts</h3>
<p>While fixing my system to run <a href="/blog/2016/05/07/Ubuntu-with-Nvidia-Bumblebee.html">Nvidia + Bumblebee</a> I had to work on the Virtual Console (Alt + Ctrl + F1..F6). The fonts appear too small to read here too. To fix that follow the below steps.</p>
<p>Open up a terminal (need not be a Virtual Terminal), and issue the command</p>
<p><code class="highlighter-rouge">sudo dpkg-reconfigure console-setup</code></p>
<p>A curses based application will start, select the configuration as below</p>
<div class="highlighter-rouge"><pre class="highlight"><code>Encoding - UTF-8
Character Set - . Combined - Latin; Salvic Cyrillic; Greek
Font for console - Terminus
Font Size - 16x32
</code></pre>
</div>
<p>So as to apply this configuration each time the machine start up we need to make below changes for systemctl (15.10 onwards) or init (14.04).</p>
<p><strong>For Systemctl</strong></p>
<p>Edit <code class="highlighter-rouge">/lib/systemd/system/console-setup.service</code> and in <code class="highlighter-rouge">[Service]</code> section add <code class="highlighter-rouge">ExecStart=/bin/setupcon</code> to the bottom.</p>
<p><strong>For Init</strong></p>
<p>Edit <code class="highlighter-rouge">/etc/init/console-setup.conf</code> and add <code class="highlighter-rouge">exec /bin/setupcon</code> to the bottom of the file.</p>
<p>Both these settings cause <code class="highlighter-rouge">/bin/setupcon</code> command to run each time on boot.</p>
<p>Restart the system and open a virtual console. This time you will see that the text fonts are scaled up.</p>
<p>If any time you need to start Ubuntu in recovery mode, Systemctl or Init will not apply the above settings. In that case execute the command <code class="highlighter-rouge">/bin/setupcon</code> and the settings will get applied.</p>
<h3 id="mouse-pointer-size">Mouse pointer size</h3>
<p>This issue was experienced on 14.04, 15.10, but not experienced on 16.04. Post scaling while the windows were comfortable size, the mouse pointer still appeared very small. To fix it add the setting <code class="highlighter-rouge">Xcursor.size: 48</code> in file <code class="highlighter-rouge">/etc/X11/Xresources/x11-common</code></p>
<h3 id="display-brightness-adjustment">Display brightness adjustment</h3>
<p>This issue is noticed in 14.04, 15.10 and 16.04 was well, but in 16.04 the brightness level seems to persist once changed manually. 15.10 and 14.04 did not persist the changes done manually so the following steps are needed.</p>
<blockquote>
<p>Note the path of the file mentioned below is dependent on your graphics card.</p>
</blockquote>
<p>Fix is to add the below line above the <code class="highlighter-rouge">exit 0</code> line in <code class="highlighter-rouge">/etc/rc.local</code> (note above exit 0)</p>
<p><code class="highlighter-rouge">echo 339 > /sys/class/backlight/intel_backlight/brightness</code></p>
<p>To get the desired number (339 in the above case), adjust brightness to the desired level manually and issue comment to get the required number which you can then substitute in the above command.</p>
<p><code class="highlighter-rouge">cat /sys/class/backlight/intel_backlight/brightness</code></p>
<h3 id="scaling-of-grub-menu">Scaling of GRUB menu</h3>
<p>Refer to the section “Persist GRUB Settings” in <a href="/blog/2016/05/07/Ubuntu-with-Nvidia-Bumblebee.html">Nvidia + Bumblebee</a> which provides settings to improve the font scaling in GRUB menu.</p>
<p>Ok. That’s it for now.</p>
Introducing hydeX2015-03-14T00:00:00+05:30https://hemenkapadia.github.io/blog/2015/03/14/introducing-hydeX<p>hydeX is an extended version of <a href="http://hyde.getpoole.com">Hyde</a>, a brazen two-column theme for <a href="http://jekyllrb.com">Jekyll</a>. hydeX supports all features of Hyde and additionally provides the following enhancements:</p>
<ul>
<li>Fully aligned with GitHub pages upgrade to Jekyll 3.0 <a href="https://github.com/poole/hyde#sticky-sidebar-content">read more</a>. Uses the default Markdown engine (kramdown) as well as the default highlighter (Rogue).</li>
<li><a href="https://www.mathjax.org/">MathJax</a> support added allowing ability to include inline as well as block math constructs.</li>
<li>Sidebar content is no longer sticky - making itfloat to the top as compared to stick to the bottom of the sidebar. If you want sticky content in the Sidebar then refer to the <a href="https://github.com/poole/hyde#sticky-sidebar-content">Sidebar Sticky option</a></li>
<li>Sidebar includes support for <a href="http://fortawesome.github.io/Font-Awesome/">Font Awesome</a> icons for following popular social media sites - Twitter, LinkedIn, Facebook, Instagram, GooglePlus, YouTube and StackOverflow. Just update your social media username in config.yml file and the rest should be taken care of. You can also extend this logic to any other social media sites that are currently not included (supported).</li>
<li>Homepage now displays only the excerpt for the post as compared to the full post</li>
</ul>
<p>Thanks!</p>