Login Loop - "BadValue (integer parameter out of range for operation)" - 16.04

I was running Ubuntu 16.04 LTS with a manually installed NVIDIA 361 driver. After upgrading the driver to v367 I am now locked out of Unity with a login loop with the following error in .xsession-errors:

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  32
  Current serial number in output stream:  33
openConnection: connect: No such file or directory
cannot connect to brltty at :0

I also found this in the Xorg logs:

[ 2312.921302] NVRM: Your system is not currently configured to drive a VGA console
[ 2312.921304] NVRM: on the primary VGA device. The NVIDIA Linux graphics driver
[ 2312.921305] NVRM: requires the use of a text-mode VGA console. Use of other console
[ 2312.921305] NVRM: drivers including, but not limited to, vesafb, may result in
           NVRM: make sure that this kernel module and all NVIDIA driver

And then this further down:

[  2850.609] (II) NOUVEAU driver Date:   Tue Dec 8 15:52:25 2015 +1000
[  2850.609] (II) NOUVEAU driver for NVIDIA chipset families :
[  2850.706] (EE) [drm] Failed to open DRM device for (null): -22
[  2850.706] (EE) [drm] Failed to open DRM device for (null): -22
[  2850.706] (EE) [drm] Failed to open DRM device for pci:0000:02:00.0: -22
[  2850.706] (EE) No devices detected.
[  2850.706] (II) Applying OutputClass "nvidia" to /dev/dri/card0
[  2850.706]    loading driver: nvidia
[  2850.706] (==) Matched nvidia as autoconfigured driver 0
[  2850.706] (==) Matched nvidia as autoconfigured driver 1
[  2850.706] (==) Matched nouveau as autoconfigured driver 2
[  2850.706] (==) Matched nvidia as autoconfigured driver 3
[  2850.706] (==) Matched nouveau as autoconfigured driver 4
[  2850.706] (==) Matched vesa as autoconfigured driver 7
[  2850.706] (II) LoadModule: "nvidia"
[  2850.706] (II) Loading /usr/lib/xorg/modules/drivers/nvidia_drv.so
[  2850.708] (II) Module nvidia: vendor="NVIDIA Corporation"
[  2850.708] (II) LoadModule: "nouveau"
[  2850.708] (II) Loading /usr/lib/xorg/modules/drivers/nouveau_drv.so
[  2850.708] (II) Module nouveau: vendor="X.Org Foundation"
[  2850.708] (II) UnloadModule: "nouveau"
[  2850.708] (II) Unloading nouveau
[  2850.708] (II) Failed to load module "nouveau" (already loaded, 21886)
[  2850.709] (II) LoadModule: "vesa"
[  2850.709] (II) Loading /usr/lib/xorg/modules/drivers/vesa_drv.so
[  2850.709] (II) Module vesa: vendor="X.Org Foundation"
[  2850.709] (II) NOUVEAU driver Date:   Tue Dec 8 15:52:25 2015 +1000
[  2850.709] (II) NOUVEAU driver for NVIDIA chipset families :
[  2850.709] (II) NVIDIA dlloader X Driver  364.19  Tue Apr 19 13:48:55 PDT 2016
[  2850.709] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
[  2850.709] (II) VESA: driver for VESA chipsets: vesa
[  2850.709] (WW) xf86OpenConsole: setpgid failed: Operation not permitted
[  2850.709] (WW) xf86OpenConsole: setsid failed: Operation not permitted
[  2850.709] (EE) [drm] Failed to open DRM device for (null): -22
[  2850.709] (EE) [drm] Failed to open DRM device for (null): -22
[  2850.709] (EE) [drm] Failed to open DRM device for (null): -22
[  2850.709] (EE) [drm] Failed to open DRM device for pci:0000:02:00.0: -22
[  2850.709] (EE) [drm] Failed to open DRM device for pci:0000:02:00.0: -22

A web search of this error message does not yield many relevant results.

I have tried downgrading to v364 and then back to v361 to no avail I have tried purging xserver-xorg, xserver-xorg-core, nvidia*, lightdm to no avail I have tried reinstalling ubuntu-desktop to no avail

A complete reformat and reinstall would be hugely disruptive and I want to avoid that at all costs.

The error message in .xsession-errors always remains the same. How can I purge / restore / reset my settings and/or packages and/or libraries to a sane state without completely reformatting and reinstalling?


Adding +iglx to xserver-command in /usr/share/lightdm/lightdm.conf.d/50-xserver-command.conf.

[SeatDefaults] 
# Dump core 
xserver-command=X -core +iglx

After which you either reboot or Ctrl-Alt-F1, login, and sudo service lightdm restart.

Works like a charm


I resolved the issue. Although I attempted a manual uninstall of the manually installed 361 driver, it failed to clean-up all the shared objects and so what I was experiencing was essentially a library problem.

After purging all NVIDIA packages using apt, I resolved this as follows:

  1. Locate all the 361 driver shared object files, excluding any trash folder, home folder and Steam games folder, by running:

    locate so.361.45 | egrep -vi "trash|steam|^/home"
    
  2. Remove the suspicious shared object files (some contain the word nvidia while others contain just nv).

  3. Run ldconfig.

  4. Run ldd $( which glxinfo ).

  5. Inspect the output of ldd and ensure that none of the entries point to any stale NVIDIA 361.45 shared objects.

  6. Reboot.

  7. Install the NVIDIA 364 driver via apt.

  8. Reboot.