Ubuntu – Switch video drivers in dual boot environment

driversdual-bootgraphicsnvidiavmware

What is the easiest way to make ubuntu boot on both native computer with NVIDIA card installed and as a VMware guest. After installing nvidia-304 driver package I can't load it in VMware. It stuck in login loop with this error in .xsession-errors:

Xlib: extension "GLX" missing on display ":0".

The only relevant answer I found is this but it doesn't work for me. There is no switchlibglx in NVIDIA drivers.

EDIT: My investigation results. NVIDIA spoilt the system with their OpenGL module through the symbolic link in system directory libglx.so. Their module can only work with NVIDIA driver which is not loaded if you start the system with a different video adapter obviously. There is no default and easy way to choose which OpenGL module to use depending on the driver loaded. It's a classic unix logic. In any difficult situation don't bother to invent API and options, just overwrite the default symbolic link in global directory and let a user deal with this mess. NVIDIA just use the standard crutch to install their driver and module. There are three possible workaround:

1) install and uninstall nvidia drivers every time you use it in VMware

2) make a complicated config file that run a script and overwrite symbolic links during boot depending on the adapter present (See the answer below)

3) somehow disable the use of GLX extensions in X server to load it in VMware

Best Answer

You are having this problem because your X configuration is trying to load the nvidia driver which is then looking for a compatible nvidia device. Such a device does not exist in the guest environment instead a VMware virtual graphics device is presented instead and thus the nvidia driver is not the correct driver in the guest OS.

The correct driver for the vmware virtual graphics interface is the one provided by the xserver-xorg-video-vmware package not the ones provided by the nvidia-* packages which are only suitable for direct access to the GPU. You can install the correct driver using the following command on the guest:

sudo apt-get install xserver-xorg-video-vmware

Also make sure that 3D acceleration is enabled on the virtual machine configuration and that you have installed the vmware guest additions correctly. You should also make sure that you don't have an xorg.conf file which is explicitly selecting the nvidia driver since this will fail.

If you wanted a script you could set to run at boot time before lightdm is started you could try something like this:

#!/bin/bash
# Vendor identifiers
nvidia=\"10de\"
vmware=\"15ad\"

# Detect NVIDIA driver
nvidia_driver=`dpkg --get-selections | awk '/nvidia-[0-9]+\t+install/ { print $1 }'`

# Detect PCI bus ID
vga_bus_id=`lspci | awk '/VGA/ { print $1 }'`

# Detect VGA vendor identifier
vga_vendor=$(lspci -nm | awk "/$vga_bus_id/ { print \$3 }")

if [ $vga_vendor == $nvidia ]; then
   # Configure for nvidia GLX via update-alternatives
   update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/${nvidia_driver}/alt_ld.so.conf
   update-alternatives --set i386-linux-gnu_egl_conf /usr/lib/${nvidia_driver}/alt_ld.so.conf
   update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/${nvidia_driver}/ld.so.conf
   update-alternatives --set x86_64-linux-gnu_egl_conf /usr/lib/${nvidia_driver}/ld.so.conf
elif [ $vga_vendor == $vmware ]; then
   # Configure for mesa GLX via update-alternatives
   update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/i386-linux-gnu/mesa/ld.so.conf
   update-alternatives --set i386-linux-gnu_egl_conf /usr/lib/i386-linux-gnu/mesa-egl/ld.so.conf
   update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf
   update-alternatives --set x86_64-linux-gnu_egl_conf /usr/lib/x86_64-linux-gnu/mesa-egl/ld.so.conf
else
   # Configure for mesa GLX via update-alternatives
   update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/i386-linux-gnu/mesa/ld.so.conf
   update-alternatives --set i386-linux-gnu_egl_conf /usr/lib/i386-linux-gnu/mesa-egl/ld.so.conf
   update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf
   update-alternatives --set x86_64-linux-gnu_egl_conf /usr/lib/x86_64-linux-gnu/mesa-egl/ld.so.conf
fi

The script checks which vendor identifier is detected for the graphics card, if nvidia it will configure ld to use the nvidia provided opengl libraries however if the vmware device is detected it will configure for mesa, mesa being the default if neither vendor string is recognised.

A number of assumptions are being made here the script wont work correctly if these are not the case:

  1. Multilib install is assumed thus the settings for both i386 and x86_64
  2. It is assumed that the ubuntu provided nvidia driver is installed this will not work if you installed the nvidia driver manually without using apt.

I do not however have vmware installed so I am only able to test and be sure that it works correctly when the nvidia device is detected and the ubuntu provided nvidia drivers are installed.