NVIDIA drivers and Ubuntu: an horror story
A short horror story (with a nice ending) featuring Ubuntu and NVIDIA drivers.
It is a widely accepted truth that NVIDIA and Linux are a bad combination. There are some stories about broken systems after drivers updates; I know a person who is afraid to update his system because of past horror experiences.
For the past 3 years my Ubuntu+NVIDIA experience has been quite smooth, until last week. I don’t really know what caused it, but out of the blue my system stopped to be reliable after suspension. In this post I describe the symptoms and what I did to finally solve the problem.
After the unknown culprit update, my system started to behave like that:
- No lock screen video after resuming from suspension.
- Broken X11 after logging back in.
- No video in virtual TTY consoles (
- Occasional fails to resume from suspension (basically the system appeared as shut down) or to shutdown (stuck with black screen).
When my system became sick, I tried to get around the issues. The issues from 1 to 3 can be short-term solved without rebooting, by just using the system without video to log back in, and to use keyboard shortcuts to open a terminal and type something in it; for example:
- Press a key to resume from suspension.
- Type your password without video output.
- Use a keyboard shortcut to open a terminal.
- Restart your window manager, like
mutter --replace &or
xfwm4 --replace &.
- If needed, restart your compositor.
In my case, these operations were sufficient to resume a normal system state without losing the current session. The operations can be also done in a TTY virtual console, still without any video feedback.
This strategy—however—is not sustainable.
A super easy fix consists of disabling the proprietary NVIDIA driver and sticking with the noveau driver.
That is possible to do for free by removing any trace of NVIDIA from the system:
sudo apt purge \*nvidia\*.
It may also be needed to manually remove NVIDIA power management services:
sudo systemctl stop nvidia-suspend.service sudo systemctl stop nvidia-hibernate.service sudo systemctl stop nvidia-resume.service sudo systemctl disable nvidia-suspend.service sudo systemctl disable nvidia-hibernate.service sudo systemctl disable nvidia-resume.service
After a reboot, you have a system that works and uses the open source nouveau video driver. But you also have a system without hardware acceleration, which uses 90% of your CPU just for a video call.
Maybe we need to reach a peaceful agreement with the NVIDIA proprietary driver.
That is how I discovered the appropriate things to do and how I ended up with.
Experimenting (the horror part)
This is the horror part of the story. One day I decided to install the
nvidia-driver-515-open. The result was that the video was completely absent at boot.
Here is when I discovered that I could temporarily defer the initialization of the video driver, by adding a keyword in the Grub2 configuration. To do that at boot:
- Move to your OS entry on the Grub2 menu.
- Press the
ekey to enter in edit mode.
nomodesetat the end of the line that starts with
That fixed the black-screen problem and I could enter in my system.
The right plan (light bulb part)
Now that I knew that I could experiment with drivers and just use the
nomodeset trick to bypass any no-video issue, I decided to press the accelerator.
I found out that
ubuntu-drivers devices tells you not only the available drivers, but also the recommended one for your system.
- Cleanup everything NVIDIA from my system.
- Install the recommended driver.
- Eventually use the
nomodesettrick to revert in case of boot problems.
Finding peace with NVIDIA
I followed the plan by installing
nvidia-driver-515 and I basically restored the initial starting configuration with the broken power management.
But booting with
nomodeset fixed the power management issues.
Hence, the solution was easy: make the
nomodeset trick permanent.
sudo vim /etc/default/grub.
nomodesetat the end of
- Save and exit.
- Refresh the configuration with
That fixed everything.
The take-home message from this experience is that, if you have problems with NVIDIA cards:
- Cleanup everything related to NVIDIA.
- Install the recommended proprietary driver for your system.
- Add the
nomodesetparameter to the boot options.
Step 3 may be different according to the specific video card: there are other kernel flags that can be played with if
nomodeset doesn’t work.