My Ubuntu Linux boots into a black screen: GUIDE


HELP! My Linux computer was working fine and today after I rebooted, it would not longer boot to a GUI, or it boots to a black screen, or it boots into the terminal, or I have no display acceleration and the best resolution I can do is 1024×768

This guide is for troubleshooting GPU / driver issues assuming your GPU used to work, and now it does not (e.g. after an upgrade, a reboot, etc).

It’s not written to troubleshoot why your brand new GPU you just installed doesn’t work, however some of these steps may still help you or be of use.

It’s also written mostly AMDGPU and Ubuntu 18.04/20.04/22.04 centric; however some advise is generic and applies to other GPUs or other distros.

Before we begin…

If you’re reading this, then your graphical interface is very limited. Or you boot into a blackscreen.

You’ll need to execute commands. But your system appears dead.

Therefore three things are of utter importance:

1. You can switch to a virtual terminal

Hitting Ctrl+Alt+F2 should switch you to virtual terminal. You should be able to switch back to the GUI via Ctrl+Alt+F7 (though sometimes it is Ctrl+Alt+F1)

2. Install OpenSSH server

You can install OpenSSH via:

sudo apt install openssh-server

I won’t cover how to setup an SSH server since there are plenty of tutorials online.

If you have no display, you can try booting into recovery, and install openssh-server from there.
Then reboot (sudo shutdown -r now).

Thanks to SSH, you will be able to control the computer from a 2nd computer which is important if your keyboard is not responsive, or you have no display at all.

Furthermore, from the client, you can mount your entire filesystem remotely:

sudo mkdir -p /mnt/my_server
sudo chown /mnt/my_server $USER:$USER
sshfs username@192.168.1.128:/ /mnt/my_server -o default_permissions,idmap=user
# Or alternatively if it's password-based
sshfs username@192.168.1.128:/ /mnt/my_server -o default_permissions,idmap=user,PreferredAuthentications=password

Where username is the username of your account in the server, and I assume 192.168.1.128 is the IP address of your server.

This makes navigating towards your log files much easier, from a comfy 2nd computer with a full GUI.

3. If VIM or EMACS isn’t for you…

The default text editors are Vim and Emacs. I hate them both equally.

If all you need is something basic and you come from a DOS or Windows background, then install Tilde.

sudo apt install tilde

You’ll find Tilde to be much more user-friendly for editing config files via terminal.

Of course if you are comfortable with Vim or Emacs, then use that.

Do I need to install GPU drivers? Where do I get them from?

If you have an Intel or AMD GPU, the answer is: NO.

If you have an NVIDIA GPU: the answer is yes.

On Linux, both Intel and AMD GPU drivers are Open Source, high quality, and included with the default installations of (almost?) every distro.

AMD has a proprietary driver called AMDGPU-Pro (note the Pro suffix, because the Open Source driver is called AMDGPU. Yes I know, super confusing).

You can try installing AMDGPU-Pro but I don’t recommend it since a lot of users end up having trouble with it, and if you’re not fluent with the CLI, it gets hard to restore a graphical interface if things go wrong. It’s a hit or miss. And they often will only work on LTS distros.

The reasons to install AMDGPU-Pro are very specific (you need better OpenCL support, your GPU literally came out yesterday thus is not yet supported by the Open Source driver, you need a specific feature, etc).

Anatomy of Open Source drivers

IMPORTANT: This section does NOT apply to NVIDIA drivers, unless you use Optimus.

Linux Open Source drivers consist of various parts:

Kernel Space module

This component is tied to Kernel versions. That’s why downgrading/upgrading a Kernel version may fix your problem.

The AMD drivers bundled with the kernel are radeon and amdgpu:

  • radeon driver is an older one written to work with Radeon HD 2000-6000 series and first- and second-generation GCN cards (e.g. Radeon HD 7770, Radeon R9 280, etc).
  • amdgpu driver is a newer driver that works with all GCN and RDNA chips. If your GPU is too new (e.g. Radeon RX 560, Vega, Radeon RX 5700, or Radeon RX 6800 XT) this is the only driver you can use.

On Intel the driver for all Intel GPUs is called i915. Do not confuse this with i965 which is an old user-space OpenGL driver (currently being replaced by Crocus for old HW, and Iris for new HW).

Userspace: libdrm

Note: DRM here stands for Direct Rendering Manager. It has nothing to do with Digital Rights Management. This is a key component for rendering.

In Ubuntu this is provided by:

sudo apt install --reinstall libdrm2

This package is very important. It’s the interface between user space and the kernel driver. It’s used when switching resolution, setting up new screens, multiple monitors.

If a distro maintainer screwed up, they may have upgraded the Kernel version but forgot to update libdrm which added support for the new driver features or changes in the new Kernel; which can cause your display to fail. Though this should be rare.

Sometimes the opposite can happen and libdrm got upgraded and tries to use a feature the current Kernel does not provide. This should never happen since libdrm should detect the presence of missing features and avoid them. But if everything would be perfect, your display wouldn’t have shown up black, would it?

Userspace: Mesa

Mesa is a big project. As a project, it has a lot of components: OpenGL drivers, DRM, Vulkan, VAAPI and more. However often when we talk about “Mesa”, we are referring about the OpenGL drivers or the Vulkan ones.

I’m gonna skip Vulkan since, at the time of writing, it is not necessary to boot into Graphical Mode.

IIRC the main packages are these:

sudo apt install --reinstall libgl1-mesa-glx libgl1-mesa-dri libglx-mesa0 libgbm1 libglu1-mesa

If your OpenGL libraries are corrupt, it could cause your DM (Desktop Manager) to fail to start.

Userspace: X11 drivers

sudo apt install --reinstall xserver-xorg-video-amdgpu xserver-xorg-video-ati xserver-xorg-video-radeon xserver-xorg-video-intel

I heard that there is a PPA…

If your GPU was working fine, and now isn’t; do not try a PPA like Kisak’s.

This will only make things worse. You need to rollback something that went wrong. PPAs will override lots of packages with newer versions, and if you are unlucky it may be hard to uninstall them.

The main reason to use a Mesa PPA is because you just bought a new GPU not yet supported by your distro version; or because you want the latest Mesa version with fixes and improvements for playing games.

Solutions

Try an older kernel.

Go to GRUB -> Advanced options for Ubuntu and select and older kernel.

Make sure it’s an older kernel via:

uname -r

If this works, then submit a bug to Canonical via apport, and in the meantime freeze your Kernel package via Synaptic or install a newer mainline kernel.

Check your X11 logs

Your X11 logs should be in /var/log/Xorg.0.log

You can use cat /var/log/Xorg.0.log or less /var/log/Xorg.0.log to navigate it.

It usually tells you why the X11 server failed to launch.

This of course, will not apply if you use Wayland. And I’m unfamiliar with Wayland.

Check your system logs

More logs you should check are:

  • /var/log/kern.log
  • /var/log/syslog
  • sudo dmesg

Check the logs of your DM (Desktop Manager)

There are 3 popular DMs in Ubuntu (though there are more): lightdm, gdm3, and sddm.

You only need to check the logs for your DM. Not all 3:

  • journalctl -u lightdm
  • journalctl -u gdm3
  • journalctl -u sddm

If the logs are too big, you can try appending -b to show the logs from last boot. i.e. journalctl -u lightdm -b

Check multiple userspace Mesa drivers aren’t installed

Mesa drivers may be installed in multiple places:

  1. /usr/lib/x86_64-linux-gnu/ (general OpenGL & Vulkan libs like libdrm.so, libGL.so, libvulkan_radeon.so)
  2. /usr/lib/x86_64-linux-gnu/dri (specific drivers like radeonsi_dri.so & i915_dri.so)
  3. /usr/local/lib/x86_64-linux-gnu/
  4. /usr/local/lib/x86_64-linux-gnu/dri
  5. /opt/amdgpu/
  6. /opt/amdgpu-pro/

The system installation (e.g. Ubuntu’s default packages) are in /usr/lib/x86_64-linux-gnu/ and /usr/lib/x86_64-linux-gnu/dri.

However if you accidentally installed specific packages (e.g. ROCm, Mesa from source code, etc), you may have lingering drivers in those other locations that are being picked up.

If you’ve upgraded your system or kernel, those alternate versions (the ones in /usr/local and /opt) may not be compatible anymore. Remove them (always backup first).

Make sure amdgpu module is loaded

Run:

lsmod | grep amdgpu

It should have hits and amdgpu should be in use.

If it’s not there then run:

sudo modprobe amdgpu

If that fails, check dmesg.

Restart your DM

Sometimes there is a race condition in loading your drivers, and the real problem is that your DM started before your GPU drivers were ready. So the DM crashed.

I’ve personally ran into this problem: Half of the time, at random, I would boot into a black screen and the keyboard would be dead. However the following command from an SSH session would restore my computer.

I don’t know which DM you use so one of these commands should be the one for you:

sudo service lightdm restart
sudo service gdm3 restart
sudo service sddm restart

Add amdgpu firmware to initramfs so it’s available early

This is a fix to the mentioned race condition in the previous item.

Run the following:

echo "amdgpu" | sudo tee --append /etc/initramfs-tools/modules
sudo update-initramfs -c -k $(uname -r)

You can check if you’ve done this properly by running:

lsinitramfs /boot/initrd.img-$(uname -r) | grep amdgpu

This should return multiple hits (where previously there should have been none).

Then reboot and cross fingers things work.

You can undo this change by removing the amdgpu line from /etc/initramfs-tools/modules and running update-initramfs again.

If you are not in Ubuntu, in Arch it is known as Early KMS.

Try another firmware package

The package linux-firmware provides all the firmware blobs for your HW, including AMD’s and Intel GPUs (note: this does not apply to proprietary NVIDIA GPUs).

An older version may fix your problems, or a newer one.

You can also try the latest ones from https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git

Unpacking them, then sudo make install.

Make sure to backup your /lib/firmware folder first.

You can rollback the latest ones from git via sudo apt install --reinstall linux-firmware (since they are all files that go into /lib/firmware).

Sometimes newer/older firmware fixes problems like your system randomly hanging up, or the system locking up when going into suspend or resuming from it.

Check from a LiveUSB

If you stil are unable to fix it; create a LiveUSB and boot from there: You may be tempted to reinstall Ubuntu (a valid option).

If the LiveUSB shows the same problem, you may have to consider HW damage (your iGPU is malfunctioning, or the cable to your monitor is bad, the cable is loose, or your monitor is bad, or the connector/port is). If this is the case, try Windows as well.

NVIDIA specific

The user experience on Linux with NVIDIA cards is a terrible one.

Once upon a time they were the best choice because the Open Source drivers were in a very sorry state. But it’s been almost a decade since the tables have turned.

This is because NVIDIA insists on overriding the whole Linux rendering infrastructure with their own stuff. The Windows equivalent would be if NVIDIA drivers tried to force-uninstall DirectX, DXGI & WDDM and install their own DLLs.

No one would think that’d be a good idea on Windows, but NVIDIA somehow thinks it’s a fine idea to do on Linux.

As a result, everything works fine until it doesn’t, for example because:

  • You upgraded the kernel
  • You wanted to use Wayland
  • You upgraded the X11 server
  • You upgraded the Wayland server
  • You have more than one GPU
    • This is worse if it’s not an NVIDIA GPU, because NVIDIA drivers must override all Mesa & DRM stuff but only for the NVIDIA GPU, as it can’t actually uninstall Mesa because it’s needed by the other GPU
  • You have more than one monitor
  • Mesa drivers were updated (which may once again override NVIDIA’s version)

Having that said. There are a few things you need to be aware of:

There’s 2 drivers

NVIDIA GPUs have 2 drivers:

  • nouveau: An Open Source driver, that frankly, it’s absolute dogshit. It works like crap. Do not use this unless you have to.
    • It’s not the developers fault. The AMD and Intel FOSS (Free and Open Source Software) drivers were written using very thorough public documentation provided by Intel & AMD. Intel in facts allocates their own employees on that driver.
    • NVIDIA on the other hand has been very secretive, so the driver is written using reverse engineering.
    • NVIDIA locks out their HW on purpose using encryption keys, thus it runs very slowly because the clock speeds are locked out.
  • nvidia: The proprietary driver provided by NVIDIA.

Make sure you are not using nouveau:

lsmod | grep nouveau

That command should return no hit.

If your system is working very slowly, your screen suddenly fills with garbage, your system crashes often; you may be running on nouveau.

At the time of writing there is a new FOSS driver getting cooked called NVK. However it’s not ready for daily use so it’s not worth mentioning yet.

The drivers provided by Ubuntu are not exactly the same as the one provided by NVIDIA

Ubuntu conveniently provides *.deb packages to install proprietary NVIDIA drivers. This can be found in Software & Updates -> Additional Drivers

However if you have the following problems:

  • Can’t get multimonitor to work
  • Can’t get multiple (non-NVIDIA) GPUs to work
  • Can’t get DRI PRIME to work
    • i.e. __NV_PRIME_RENDER_OFFLOAD and __GLX_VENDOR_LIBRARY_NAME

You may have better luck using drivers downloaded and installed from https://www.nvidia.com/en-us/geforce/drivers.

The only issue with this approach is that Ubuntu upgrades may at some point undo the installation, so you have to run the installer again.

On some rare cases, the installer may break your Graphical GUI. Which often, but not always, gets fixed by running:

sudo ./NVIDIA-Linux-x86_64-525.xx.run --uninstall

I have an old GeForce 9800, how can I run Ubuntu 22.04 LTS?

Short version: You can’t.

Only nouveau will work (assuming it works at all).

NVIDIA has dropped support for older HW.

So the last driver they released will only work for the latest Ubuntu version at that time.