1. Home
  2. Linux

How To Fix The NVIDIA Resume Bug On Elementary OS Loki

Elementary OS Loki is a really solid Linux distribution, but when using it with the Nvidia proprietary drivers, users sometimes run into an irritating bug coming out of the suspend state. As of right now, the Nvidia resume bug on Elementry OS Loki persists, and users in the community are trying to figure out why.

Our solution to fixing Nvidia resume bug isn’t 100% solid. Even after setting up this fix, you may still run into these issues. The fix itself relies on using the systemd init system in Elementary OS to reset the window manager.

You may notice the Gala window manager failing to reset. If the service refuses to work, consider deleting the files and starting again, or manually running this in the Wingpanel application launcher:

gala --replace

Attempt at your own risk.

Writing The Script

Before creating a sleep hook within systemd, a script is required. This is due to the fact that you can’t exactly write the commands directly inside of the service file. Instead, open up a terminal window on your Elementary OS desktop, and gain root access using sudo -s.

With the root terminal, open up the nano text editor.

nano /usr/bin/pantheon-wm-refresh.sh

The following command will make a new SH file ready to be saved inside of the /usr/bin/ directory. From here, paste the following code at the top of the file. This code is important, as it will set the environment that the script runs in. Without this line, everything will fail.

#!/bin/bash

With the shebang at the top of the script, the SH file has the everything necessary for the interpreter to read it. Now, it’s time to add the rest of the command arguments. Let’s start off by specifying the default display. This is to ensure that the window manager refreshes on the right screen.

export DISPLAY=:0

Directly after “export DISPLAY=:0”, we can specify the command that will force the Pantheon desktop environment to reset the window manager when it comes out of resume. The command is a simple command that will tell the Elementary OS’s window manager (known as Gala) to replace itself.

gala --replace

With the last command written into the shell script, it’s time to save. Do Ctrl + O to save everything in nano. After saving, update the permissions of the file so that it can execute as a program:

chmod +x /usr/bin/pantheon-wm-refresh.sh

Creating A Systemd Service

The next step in the process to fixing the dreaded Nvidia resume bug is to create what is known as a “sleep hook”. This is a service that can execute within systemd when the user returns from “sleeping”. To get started, once again we’ll need the nano text editor. Ensure that your terminal still has root access. If not, use sudo -s to gain root, and open a new file with:

nano /etc/systemd/system/resume@.service

Inside of the “resume@.service” file, paste the following:

[Unit]
Description=User resume actions
After=suspend.target

[Service]
User=%I
Type=simple
ExecStart=/usr/bin/pantheon-wm-refresh.sh

[Install]
WantedBy=suspend.target

Save the new systemd file with Ctrl + O, and then use the systemctl command to enable this new service within the init system.

systemctl enable resume@user

and

systemctl start resume@user

From here, each time you resume your PC from suspend, the Pantheon window manager will be refreshed. This will prevent the annoying glitchy screen problem that occurs on some Nvidia proprietary GPU drivers running Elementary OS.

Other Troubleshooting Options

Update Drivers

Try our solution above and nothing works? Consider doing one of these two things. The first thing to do would be to get the absolute latest version of the Nvidia proprietary drivers installed on your Elementary OS system. This starts out by installing software that enables PPA use on the operating system.

sudo apt install software-properties-common

Then, add the regularly updated driver PPA with:

sudo add-apt-repository ppa:graphics-drivers/ppa

From here, open up the Elementary OS Software center, search for “additional drivers”, click install and launch it (if you don’t have it already). Deselect the current version of the Nvidia proprietary driver you’re running, and install the absolute latest. This will update your system to the newest version of the drivers — something that may very well resolve annoying bugs.

Roll-back Drivers

If the fix, or updating Nvidia to the latest version didn’t help ,consider trying to roll-back the proprietary Nvidia drivers and use the Open Source Noveau drivers instead. Though not as effective as the ones straight from Nvidia, they won’t have the resume bug.

Replace Elementry OS Window Manager

If you’re dead-set on using the closed source drivers on Elementary OS, consider manually replacing the Elementary OS window manager with something else, like Mutter.

Mutter is a lightweight, nice looking window manager with similar visual effects. Simply run this command in the terminal:

sudo apt install mutter

Then, go to the system settings (or search for startup) and add: mutter –replace as a command. At startup, your PC will automatically replace Gala with Mutter. This is a crude solution, but it’ll get the job done.

Leave a comment