Finally found a way to fix NVIDIA Bumblebee on my notebook reliably

NVIDIA Bumblebee on my notebook would get broken from time to time (WITH NVIDIA DRIVERS). After that happens I would always get the famous:

[ERROR]Cannot access secondary GPU - error: [XORG] (EE) /dev/dri/card0: failed to set DRM interface version 1.4: Permission denied
or
[ERROR]Cannot access secondary GPU - error: [XORG] (EE) /dev/dri/card1: failed to set DRM interface version 1.4: Permission denied

And after this I had to remove all nvidia and bumblebee stuff and hope I can get a working setup again (the only solution I found online that worked for me). Today I finally tried again after having it broken for months (I think it can break for me if losing power while nvidia is off (on shutdown it would turn it on normally), or if one of many other things go wrong (e.g. for me today while testing: running optirun -b primus)).

But what atm restores it for me is this:


#WHILE NVIDIA IS RUNNING:
zypper in -f bbswitch-kmp-desktop-0.8_k3.16.6_2-22.1  bbswitch && depmod -a && mkinitrd && reboot

I use ‘bbswitch-kmp-desktop-0.8_k3.16.6_2-22.1’ to be sure I get the version from Bumblebee repo, change the version to the current one! Make sure you get both of these from Bumblebee repo!!!

The important thing is that nvidia must be running while you do that!!! E.g. call the following first:

tee /proc/acpi/bbswitch <<<ON
modprobe nvidia_drm
modprobe nvidia_modeset
modprobe nvidia_uvm
modprobe nvidia

Hope this can help someone.

Note: the thing above is just what worked for me.

I am rather sure the ‘depmod -a && mkinitrd’ is not needed.
The re-install of bbswitch is probably also not needed. Important is that you reboot while nvidia is running.

So turn on nvidia:

tee /proc/acpi/bbswitch <<<ON
modprobe nvidia_drm
modprobe nvidia_modeset
modprobe nvidia_uvm
modprobe nvidia

Make sure nvidia is on:

cat /proc/acpi/bbswitch
# must return 'ON'

lsmod | grep nvidia
#should return something like:
#nvidia_uvm            792145  0 
#nvidia_drm             14339  0 
#nvidia_modeset        768418  1 nvidia_drm
#nvidia              11495538  2 nvidia_modeset,nvidia_uvm
#drm                   335594  5 i915,drm_kms_helper,nvidia_drm

Then reboot.