Here's my fix/workaround for the bug:
If you want to use bumblebee instead of nvidia-prime, have a look at the answer provided by @whizzzkid below.
Tested with Kubuntu 16.10 64-bit using KDE Plasma Version.7.5 and KDE Frameworks Version 5.26.0. The following steps work for me. I hope they will work for you too, but I can't guarantee that and take no responsibility if they don't. But I'm glad to help you if you leave a comment.
In my case, the problem was that the update-alternative /usr/lib/nvidia-XYZ-prime/ didn't work at all. It's supposed to redirect calls to the intel-mesa driver, but for some reason it didn't. So it's probably after all a bug in update-alternatives? I still haven't found a place to report a bug for update-alternatives. Please comment if you can help me.
I basically modified nvidia-prime a bit to change the update-alternatives directly to the intel-mesa driver instead of /usr/lib/nvidia-XYZ-prime/.
Important:
Before you apply any of these steps make sure to know how to access recovery mode on your PC. If you can't boot anymore due to this guide you can still undo the changes in recovery mode with the commands in the last section of this guide. See this website about how to access recovery mode for more information.
If you use a 32-bit operating system, you have to leave out all commands containing x86_64 in Step 4 and in the section How to undo all these modifications.
Step 1:
Install my patch using an easy method provided by @whizzzkid in his answer below:
cd /usr/bin
sudo mv prime-select prime-select.bkup
sudo wget https://raw.githubusercontent.com/C11235/nvidia-prime-bugfix/master/prime-select
sudo chmod 755 prime-select
Step 2:
Apply my second patch to reduce the power consumption in intel mode:
Check which nvidia-driver version you have. For example with the following command:
$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 378.13 Tue Feb 7 20:10:06 PST 2017
GCC version: gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)
In this case nvidia-XYZ is nvidia-378. See this Stackoverflow thread.
Create a bash file containing with the following contents named for example poweroff.sh
#!/bin/bash
line=$(</etc/prime-discrete)
if [ "$line" == "off" ]
then
rmmod nvidia-drm
rmmod nvidia-modeset
rmmod nvidia
bash -c 'echo OFF > /proc/acpi/bbswitch'
fi
Create a second bash file containing with the following contents named for example poweron.sh and replace XYZ with your nvidia driver version number.
#!/bin/bash
modprobe nvidia-XYZ
modprobe nvidia-XYZ-modeset
modprobe nvidia-XYZ-drm
modprobe nvidia-XYZ-uvm
echo ON > /proc/acpi/bbswitch
In Intel mode, you have to run the first script after login with sudo and the second one before logout with sudo (otherwise your laptop will probably crash, as in my case). I just execute them with sudo bash FILENAME
.
So far I wasn't able to automatically autostart these scripts as root on login and before logout. However, it might be possible with upstart, as @Fiximan pointed out. I might update this answer again sometime in the future if I manage to do so.
(probably) KDE Plasma specific errors:
There is still a bug I wasn't able to fix in KDE Plasma: Whenever I switch from Nvidia to Intel after I started the PC in nvidia-mode, ksmserver crashes and the PC is rendered unusable, I have to turn it off by pressing the power button for about 5-10 seconds. This sometimes results in the update-alternatives being changed to nvidia-prime instead of intel-mesa which leads to a black-screen upon startup.
If you happen to be affected by the ksmserver bug, please contribute to the official bug-report on bugs.kde.org.
However, the problem that the PC won't shutdown can be avoided by always selecting intel-mode before shutdown, even when you use nvidia-mode. If you do this, everything works as it should in the first place and you don't have to power off your PC by long-pressing the power-button except after you apply this guide in nvidia-mode.
A simple workaround for the black-screen-upon-startup-bug is to just remove the not working update-alternatives completely:
Step 1:
You can access your PC again after you enter recovery mode, select root command shell and execute the following 2 commands:
mount -o remount,rw /
prime-select nvidia
Step 2:
Execute the following commands:
sudo update-alternatives --remove i386-linux-gnu_gl_conf /usr/lib/nvidia-XYZ-prime/alt_ld.so.conf
sudo update-alternatives --remove i386-linux-gnu_egl_conf /usr/lib/nvidia-XYZ-prime/alt_ld.so.conf
sudo update-alternatives --remove x86_64-linux-gnu_gl_conf /usr/lib/nvidia-XYZ-prime/ld.so.conf
sudo update-alternatives --remove x86_64-linux-gnu_egl_conf /usr/lib/nvidia-XYZ-prime/ld.so.conf
How to undo all these modifications
Just execute the following commands:
sudo rm /usr/bin/prime-select
sudo mv /home/YOUR-USERNAME/prime-select.backup /usr/bin/prime-select
sudo update-alternatives --install /etc/ld.so.conf.d/i386-linux-gnu_GL.conf i386-linux-gnu_gl_conf /usr/lib/nvidia-XYZ-prime/alt_ld.so.conf 8603
sudo update-alternatives --install /etc/ld.so.conf.d/i386-linux-gnu_EGL.conf i386-linux-gnu_egl_conf /usr/lib/nvidia-XYZ-prime/alt_ld.so.conf 8603
sudo update-alternatives --install /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf x86_64-linux-gnu_gl_conf /usr/lib/nvidia-XYZ-prime/ld.so.conf 8603
sudo update-alternatives --install /etc/ld.so.conf.d/x86_64-linux-gnu_EGL.conf x86_64-linux-gnu_egl_conf /usr/lib/nvidia-XYZ-prime/ld.so.conf 8603
Best Answer
I have a Dell 7577 with a GTX 1060 and recently updated to 20.04. As with 18.04/10 the nvidia driver/module had problems detecting the 1060. My solution was to use "nvidia-xconfig" to create an xorg.conf file and then specify the Driver and BusID fields...