So lately I’ve been devoting my time in Igalia around the GNU/Linux graphics stack focusing, more specifically, in Mesa, the most popular open-source implementation of the OpenGL specification.
When working in Mesa and piglit, its testing suite, quite often you would like to compare the results obtained when running a specific OpenGL code with one driver or another.
In the case of nVIDIA graphic cards we have the chance of comparing the default open source driver provided by Mesa, nouveau, or the proprietary driver provided by nVIDIA. For installing the nVIDIA driver you will have to run something like:
root$ apt-get install linux-headers nvidia-driver nvidia-kernel-dkms nvidia-xconfig nvidia-kernel-amd64
Changing from one driver to another involves several steps so I decided to create a dirty script for helping with this.
The actions done by this script are:
-
Instruct your X Server to use the adequate X driver.
These instructions apply to the X.org server only.
When using the default nouveau driver in Debian, the X.org server is able to configure itself automatically. However, when using the nVIDIA driver you most probably will have to instruct the proper settings to X.org.
nVIDIA provides the package nvidia-xconfig. This package provides a tool of the same name that will generate a X.org configuration file suitable to work with the nVIDIA X driver:root$ nvidia-xconfig WARNING: Unable to locate/open X configuration file. Package xorg-server was not found in the pkg-config search path. Perhaps you should add the directory containing `xorg-server.pc' to the PKG_CONFIG_PATH environment variable No package 'xorg-server' found New X configuration file written to '/etc/X11/xorg.conf'
I have embedded this generated file into the provided custom script since it is suitable for my system:
echo 'Section "ServerLayout" Identifier "Layout0" Screen 0 "Screen0" InputDevice "Keyboard0" "CoreKeyboard" InputDevice "Mouse0" "CorePointer" EndSection Section "Files" EndSection Section "InputDevice" # generated from default Identifier "Mouse0" Driver "mouse" Option "Protocol" "auto" Option "Device" "/dev/psaux" Option "Emulate3Buttons" "no" Option "ZAxisMapping" "4 5" EndSection Section "InputDevice" # generated from default Identifier "Keyboard0" Driver "kbd" EndSection Section "Monitor" Identifier "Monitor0" VendorName "Unknown" ModelName "Unknown" HorizSync 28.0 - 33.0 VertRefresh 43.0 - 72.0 Option "DPMS" EndSection Section "Device" Identifier "Device0" Driver "nvidia" VendorName "NVIDIA Corporation" EndSection Section "Screen" Identifier "Screen0" Device "Device0" Monitor "Monitor0" DefaultDepth 24 SubSection "Display" Depth 24 EndSubSection EndSection ' > /etc/X11/xorg.conf
I would recommend you to substitute this with another configuration file generated with nvidia-xconfig on your system.
-
Select the proper GLX library.
Fortunately, Debian provides the alternatives mechanism to select between one or the other.ALTERNATIVE=""
…
ALTERNATIVE="/usr/lib/mesa-diverted"
…
ALTERNATIVE="/usr/lib/nvidia"
…
update-alternatives --set glx "${ALTERNATIVE}"
-
Black list the module we don’t want the Linux kernel to load on start up.
Again, in Debian, the nVIDIA driver package installs the file /etc/nvidia/nvidia-blacklists-nouveau.conf that is linked, then, from /etc/modprobe.d/nvidia-blacklists-nouveau.conf instructing that the open source nouveau kernel driver for the graphic card should be avoided.
When selecting nouveau, this script removes the soft link creating a new file which, instead of black listing nouveau’s driver, does it for the nVIDIA proprietary one:rm -f /etc/modprobe.d/nvidia-blacklists-nouveau.conf echo "blacklist nvidia" > /etc/modprobe.d/nouveau-blacklists-nvidia.conf
When selecting nVIDIA, the previous file is removed and the soft link is restored.
-
Re-generate the image used in the inital booting.
This will ensure that we are using the proper kernel driver from the beginning of the booting of the system:update-initramfs -u
With these actions you will be already able to switch your running graphic driver.
You will switch to nouveau with:
root$/alternate-nouveau-nvidia.sh nouveau update-alternatives: using /usr/lib/mesa-diverted to provide /usr/lib/glx (glx) in manual mode update-initramfs: Generating /boot/initrd.img-3.17.0 nouveau successfully set. Reboot your system to apply the changes ...
And to the nVIDIA proprietary driver with:
root$/alternate-nouveau-nvidia.sh nvidia update-alternatives: using /usr/lib/nvidia to provide /usr/lib/glx (glx) in manual mode update-initramfs: Generating /boot/initrd.img-3.17.0 nvidia successfully set. Reboot your system to apply the changes ...
It is recommended to reboot the system although theoretically you could unload the kernel driver and restart the X.org server. The reason is that it has been reported that unloading the nVIDIA kernel driver and loading a different one is not always working correctly.
I hope this will be helpful for your hacking time!
Pingback: Links 24/11/2014: Linux 3.18-rc6, Qualcomm Eyes GNU/Linux Servers | Techrights
This seems to be the least fussy way to alternate. Do you know if it still works on Debian 8.2 and newer?
I’m currently using Debian Testing an it keeps working for me.
Just be aware that, when upgrading, you may end with a messy set of packages, with different versions of the nVidia packages, kernel module and running kernel.
If you have a coherent set of packages, it is working correctly, AFAIK.
it is really bothering one cannot just launch apps chosing which renderer use, e.g.
OPENGL=nvidia glxgears
or
OPENGL=mesa glxgears
That would be much more flexible!
Have into account that this post has become a bit old. Debian (and other distros) makes the change between drivers much easier nowadays.
In any case, rebooting is almost a must since you will have to unload a kernel module and load a different one no matter what. I suppose it’s possible to do it without rebooting but probably it’s not advisable.
Thank you for the reply.
Is it possible to select the library (mesa vs nvidia) using libglvnd (GL vendor-neutral dispatch)?