Ubuntu – Ubuntu can’t login after set LD_LIBRARY_PATH for CUDA

cudadriversgraphicsnvidiaxorg

I'm having a problem with my configuration of LD_LIBRARY_PATH environment variable for UBUNTU.

My system configuration is the following: UBUNTU 17.10 CUDA 8.0 (required by Tensorflow) NVIDIA DRIVER 387.26

My current LD_LIBRARY_PATH is set as follow in the .profile file: export LD_LIBRARY_PATH="/usr/lib/nvidia-387:/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"

I had to include also /usr/lib/nvidia-387 because of this

I also had to set my primary graphic controller to "INTEL" because I wanted my GPU free from any other graphic process (basically I run sudo prime-select intel)

However when /usr/lib/nvidia-387 is set I can't login to my profile anymore: after password input I just get a black screen for several seconds, and I eventually return to the login screen.

I also attach my current XORG conf (copied and pasted from other similar topic).

Section "ServerLayout"
  Identifier "layout"
  Screen 0 "nvidia"
  Inactive "intel"
EndSection

Section "Device"
  Identifier "intel"
  Driver "modesetting"
  BusID "PCI:0@0:2:0"
  Option "AccelMethod" "None"
EndSection

Section "Screen"
   Identifier "intel"
   Device "intel"
EndSection

Section "Device"
   Identifier "nvidia"
   Driver "nvidia"
   BusID "PCI:1@0:0:0"
   Option "ConstrainCursor" "off"
EndSection

Section "Screen"
   Identifier "nvidia"
   Device "nvidia"
   Option "AllowEmptyInitialConfiguration" "on"
   Option "IgnoreDisplayDevices" "CRT"
EndSection

Any idea how to solve? It's important that I keep the LD_LIBRARY_PATH as is.

Thank you for your help.

Best Answer

I didn't solve the problem. But I have a workaround for you.

1. edit /etc/default/grub

Modify GRUB_CMDLINE_LINUX_DEFAULT to

GRUB_CMDLINE_LINUX_DEFAULT='pcie_port_pm=off acpi_backlight=none acpi_osi=Linux acpi_osi=! acpi_osi="Windows 2009"'

This step is to prevent blank screen after logging in.

2. move nvidia library directories to /etc/ld.so.conf.d/nvidia.conf

The content of nvidia.conf is

/usr/lib/nvidia-390
/usr/lib32/nvidia-390

These directories depends on driver version on your computer.

3. create /etc/init.d/nvidia

To disable and enable nvidia runtime libraries.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          nvidia 
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     5
# Default-Stop:      0 6
# Short-Description: load/unload nvidia library
# Description:       load/unload nvidia library
### END INIT INFO

PRIME=$(prime-select query)
if [ "$PRIME" = "nvidia" ]; then
    exit 0
fi

case "$1" in
  start)
    sleep 10
    cd /etc/ld.so.conf.d
    mv nvidia.conf.bak nvidia.conf
    ldconfig
    nvidia-smi
    ;;
  stop)
    cd /etc/ld.so.conf.d
    mv nvidia.conf nvidia.conf.bak
    ldconfig
esac

4. execute update-rc.d nvidia defaults

You should find SXXnvidia in /etc/rc5.d/ and KXXnvidia in /etc/rc6.d/, /etc/rc0.d/.

Try to execute /etc/init.d/nvidia stop and nvidia-smi, you should see error messages of libraries not found.

Try to execute /etc/init.d/nvidia start, then nvidia-smi is fine again.

If everything is OK, you can reboot now. You are expected to login to desktop.

5. If anything goes wrong

The most possible problem is nvidia script not executed. If it happens, you can press Ctrl+Alt+F1 to tty mode, execute /etc/init.d/nvidia stop; reboot. Then you can go back to unity desktop to debug.

6. known side-effect

When use intel as prime GPU, unity-control-center(system settings) will be failed to start.

GLib-CRITICAL **: g_strsplit: assertion `string != NULL' failed.

Note: my system spec

# uname -r
4.13.0-32-generic
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial
# dpkg -l | grep cuda
ii  cuda-9-0                                    9.0.176-1                                    amd64        CUDA 9.0 meta-package
ii  cuda-command-line-tools-9-0                 9.0.176-1                                    amd64        CUDA command-line tools
ii  cuda-core-9-0                               9.0.176-1                                    amd64        CUDA core tools
ii  cuda-cublas-9-0                             9.0.176.1-1                                  amd64        CUBLAS native runtime libraries
ii  cuda-cublas-dev-9-0                         9.0.176.1-1                                  amd64        CUBLAS native dev links, headers
ii  cuda-cudart-9-0                             9.0.176-1                                    amd64        CUDA Runtime native Libraries
ii  cuda-cudart-dev-9-0                         9.0.176-1                                    amd64        CUDA Runtime native dev links, headers
ii  cuda-cufft-9-0                              9.0.176-1                                    amd64        CUFFT native runtime libraries
ii  cuda-cufft-dev-9-0                          9.0.176-1                                    amd64        CUFFT native dev links, headers
ii  cuda-curand-9-0                             9.0.176-1                                    amd64        CURAND native runtime libraries
ii  cuda-curand-dev-9-0                         9.0.176-1                                    amd64        CURAND native dev links, headers
ii  cuda-cusolver-9-0                           9.0.176-1                                    amd64        CUDA solver native runtime libraries
ii  cuda-cusolver-dev-9-0                       9.0.176-1                                    amd64        CUDA solver native dev links, headers
ii  cuda-cusparse-9-0                           9.0.176-1                                    amd64        CUSPARSE native runtime libraries
ii  cuda-cusparse-dev-9-0                       9.0.176-1                                    amd64        CUSPARSE native dev links, headers
ii  cuda-demo-suite-9-0                         9.0.176-1                                    amd64        Demo suite for CUDA
ii  cuda-documentation-9-0                      9.0.176-1                                    amd64        CUDA documentation
ii  cuda-driver-dev-9-0                         9.0.176-1                                    amd64        CUDA Driver native dev stub library
ii  cuda-drivers                                390.12-1                                     amd64        CUDA Driver meta-package
ii  cuda-libraries-9-0                          9.0.176-1                                    amd64        CUDA Libraries 9.0 meta-package
ii  cuda-libraries-dev-9-0                      9.0.176-1                                    amd64        CUDA Libraries 9.0 development meta-package
ii  cuda-license-9-0                            9.0.176-1                                    amd64        CUDA licenses
ii  cuda-misc-headers-9-0                       9.0.176-1                                    amd64        CUDA miscellaneous headers
ii  cuda-npp-9-0                                9.0.176-1                                    amd64        NPP native runtime libraries
ii  cuda-npp-dev-9-0                            9.0.176-1                                    amd64        NPP native dev links, headers
ii  cuda-nvgraph-9-0                            9.0.176-1                                    amd64        NVGRAPH native runtime libraries
ii  cuda-nvgraph-dev-9-0                        9.0.176-1                                    amd64        NVGRAPH native dev links, headers
ii  cuda-nvml-dev-9-0                           9.0.176-1                                    amd64        NVML native dev links, headers
ii  cuda-nvrtc-9-0                              9.0.176-1                                    amd64        NVRTC native runtime libraries
ii  cuda-nvrtc-dev-9-0                          9.0.176-1                                    amd64        NVRTC native dev links, headers
ii  cuda-repo-ubuntu1604                        9.1.85-1                                     amd64        cuda repository configuration files
ii  cuda-runtime-9-0                            9.0.176-1                                    amd64        CUDA Runtime 9.0 meta-package
ii  cuda-samples-9-0                            9.0.176-1                                    amd64        CUDA example applications
ii  cuda-toolkit-9-0                            9.0.176-1                                    amd64        CUDA Toolkit 9.0 meta-package
ii  cuda-visual-tools-9-0                       9.0.176-1                                    amd64        CUDA visual tools
ii  libcuda1-390                                390.12-0ubuntu1                              amd64        NVIDIA CUDA runtime library
ii  libcudnn7                                   7.0.5.15-1+cuda9.0                           amd64        cuDNN runtime libraries
ii  libcudnn7-dev                               7.0.5.15-1+cuda9.0                           amd64        cuDNN development libraries and headers
# dpkg -l | grep nvidia
ii  nvidia-390                                  390.12-0ubuntu1                              amd64        NVIDIA binary driver - version 390.12
ii  nvidia-390-dev                              390.12-0ubuntu1                              amd64        NVIDIA binary Xorg driver development files
ii  nvidia-modprobe                             390.12-0ubuntu1                              amd64        Load the NVIDIA kernel driver and create device files
ii  nvidia-opencl-icd-390                       390.12-0ubuntu1                              amd64        NVIDIA OpenCL ICD
ii  nvidia-prime                                0.8.2                                        amd64        Tools to enable NVIDIA's Prime
ii  nvidia-settings                             390.12-0ubuntu1                              amd64        Tool for configuring the NVIDIA graphics driver