Bumblebee not disabeling NVIDIA

I installed bumblebee to save some battery on my laptop. It works very well. When I boot the computer cat /proc/acpi/bbswitch says OFF. When i run an application with primusrun, cat /proc/acpi/bbswitch says ON as expected, but it doesn't go back to OFF when the application quits. I have seen questions about similar problems but no answers. The only thing I have found is that you can run sudo rmmod nvidia && sudo tee /proc/acpi/bbswitch <<<OFF to disable the NVIDIA graphics card manually.


Had the same behaviour a while ago on Xubuntu 15.10 (64bit) with bumblebee and nvidia-355 (installed from here). There might to be some issues in Bumblebee with removing nvidia kernel module when it has a alias in modprobe.d, something to do with modprobe vs. insmod/rmmod I think.

Warning: I tried other things before this one so this might or might not be the complete fix.

Starting point was that I had an otherwise working configuration except NVIDIA GPU stayed on after running something with optirun. I then edited /etc/modprobe.d/nvidia-graphics-drivers.conf and commented out line (which probably get overwritten on driver updates and will have to be fixed again):

#alias nvidia nvidia_355

In /etc/bumblebee/bumblebee.conf I use Driver=nvidia with these settings:

[driver-nvidia]
KernelDriver=nvidia_355
PMMethod=auto
LibraryPath=/usr/lib/nvidia-355:/usr/lib32/nvidia-355
XorgModulePath=/usr/lib/nvidia-355/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia

After this Bumblebee removes nvidia_355 kernel module ok and optirun --status reports "Discrete video card is off".

EDIT: removed commenting out "alias nvidia-uvm", tested and no need to comment out, might even be bad idea.

EDIT2: these settings should work also with nvidia-361 drivers if you update the settings above from "355" to "361". In addition with current bumblebee package from universe (3.2.1-9), you have to add blacklisting for 361 to /etc/modprobe.d/bumblebee.conf and add nvidia-modeset to the "remove line" at the end of the file i.e. change:

# Workaround to make sure nvidia-uvm is removed as well
remove nvidia rmmod nvidia-uvm nvidia

to

# 361
blacklist nvidia-361
blacklist nvidia-361-updates
blacklist nvidia-experimental-361
# Workaround to make sure nvidia-uvm is removed as well
remove nvidia rmmod nvidia-modeset nvidia-uvm nvidia

EDIT3: with nvidia-364 change remove line to:

remove nvidia rmmod nvidia-drm nvidia-modeset nvidia-uvm nvidia