Ubuntu 16.04 stuck in login loop after attempting to install NVIDIA-Linux-x86_64-375.39.run

Recently my Ubuntu 16.04 system upgrade the driver from 375.26 to 375.39. After the upgrade, I began to encounter bad borders around popup windows. I filed a bug report https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-375/+bug/1667158 to launchpad nvidia-graphics-drivers-375-package.

To avoid the inconveniences caused by the issue, I purged the ppa that upgraded my graphic driver so that I could use the graphic driver from ubuntu repository. After doing so, my X-window started to become blur after a few second following any screen event. This was worst.

So I tried to purge my system of all nvidia driver and to reinstall the 375.39 driver using Nvidia supplied .run file. There was some issue during the installation. When I rebooted, I ended getting stuck in a login loop.

I have described my issues in this post http://askubuntu.com/questions/887159/ubuntu-16-04-stuck-in-login-loop-after-attempting-to-install-nvidia-linux-x86-64.

After several failed attempts to install the .run file, because nouveau was still used by my system, I finally relented to using the nvidia ubuntu repository graphic driver 375.26 again. As described in my post, I do not even see a login window now. Instead I get a popup window informing me that i have to run in low graphics mode and the subsequent popup window with 4 follow-up action options don’t seem responsive.

.xsession-errors:

openConnection: connect: No such file or directory
cannot connect to brltty at :0
upstart: gnome-session (Unity) main process(2743) terminated with status 1
upstart: unity-settings-daemon main process (2735) killed by TERM signal
upstart: Disconnected from notified D-Bus bus
upstart: upstart-dbus-session-fridge main process (2659) terminated with status 1
upstart: bamfdaemon main process (2644) killed by TERM signal
upstart: hud main process (2733) killed by TERM signal
upstart: unity7 prestart process(2737) terminated with status 143
upstart: logrotate main process (2540) killed by TERM signal
upstart: unity-panel-service main process (2750) killed by TERM signal

Can someone help me regain access to my X window? I need to use the nvidia graphic driver as I need to use CUDA.

.xsession-errors

openConnection: connect: No such file or directory
cannot connect to brltty at :0
upstart: gnome-session (Unity) main process(32699) terminated with status 1
upstart: unity-settings-daemon main process (32691) killed by TERM signal
upstart: Disconnected from notified D-Bus bus
upstart: logrotate main process (32449) killed by TERM signal
upstart: upstart-dbus-session-bridge main process (32570) terminated with status 1
upstart: hud main process (32689) killed by TERM signal
upstart: bamfdaemon main process (32566) killed by TERM signal
upstart: unity7 pre-start process(32693) terminated with status 143
upstart: indicator-bluetooth main process (32738) killed by TERM signal
upstart: indicator-power main process (32739) killed by TERM signal
upstart: indicator-datetime main process (32740) killed by TERM signal
upstart: indicator-keyboard main process (32744) killed by TERM signal
upstart: indicator-application main process (308) killed by TERM signal
upstart: indicator-network pre-start process (303) terminated with status 1

After viewing /var/log/syslog and /var/log/kern.log I found the following kernel issue:

NVRM: API mistmatch: the client has version 375.26, but
NVRM: this kernel module has the version 375.39. Please 
NVRM: make sure that kernel module and all NVIDIA driver
NVRM: components have the same version.

I found http://askubuntu.com/questions/342664/nvidia-driver-updated-mixed-versions-of-304-88-and-319-32 describing the same problem. To avoid the confusion, I ran command:
dpkg -l | grep nvidia
sudo apt-get autoremove nvidia375
sudo apt-get --purge remove nvidia*
dpkg -l | grep nvidia

Output from last command confirmed no nvidia packages are installed. Thereafter, I ran:
sudo update-grub
sudo update-initramfs -u
sudo reboot

However, I am still experiencing the same issue. Low graphics mode and kernel and syslog still complaining client has 375.26 and server has 375.39. Can any help?

I found the nvidia modules read in by the kernel using this command.

$ lsmod | grep nvidia
module            size    used by
nvidia_drm        53248   0
nvidia_modeset   790528   1 nvidia_drm
nvidia         12144640   1 nvidia_modeset
drm_helper       155648   2 i915_bpo,nvidia_drm
drm              364544   4 i915_bpo,drm_helper,nvidia_drm

Command “modinfo module_name” showed these modules are located in folder /lib/modules/4.4.0-64-generic/updates/dkms/, their filenames are nvidia-drm.ko, nvidia-modeset.ko and nvidia.ko, and their version is 375.39.

Why do these modules even exist after I have purged all nvidia packages? Should I remove them? If so, how?

I was able to resolve my issue by performing the following steps:

  1. First reinstall the nvidia-375 repository graphic driver.
    sudo apt-get install nvidia-375
    During the installation, I noticed that nvidia-375.26 driver was being installed.

  2. I moved the entire /lib/modules/4.4.0-64-generic/updates/dkms folder to my home directory backup folder. This was to make sure all old .ko files were removed.
    cp -R /lib/modules/4.4.0-64-generic/updates/dkms ~/backup

  3. I regenerated the .ko files for the installed driver using
    sudo dpkg-reconfigure nvidia-375
    It created a new dkms folder with the relevant nvidia kernel modules. I also checked their version using command:
    sudo modinfo nvidia_375.ko
    sudo modinfo nvidia_375_drm.ko
    sudo modinfo nvidia_375_modeset.ko
    sudo modinfo nvidia_375_uvm.ko
    Their output showed that they were for version 375.26.

  4. I rebooted the system with
    sudo reboot

Adapted from [url]https://devtalk.nvidia.com/default/topic/525877/linux/api-mismatch-means-ubuntu-can-39-t-boot-i-can-39-t-fix-i-please-help-/1[/url]

Hi sunbearc22

I encounter the similar problem, and your reconfiguration method works for me. Thanks.

Best regards
George Liao