Fix Blank Screen Nvidia Optimus Laptop Linux and Cuda
Kali Linux Nvidia Blank Screen Optimus Laptop

Fix Blank Screen Nvidia Optimus Laptop Linux and Cuda

By 0fajarpurnama0 | 0fajarpurnama0 | 12 Oct 2020


Checklist

I assumed that you got your laptop running and the only thing left is installing Nvidia video driver to perform more advance tasks such as playing video games and parallel processing. Simply, the checklist is knowing your video graphic card and which driver version suits it. For example, my laptop graphic card is Nvidia 720M which has a compute capability of 2.x Fermi. Therefore, the highest Nvidia driver version that supports is 390s and finally the highest cuda version is 8.0 where higher versions are not supported.

Find your card's compute capability at https://en.wikipedia.org/wiki/CUDA or check using their website https://www.nvidia.com/download/index.aspx?lang=en-us.

Nvidia Card Compute Capability Table

Go to https://docs.nvidia.com/deploy/cuda-compatibility/index.html and check which cuda version supports base on Nvidia driver version.

Cuda Nvidia Driver Version Compatibility

Go to https://docs.nvidia.com/deploy/cuda-compatibility/index.html and check which cuda version supports base on compute capability. If it is 2.x Fermi or lower, you have to try Cuda 8 and lower if it still does not work. 

Compute Capability to CUDA Nvidia Driver Table

Restore Default

This section is for those who have tried and failed and neeeded to restore the default installation. If you think you do not need this section, go ahead and do so. Still, starting here will be using full terminal in administrator mode and not GUI. If you messed up bad, try pressing ctrl+alt+f2 (try all f1-f12 until you are presented with a terminal). The concept is find all the Nvidia, Cuda, Primus, Bumblebee, and any packages that you just installed and uninstall them and finally reinstall Nouveau. Here I use aptitude to see the packages.

sudo su
apt install aptitude
aptitude search nvidia
aptitude search cuda
aptitude search bumblebee
aptitude search primus

Uninstall all of them one by one or try the following command line and if the following command does not work then uninstall them one by one.

apt-get purge 'nvidia.*'
apt-get purge 'cuda.*'
apt-get purge 'bumblebee.*'
apt-get purge 'primus.*'

Check again using aptitude and after everything is uninstalled, install Nouveau.

apt-get install 'nouveau.*'

Check modprobe configuration directory (/etc/modprobe.d etc), move all files associated with Nvidia to another directory, and check all remaining files whether Nouveau is blacklisted and if so remove the blacklist. Finally, restart your laptop.

Install Nvidia Video Driver

Most of the time is best practice to update and upgrade your system:

apt update
apt full-upgrade

Before continuing, you can checked your video cards information and driver installed using the following commands:

lspci -v

The general way to install nvidia driver in Linux is to install nvidia-kernel-dkms. I recommend to install nvidia-smi as well if it is not included in the installation as it is on of the best way to see whether the driver is working or not.

apt install nvidia-kernel-dkms
apt install nvidia-smi

I recommend to reboot to see whether this step is problematic or not. If you are using an older Optimus Laptop like me with Intel HD Graphic and Nvidia, the probability is high that Nvidia driver will not work and will leave you with blank screen. If you have internet connection through LAN cable or USB tethering than there is no fear of rebooting as you can easily connect to the Internet. If you use WiFi than it can be challenging setting up Internet using the command line so I recommend to learn how to do it first. If you are already sure that it will be a blank screen, then do not reboot and proceed to the next step.

reboot

Fixing Blank Screen After Nvidia Driver Installation

If in the end you are left with a blank screen then press ctrl+alt+f2 (try from f1-f12) to start the console. Once you are successful, connect to the Internet and check the version of the installed nvidia package.

apt show nvidia-kernel-dkms

Go back to the check list section and see whether the driver version supports your card or not. In my case, the driver installed is the latest version that does not support my old GT720M. The highest that supports is 390. Therefore search for suitable nvidia driver version in your package manager. If you cannot find a suitable version in you package manager then you have to download manually from Nvidia website. Usually, when trying to install, the previous version that you installed will be replace but if it does not then purge it manually.

aptitude search nvidia
apt install nvidia-legacy-390xx-kernel-dkms
reboot

If the last step still does not work then try either or both of the following steps. The first step is to install opencl where I found this step on Kali Linux Website.

apt install mesa-opencl-icd
reboot

and/or

apt install nvidia-opencl-icd
reboot

If everything works for you, then congratulations. As for my laptop, it only fixes the blank screen but Nvidia driver does not work when playing video games and performing parallel processing. The following solution fixes my problem and if it does not work, try to purge the opencls if you have installed. Bumblebee and bbswitch are packages for laptops that have multiple graphic cards.

apt install bbswitch-dkms bumblebee-nvidia
nano /etc/bumblebee/bumblebee.conf
nano /etc/bumblebee/xorg.conf.nvidia
reboot

If everything succeeded, well done, if not then I do not know anymore ways for now so do comment if you found another way. Check everything:

lspci -v
nvidia-smi
lsmod
glxgears
glxdemo
glxinfo

Install Cuda Toolkit

If you want it quick, you can try installing from package manager but do check whether the versions suits your Nvidia card or not:

apt show nvidia-cuda-toolkit
apt install nvidia-cuda-toolkit
nvcc -V
type nvcc
ls /usr/lib/nvidia-cuda-toolkit

For my case, the nvidia-cuda-toolkit version is to high. My Geforce 720M can only handle up to CUDA 8, so I have to go to https://developer.nvidia.com/cuda-toolkit-archive and get the suitable version.

dpkg -i [your deb package].deb
apt-key add /var/cuda...../[...].pub (which will be shown on your terminal)
apt update && apt install cuda-toolkit-8-0

Edit /etc/environment, edit and add the following lines:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda/bin"
LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib"
reboot
nvcc -V

CUDA 8 support GCC and G++ up to version 5 and not higher. So follow the instruction from https://unix.stackexchange.com/questions/384780/how-to-temporarily-change-default-version-of-gcc-in-archlinux

apt install gcc-5 g++-5
sudo ln -s $(which gcc-5) /usr/local/bin/gcc
sudo ln -s $(which g++-5) /usr/local/bin/g++
hash -r

To restore default GCC:

sudo rm /usr/local/bin/gcc /usr/local/bin/g++
hash -r

If you are using Ubuntu or any distros mentioned on their website, it will be smoother to download install the deb package instead. If you have to use the run file, then do the following and finally check the logs if any errors persists.

sudo chmod +x cuda_8.0.61_375.26_linux.run
sudo sh cuda_8.0.61_375.26_linux.run --override
Follow the command-line prompts

Do you accept the previously read EULA?
accept/decline/quit: accept

You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: yes

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: no

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: yes

Enter Toolkit Location
 [ default is /usr/local/cuda-8.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: yes

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: yes

Enter CUDA Samples Location
 [ default is /home/fajarpurnama ]: /usr/local/cuda-8.0/samples
Edit /etc/environment, edit and add the following lines:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda/bin"
LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib"

If you are on older cards, you need to search the suitable cuda version or maybe your card are not supported at all. For example, I once come across ancient cards of GTS250 and GT8800 with compute capability of 1.1 Tesla and the cudatoolkit that supports is 6.5.

How do you rate this article?


39

0

0fajarpurnama0
0fajarpurnama0

I'm a content creator who is interested in financial freedom, decentralization, internet, computer, censorship resistance, unconfiscateable, cryptocurrency, monetization, passive income, and referrals.


0fajarpurnama0
0fajarpurnama0

This blog contains all my articles of various categories which I will separate in the future once a category becomes big. This blog along with other online contents are licensed under creative commons attribution customized sharealike (cc-by-sa) where I Fajar Purnama as the creator customized the ShareAlike (sa) license here where you are also allowed to sell my contents but with a condition that you must mention that the free and open version is available here.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.