ubuntu – black screen on ubuntu laptop after installing nvidia drivers

the joy of using nvidia drivers on a ubuntu laptop

I’m running Ubuntu on my Lenovo Y50 laptop, with a Nvidia GPU. And every time I do an update (or restart it?), I see the Ubuntu logo, hear the chime to log in, and then see a blank black screen, or a small white dot in the upper corner.

Other times, after a reboot, I get to the login screen, enter my username and password, then everything flickers violently, and it loops back to asks me to enter in my info again.

Today this post is not about how to permanently fix this (although that would be nice), but rather how to get your GUI back (until you update/restart your machine again).

It seems that on some laptops, the Nvidia drivers and Ubuntu do not always nicely play together. Why? I am not sure.

But anyways, here’s how to get fix your laptop when Ubuntu has a black screen on login (assuming your problem is related to the Nvidia drivers).

1. Drop into the terminal from the login or blank screen

To drop into a terminal from the login (or blank screen), press these three keys: Ctrl-Alt-F1

You should see a prompt now to enter your username and password. Enter in your info to log in.

Basically, we are going to remove the Nvidia drivers, and reinstall them. This seems to fix everything and will get your GUI/desktop back. So let’s start.

2. Remove nvidia

Type in this command to remove the nvidia drivers from your system.
sudo apt-get purge nvidia*

3. Restart the machine

sudo reboot

After your reboot, your GUI should be back and you can log in now! Yay!


But wait, why do I now get this annoying popup message?

System program problem detected
Do you want to report the problem now?

You need to reinstall the Nvidia drivers. Here’s how to do this.

[side note]
You might be tempted to skip these steps and keep the default drivers. However, without doing the following, on Ubuntu the fan constantly ran as my laptop was quite hot. From this tread, I believe the issue is that both the GPU and the integrated graphics are consuming power, causing the machine to overheat. Supporting this, I notice as soon as I run the command sudo nvidia-smi, the fan slows down and the machine starts to cool.
[/end side note]

3. Install the Nvidia drivers

From the command line, type in (replace 370 with whatever version you want):
sudo apt-get install nvidia-370

Okay, we are getting close to being done!

4. Check the Nvidia drivers

Open a new terminal and type,
nvidia-smi

and you’ll probably get this error message:

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

Gah!

5. Initiate GPU activity as root user

Okay, it turns out we need to run this command as sudo for the first time. So from the command prompt, type:
sudo nvidia-smi

And you should see:

+------------------------------------------------------+
| NVIDIA-SMI 370.28 Driver Version: 370.28 |
|-------------------------------+----------------------+

with a bunch more info.

And you should be good to go again! Yay! (until next time…)


[update – Nov 28 2016]

I was installing the nvidia drivers like I usually do, and my computer crashed in the middle of the installation. I rebooted, and installed them again. However, nvidia-smi no longer came up after the installation. And when I ran it directly,
/usr/lib/nvidia-375/bin/nvidia-smi

I got an error that it could not find libnvidia-ml.so

I tried a few other things like switching to use nvidia prime:
sudo prime-select nvidia

and got this error:

Error: alternatives are not set up properly

Following the instructions from here, I did the following:
sudo update-alternatives --config x86_64-linux-gnu_gl_conf

and selected the option for the driver I just installed:
/usr/lib/nvidia-375/ld.so.conf

Then I was able to run the sudo nvidia-smi

Yay! (note I now switched it to auto, and it seems to still work – not sure if that matters)
[/end update]

Leave a Reply