Installing Kubuntu 16.10 on nVidia Optimus Laptop

I’ve been using Ubuntu since 2009 (Ubuntu 9.04). I’m comfortable with Ubuntu because I can usually just install it and get things done rather than spending days or weeks trying to get things working properly (although I must admit it is extremely gratifying getting things working properly). Unlike everyone else I know who uses Linux, I actually like the Unity desktop, although I despise the default orange color scheme (something that can be easily changed).

Very recently, I decided to try out Kubuntu 16.10. I’m really glad I did. I’m not going to say I like Kubuntu better than Ubuntu (or KDE more than Unity), but I will say that Kubuntu 16.10 is beautiful and an absolute pleasure to use. Having said that, I found the installation quite difficult on any laptop that has dual Intel/nVidia graphics.

I’m going to list the steps I used to get Kubuntu 16.10 working on my Defiance II.

My Laptop

I have a PC Specialist Defiance II, which is a re-branded Clevo P65_P67RGRERA.

syd@d2-lin:~$ sudo dmidecode | grep -A 9 "System Information"
System Information
        Manufacturer: PC Specialist Limited
        Product Name: P65_P67RGRERA
        Version: Not Applicable                  
        Serial Number: Not Applicable                  
        UUID: 275BFA80-A763-0000-0000-000000000000
        Wake-up Type: Power Switch
        SKU Number: Not Applicable                  
        Family: Not Applicable

BIOS Settings

After much trial and error I discovered that, on my laptop, it was important to have the following BIOS settings:

UEFI: Enabled
Secure Boot: Disabled
GPU Settings: DISCRETE

On my laptop I set the GPU settings by navigating to:

Advanced -> Advanced Chipset Control -> MSHYBRID or DISCRETE SWITCH

in the BIOS. This will differ from laptop to laptop, and some laptops may not even offer the option to switch between the two.

Boot from Installation Media

When booting from the installation media you need to press the ‘e’ key when the GRUB menu is displayed. Add ‘nomodeset’ just before “quiet splash”, then press F10 to boot. I have found that without setting ‘nomodeset’, the installation will completely lock up at some point.

So long as nomodeset is set, the installation should complete without any problems. Once the installation is complete, you will be asked to remove the installation media and press . Do this. I have found that sometimes my laptop just won’t reboot at this stage, and I have to hold down the power button to force a power off.

The following steps is where the fun begins…

Install Updates

Again, this may differ from laptop to laptop, but I found that on both Ubuntu 16.10 and Kubuntu 16.10, I could not sign in to the GUI at this point. If I tried to do so, the system would just freeze.

Immediately after the login screen is displayed, press ALT + CTRL + F1 to bring up a virtual console (terminal). Failure to do this quickly enough after the reboot may result in your system freezing.

In the console, install system updates as usual:

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt autoremove

If you don’t have a wifi connection at this stage, you may have to use a network cable.

When done, reboot using:

sudo reboot

Again, immediately after the login screen is displayed, press ALT + CTRL + F1 to bring up a console.

Install Latest Kernel

To install the latest kernel (4.9.8 at time of writing):

mkdir /tmp/kernel && cd /tmp/kernel
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.8/linux-headers-4.9.8-040908_4.9.8-040908.201702040431_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.8/linux-headers-4.9.8-040908-generic_4.9.8-040908.201702040431_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.8/linux-image-4.9.8-040908-generic_4.9.8-040908.201702040431_amd64.deb
sudo dpkg -i *.deb

Reboot, and once again immediately press ALT + CTRL + F1 when the login window is displayed.

Installing the Latest nVidia Drivers

To install the latest nVidia drivers (378 at time of writing):

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update && sudo apt install nvidia-378

Once again, reboot (with: sudo reboot), and once again press ALT + CTRL + F1 the moment the login window appears.

Set ACPI OSI Kernel Boot Parameter

On my laptop, I found this step very important. Without it, I was getting kernel panics on rebooting. Edit /etc/default/grub and change the GRUB_CMDLINE_LINUX_DEFAULT line so it includes acpi_osi=\”!Windows 2015\”. For example, it should look something like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=\"!Windows 2015\""

When done, run:

sudo update-grub2

then reboot:

sudo reboot

From this point, you no longer have to bring up a console. You’ll be able to boot in to Kubuntu using the GUI. There is, however, one more step to complete…

Tearing

You’ll notice that there’s tearing. This is a known issue with KDE for which there is a known workaround – enabling triple buffering!

Create a file in /etc/profile.d/ called “tearing.sh” (the filename doesn’t have to be “tearing.sh”, it can be anything you choose). Tearing.sh should contain a single line:

export KWIN_TRIPLE_BUFFER=1

You will have to log out and log back in again (or just reboot the laptop) for this setting to take effect.

Switching from nVidia to Intel Graphics

From here on in, switching between nVidia and Intel graphics requires going in to the BIOS and selecting with GPU you want to use. When in Intel GPU mode, you can check to make sure the nVidia GPU is not powered on using:

cat /proc/acpi/bbswitch

(the result should be “OFF”).

If you want to see how much power your laptop is using, install powerstat:

sudo apt install powerstat

To run powerstat, you need to be running off battery (i.e. make sure the laptop is no plugged in to the mains). On my laptop, power usage at idle is around 11 Watts:

mnemonic@d2-lin:~$ sudo powerstat
[sudo] password for mnemonic: 
Running for 300.0 seconds (30 samples at 10.0 second intervals).
Power measurements will start in 180 seconds time.

  Time    User  Nice   Sys  Idle    IO  Run Ctxt/s  IRQ/s Fork Exec Exit  Watts
01:37:51   0.0   0.0   0.0 100.0   0.0    1     42     26    0    0    0  11.90 
01:38:01   0.0   0.0   0.0  99.9   0.0    1     65     28    0    0    0  11.74 
01:38:11   0.0   0.0   0.0 100.0   0.0    1     47     24    0    0    1  12.09 
01:38:21   0.0   0.0   0.0 100.0   0.0    1     34     20    0    0    0  12.22 
01:38:31   0.0   0.0   0.0 100.0   0.0    2     50     22    0    0    0  11.90 
01:38:41   0.2   0.0   0.0  99.8   0.0    1    142     63    6    2   21  12.29 
01:38:51   0.0   0.0   0.0 100.0   0.0    1     39     20    1    0    0  12.13 
01:39:01   0.1   0.0   0.0  99.9   0.0    2    180     43    3    1    0  11.70 
01:39:11   0.1   0.0   0.0  99.9   0.0    1    100     39    4    1    3  11.31 
01:39:21   0.1   0.0   0.1  99.9   0.0    1    121     40    7    2    6  12.24 
01:39:31   0.0   0.0   0.0  99.9   0.0    1     50     30    0    0    6  11.78 
01:39:41   0.0   0.0   0.0 100.0   0.0    1     33     18    0    0    0  11.74 
01:39:51   0.0   0.0   0.0 100.0   0.0    1     36     22    0    0    0  11.74 
01:40:01   0.0   0.0   0.0 100.0   0.0    1     65     26    0    0    1  11.72 
01:40:11   0.4   0.0   0.2  99.3   0.1    1    582    289    0    0    0  11.82 
01:40:21   0.0   0.0   0.0 100.0   0.0    1     30     17    0    0    0  11.74 
01:40:31   0.0   0.0   0.0 100.0   0.0    1     34     20    0    0    0  11.75 
01:40:41   0.0   0.0   0.0 100.0   0.0    1     31     20    0    0    0  11.70 
01:40:51   0.0   0.0   0.0 100.0   0.0    1     34     22    0    0    0  11.70 
01:41:01   0.1   0.0   0.0  99.9   0.0    1    256     35    1    0    0  11.70 
01:41:11   0.1   0.0   0.0  99.9   0.0    1    102     37    6    2    2  11.73                                              
01:41:21   0.1   0.0   0.0  99.9   0.0    1     45     26    1    0    5  11.70                                             
01:41:31   0.0   0.0   0.0 100.0   0.0    1     37     21    0    0    0  11.68                                            
01:41:41   0.0   0.0   0.0  99.9   0.0    1     94     35    6    2    2  11.26                                              
01:41:51   0.1   0.0   0.0  99.9   0.0    1    117     42    6    2    6  11.69 
01:42:01   0.8   0.0   0.4  98.5   0.4    1   1138    539    0    0    4  11.87 
01:42:11   0.0   0.0   0.0  99.9   0.0    1     62     29    0    0    0  11.84                                                       
01:42:21   0.0   0.0   0.0 100.0   0.0    1     41     22    0    0    0  11.72                                                       
01:42:31   0.0   0.0   0.0 100.0   0.0    1     38     22    0    0    1  11.72                                                       
01:42:41   0.0   0.0   0.0 100.0   0.0    1     35     19    0    0    0  11.69                                                       
-------- ----- ----- ----- ----- ----- ---- ------ ------ ---- ---- ---- ------                                                       
 Average   0.1   0.0   0.0  99.9   0.0  1.1  122.6   53.8  1.4  0.4  1.9  11.79                                                        
  StdDev   0.1   0.0   0.1   0.3   0.1  0.2  215.8  102.1  2.3  0.8  4.1   0.22                                                        
-------- ----- ----- ----- ----- ----- ---- ------ ------ ---- ---- ---- ------                                                        
 Minimum   0.0   0.0   0.0  98.5   0.0  1.0   29.5   17.3  0.0  0.0  0.0  11.26                                                        
 Maximum   0.8   0.0   0.4 100.0   0.4  2.0 1138.1  539.4  7.0  2.0 21.0  12.29                                                        
-------- ----- ----- ----- ----- ----- ---- ------ ------ ---- ---- ---- ------                                                        
Summary:                                                                                                                               
System:  11.79 Watts on average with standard deviation 0.22

Conclusion

While the above will enable a hybrid graphics laptop to choose between the nVidia and Intel GPUs, not everything works correctly.

In Intel GPU mode:

  • The screen brightness cannot be adjusted using the keyboard.
  • The video output ports (mini-displayport/HDMI) do not work.
  • Hibernate doesn’t work (there is a workaround: ALT + CTRL + F1, then ALT + CTRL + F7).

In nVidia GPU mode, everything just works.

1 thought on “Installing Kubuntu 16.10 on nVidia Optimus Laptop

  1. Some of the information in this article is now outdated. I have found that a solution that works for me on Kubuntu 18.04 is to add the following kernel parameter in /etc/grub/default:

    GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash nvidia-drm.modeset=1 acpi_osi=\”!Windows 2015\””

    Then run: $ sudo update-grub

    This was a suggested solution from this Nvidia forum (comment #340):

    https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/23

Comments are closed.