Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NVIDIA Suspend fix
# Use systemd for managing NVIDIA driver suspend.
# https://download.nvidia.com/XFree86/Linux-x86_64/450.66/README/powermanagement.html
# https://forums.developer.nvidia.com/t/unable-to-set-nvidia-kernel-module-parameters/161306
# Please note: In Fedora Linux you may need to just install the xorg-x11-drv-nvidia-power pakage
# as sugested by @goombah88 in the comments below.
TMP_PATH=/var/tmp
TMPL_PATH=/usr/share/doc/nvidia-driver-460/
echo "options nvidia NVreg_PreserveVideoMemoryAllocations=1 NVreg_TemporaryFilePath=${TMP_PATH}" | sudo tee /etc/modprobe.d/nvidia-power-management.conf
sudo install --mode 644 "${TMPL_PATH}/nvidia-suspend.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/nvidia-hibernate.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/nvidia-resume.service" /etc/systemd/system
sudo install "${TMPL_PATH}/nvidia" /lib/systemd/system-sleep
sudo install "${TMPL_PATH}/nvidia-sleep.sh" /usr/bin
sudo systemctl enable nvidia-suspend.service
sudo systemctl enable nvidia-hibernate.service
sudo systemctl enable nvidia-resume.service
@GugPuc
Copy link

GugPuc commented Apr 28, 2021

Thanks man! This is the only place with a full working script with all commands. I was going crazy.

@Manah7
Copy link

Manah7 commented Jun 5, 2021

Thank you so much ! I spent several trying to figure out the problem, reinstalling linux kernels and DKMS, you save me!

Some keywords to help others people to find this script:
suspend systemd-logind disappeared
Unit nvidia-suspend.service not found.
laptop do not suspend when lid closed

@nkshirsagar
Copy link

nkshirsagar commented Jun 17, 2021

Thanks this helped me on a y540 legion

@teguhash
Copy link

teguhash commented Jul 7, 2021

thanks a lot! I can confirm this to work on razer blade 15. tho on nvidia-driver-465 the files are in different folders

@mubashirhanif
Copy link

mubashirhanif commented Jul 27, 2021

thanks a lot! I can confirm this to work on razer blade 15. tho on nvidia-driver-465 the files are in different folders

@teguhash can you please share where the files were? I ran a find command and couldn't find them in the system.

@teguhash
Copy link

teguhash commented Jul 27, 2021

hi @mubashirhanif.
i found the service files in/usr/share/doc/nvidia-driver-465/systemd/system. nvidia binary is in /usr/share/doc/nvidia-driver-465/systemd/system-sleep and nvidia-sleep.sh in /usr/share/doc/nvidia-driver-465/systemd/

@jamesbirtles
Copy link

jamesbirtles commented Aug 11, 2021

Using manjaro, all those files were already installed into the correct place (with the nvidia-utils package installed), it just needed the modprobe bit, I then ran the commands to enable the services and rebooted and it seems to be working

@piersharding
Copy link

piersharding commented Aug 22, 2021

Thanks - could not find this solution anywhere else!

@goombah88
Copy link

goombah88 commented Sep 1, 2021

UPDATE: the suspend and resume services are missing in 470.63. To restore functionality just install (in Fedora) xorg-x11-drv-nvidia-power.x86_64. Looks like they moved them to their own package for easier maintenance.

When you install it:

Running transaction
Preparing : 1/1
Installing : xorg-x11-drv-nvidia-power-3:470.63.01-3.fc34.x86_64 1/1
Running scriptlet: xorg-x11-drv-nvidia-power-3:470.63.01-3.fc34.x86_64 1/1
Removed /etc/systemd/system/systemd-suspend.service.requires/nvidia-resume.service.
Removed /etc/systemd/system/systemd-hibernate.service.requires/nvidia-resume.service.
Removed /etc/systemd/system/systemd-suspend.service.requires/nvidia-suspend.service.

Then when you enable the services:
sudo systemctl enable nvidia-suspend.service
sudo systemctl enable nvidia-hibernate.service
sudo systemctl enable nvidia-resume.service
Created symlink /etc/systemd/system/systemd-suspend.service.requires/nvidia-suspend.service → /usr/lib/systemd/system/nvidia-suspend.service.
Created symlink /etc/systemd/system/systemd-hibernate.service.requires/nvidia-hibernate.service → /usr/lib/systemd/system/nvidia-hibernate.service.
Created symlink /etc/systemd/system/systemd-suspend.service.requires/nvidia-resume.service → /usr/lib/systemd/system/nvidia-resume.service.
Created symlink /etc/systemd/system/systemd-hibernate.service.requires/nvidia-resume.service → /usr/lib/systemd/system/nvidia-resume.service.

Glad I stumbled onto this. Hope it helps someone else.

@tomflannaghan
Copy link

tomflannaghan commented Sep 3, 2021

Thanks @goombah88 your solution worked perfectly for me.

@marcelo-r
Copy link

marcelo-r commented Sep 8, 2021

@goombah88 thank you! Worked perfectly. If its its own package now, it could also enable all 3 services when installed.

@bakermanus
Copy link

bakermanus commented Sep 13, 2021

wow. I love you man. Thanks. I can confirm it works on MSI gf72 with 460 server

@williamAlhant
Copy link

williamAlhant commented Sep 22, 2021

I'm on Fedora. Thanks @goombah88 for the tip! It seems to fix my suspend issue.

@empathicqubit
Copy link

empathicqubit commented Oct 3, 2021

My Ubuntu on Sager/Clevo PB50 laptop had these systemd services but they were not enabled, so my screen would never come back, forcing me to restart. Simply running the last three commands with NVidia driver installed fixed it for me.

@khteh
Copy link

khteh commented Oct 4, 2021

I don't find nvidia in /usr/share/doc/nvidia-driver-470. What do I miss?

@bmcbm
Copy link
Author

bmcbm commented Oct 14, 2021

@khteh It seems that the 470 driver may install the required scripts san systemd units in the right places.

Check if /lib/systemd/system-sleep/nvidia and /usr/lib/systemd/system/nvidia-suspend.service is present on your system.

Then you may need to just enable the systemd services:

sudo systemctl enable nvidia-suspend.service
sudo systemctl enable nvidia-hibernate.service
sudo systemctl enable nvidia-resume.service

@devent
Copy link

devent commented Nov 7, 2021

My system don't need those systemd services anymore. My nvidia driver was updated and those files were deleted. But the services weren't deactivated and this is why my system couldn't go into sleep mode. I deactivated the services and it hibernates and resumes just fine. Both suspend to RAM and suspend to disk work.

Maybe you don't need the systemd services if you use nvidia-driver-495 driver. Just for info.

driver : nvidia-driver-495 - third-party non-free recommended
Linux devent-X705UD 5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

sudo systemctl enable nvidia-suspend.service
sudo systemctl disable nvidia-suspend.service
sudo systemctl disable nvidia-hibernate.service
sudo systemctl disable nvidia-resume.service

The error message was

Unit nvidia-hibernate.service not found.

@punyidea
Copy link

punyidea commented Nov 9, 2021

I wanted to mention: I tried troubleshooting my own issue, and finally fixed it. It seems that vidia-driver-470 also does not need these services. My issue was from still having a file in modprobe.d. I had created a file called nvidia.conf in modprobed which set the NVreg_PreserveVideoMemoryAllocations=1. This is outdated and no longer necessary.

After removing the unnecessary file and removing and installing all nvidia drivers, my system finally works as intended!

@apienk
Copy link

apienk commented Nov 25, 2021

For me, with nvidia-driver-495, the simple solution was to remove the damaged symlinks from systemd. You most likely have them if you upgraded from nvidia-driver-470, because 470 still included the .service files in /lib/systemd/system/. The files are no longer included in 495 but the postinst script does not remove the symlinks. So, remove them with:

sudo rm /etc/systemd/system/systemd-hibernate.service.requires/nvidia-resume.service
sudo rm /etc/systemd/system/systemd-hibernate.service.requires/nvidia-hibernate.service
sudo rm /etc/systemd/system/systemd-suspend.service.requires/nvidia-resume.service
sudo rm /etc/systemd/system/systemd-suspend.service.requires/nvidia-suspend.service

Works instantly, no need of rebooting or logging off.

@khteh
Copy link

khteh commented Nov 25, 2021

@apienk
Copy link

apienk commented Nov 25, 2021

@khteh Here are detailed guides for all major distributions: https://linuxconfig.org/install-the-latest-nvidia-linux-driver

@khteh
Copy link

khteh commented Nov 26, 2021

I sudo apt install -y nvidia-driver-495, reboot the laptop and ubuntu-drivers devices still shows nvidia-driver-470 being selected. What do I miss?

@apienk
Copy link

apienk commented Nov 27, 2021

@khteh nvidia-driver-470 must have been automatically uninstalled when you installed nvidia-driver-495 because apt treats them as conflicting. ubuntu-drivers devices does not show the selected driver for me, only recommended. A better way to check which driver is being used:

if using dual-GPU in On-Demand mode:

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep "OpenGL version string"

if using just nVidia:

glxinfo | grep "OpenGL version string"

@khteh
Copy link

khteh commented Nov 30, 2021

But why is it that when I apt install nvidia-driver-495, ubuntu-drivers devices still show 470 as being the recommended one and nvidia-smi and nvidia-settings do NOT work properly?

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

@devent
Copy link

devent commented Nov 30, 2021

You should better ask the Ubuntu devs. This is what I get. I'm using Mint that is based on Ubuntu.

cat /etc/os-release 
NAME="Linux Mint"
VERSION="20.2 (Uma)"

ubuntu-drivers devices
WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
== /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001C8Dsv00001043sd00001B30bc03sc02i00
vendor   : NVIDIA Corporation
model    : GP107M [GeForce GTX 1050 Mobile]
driver   : nvidia-driver-495 - third-party non-free recommended
driver   : nvidia-driver-465 - third-party non-free
driver   : nvidia-driver-450-server - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-390 - distro non-free
driver   : nvidia-driver-460-server - distro non-free
driver   : nvidia-driver-455 - third-party non-free
driver   : nvidia-driver-418-server - distro non-free
driver   : nvidia-driver-460 - third-party non-free
driver   : nvidia-driver-450 - third-party non-free
driver   : nvidia-driver-470 - third-party non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

@bmcbm
Copy link
Author

bmcbm commented Nov 30, 2021

@khteh You may try to use ubuntu-drivers to install the nvidia driver:

$ sudo ubuntu-drivers install nvidia:495

@khteh
Copy link

khteh commented Dec 1, 2021

It doesn't do/help anything at all since I have installed using apt

@ajayyy
Copy link

ajayyy commented Dec 19, 2021

Still working for me on latest Manjaro KDE in a fresh install

@sarka9000
Copy link

sarka9000 commented Jan 11, 2022

Thanks, this fixed my suspend problem which probably came as I was messing with drivers and Steam VR (I think nvidia-dkms-470 emptied those service files?).

For me, pm-suspend worked fine but xfce4-session-logout --suspend and systemctl suspend only took my network down for a few seconds without suspending

@Trikenstein
Copy link

Trikenstein commented Jan 16, 2022

sudo rm /etc/systemd/system/systemd-hibernate.service.requires/nvidia-resume.service
sudo rm /etc/systemd/system/systemd-hibernate.service.requires/nvidia-hibernate.service
sudo rm /etc/systemd/system/systemd-suspend.service.requires/nvidia-resume.service
sudo rm /etc/systemd/system/systemd-suspend.service.requires/nvidia-suspend.service

@apienk Thanks. that is the solution that worked for my case (Ubuntu 20.04.3). I had installed nvidia driver v470. Then changed for a Radeon card. On a routine system update, all the nvidia were removed. But somehow, systemd-hibernate and systemd-suspend still invoke the nvidia services. journalctl -rb -1 shows

Jan 15 11:11:00 mycomputer-abc systemd-logind[1437]: Error during inhibitor-delayed operation (already returned success to client): Unit nvidia-suspend.service is masked.

Strangely enough, this is enough to hang the system. Removing all the orphan nvidia services as you showed fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment