Skip to content

Instantly share code, notes, and snippets.

@bmcbm
Last active April 19, 2024 22:03
Show Gist options
  • Star 67 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmcbm/375f14eaa17f88756b4bdbbebbcfd029 to your computer and use it in GitHub Desktop.
Save bmcbm/375f14eaa17f88756b4bdbbebbcfd029 to your computer and use it in GitHub Desktop.
NVIDIA Suspend fix
# Use systemd for managing NVIDIA driver suspend in drivers ====>>> PRIOR to version 470 <<<=====
# 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
@wiesenklee
Copy link

wiesenklee commented May 5, 2022

hey there, for the nvidia-340 i can not find the required service's in the corresponding directory /usr/share/doc/nvidia-340. is there a work-around so i can use the services from other nvidia-driver's. any ideas?

@bmcbm
Copy link
Author

bmcbm commented May 6, 2022

@han-nes The 340 series dates back to 2014. Sorry, can't help you there.

@mike-lawrence
Copy link

So, for those of us now on 510, but were previously on 470, does the procedure for getting suspend to work start with deleting the 470 files via

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

and then running the code of your gist (replacing nvidia-driver-460with nvidia-driver-510), or is merely deleting the files sufficient?

@bmcbm
Copy link
Author

bmcbm commented May 17, 2022

@mike-lawrence The instructions in the gist above is for drivers PRIOR to v470 as stated in the comment in the top.

You should not use it for v470 and later drivers. Since v470 all required scripts are installed and updated automatically (as far as I am aware)

@7h3ju57
Copy link

7h3ju57 commented May 17, 2022

@392781 wow, adding exit 0 to nvidia-sleep.sh fixed my sleep issues!
Curious if its my old GTX970 causing issues.
Running NVIDIA510 on PopOS 22.04

@bmharper
Copy link

I'm on Ubuntu 22.04, and after installing CUDA I was unable to suspend.
The following steps worked for me:

  • Inside /etc/systemd, delete all of the files that include nvidia and suspend or hibernate. There are three services inside /etc/systemd/system, which I deleted. There are also some other dead nvidia links inside systemd-hibernate.service.requires, systemd-suspend.service.requires, which I deleted.

I wish I knew the exact names of the files that I deleted, but since they're now gone, I can't remember their exact paths.
But in a nutshell, go into /etc/systemd, and do find . -iname nv*, and then delete all the of the suspend, resume, and hibernate scripts.

DO NOT DELETE nvidia-powerd.service and nvidia-persistenced.service.

Once you're done with that, do systemctl daemon-reload.

@Akib-Alvee
Copy link

@apienk Thank you very much. I was bit upset as I didn't find any solution.Then your procedures works for me perfectly.

@marani
Copy link

marani commented Jun 13, 2022

After installing latest nvidia driver & cuda tool kit I was unable to suspend or hibernate with sudo systemctl suspend or sudo systemctl hibernate as usual, the log shows this

> journalctl -b | grep suspend
... systemd-logind[1841]: Error during inhibitor-delayed operation (already returned success to client): Unit nvidia-suspend.service not found.
...

Which is correct because

> systemctl status nvidia-suspend nvidia-hibernate nvidia-resume
Unit nvidia-suspend.service could not be found.
Unit nvidia-hibernate.service could not be found.
Unit nvidia-resume.service could not be found.

My nvidia libs version

> cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  515.48.07  Fri May 27 03:26:43 UTC 2022
GCC version:  gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_18:49:52_PDT_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0

My /usr/share/doc/nvidia-driver-515 looks pretty empty

> ls /usr/share/doc/nvidia-driver-515/
LICENSE.gz                        changelog.Debian.gz               nvidia-persistenced-init.tar.bz2
NVIDIA_Changelog.gz               copyright
README.txt.gz                     html/

find /usr/share/doc/ -print | grep "suspend" shows no result

So does anyone know what TMPL_PATH should be for the latest driver 515.48.07? Or is my installation broken?

Some findings so far:

  • This comment above says the nvidia-suspend.service files were no longer needed and should be deleted, driver version was 495.
  • However, one guy in this post somehow found the old service config and script file and then put it in the correct location, thus resolved the issue, driver version was also 495.
  • Same issue was investigated here. The OP's resolution was to set NVreg_PreserveVideoMemoryAllocations=0, driver version 470.
  • Some relevant links

@bmcbm
Copy link
Author

bmcbm commented Jun 13, 2022

@marani I also experienced issues with hibernate after installing Nvidia CUDA drivers.

See the comment by @bmharper above.

I found that there were some broken links to the missing systemd service units for uspend and hibernate. Check if you have such broken links and remove them if you do.

find /etc/systemd -type l -exec file {} \; | grep broken | grep nvidia

@marani
Copy link

marani commented Jun 13, 2022

Thanks for the suggestion, I tried deleting and it worked.

However, according to docs v515, the the nvidia systemd config files are still used, the documentation mentioned it as if the files are supposed to be there (Unless they forgot to update the docs). Looking at the shell script in this post, it seems to call nvidia driver suspend, so removing them would remove this behavior?

/usr/bin/nvidia-sleep.sh

#!/bin/bash

if [ ! -f /proc/driver/nvidia/suspend ]; then
    exit 0
fi

RUN_DIR="/var/run/nvidia-sleep"
XORG_VT_FILE="${RUN_DIR}"/Xorg.vt_number

PATH="/bin:/usr/bin"

case "$1" in
    suspend|hibernate)
        mkdir -p "${RUN_DIR}"
        fgconsole > "${XORG_VT_FILE}"
        chvt 63
        if [[ $? -ne 0 ]]; then
            exit $?
        fi
        echo "$1" > /proc/driver/nvidia/suspend
        exit $?
        ;;
    resume)
        echo "$1" > /proc/driver/nvidia/suspend 
        #
        # Check if Xorg was determined to be running at the time
        # of suspend, and whether its VT was recorded.  If so,
        # attempt to switch back to this VT.
        #
        if [[ -f "${XORG_VT_FILE}" ]]; then
            XORG_PID=$(cat "${XORG_VT_FILE}")
            rm "${XORG_VT_FILE}"
            chvt "${XORG_PID}"
        fi
        exit 0
        ;;
    *)
        exit 1
esac

@rdominguez89
Copy link

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

This works perfectly

@AugustineYang
Copy link

I'm on Ubuntu 22.04, and after installing CUDA I was unable to suspend. The following steps worked for me:

  • Inside /etc/systemd, delete all of the files that include nvidia and suspend or hibernate. There are three services inside /etc/systemd/system, which I deleted. There are also some other dead nvidia links inside systemd-hibernate.service.requires, systemd-suspend.service.requires, which I deleted.

I wish I knew the exact names of the files that I deleted, but since they're now gone, I can't remember their exact paths. But in a nutshell, go into /etc/systemd, and do find . -iname nv*, and then delete all the of the suspend, resume, and hibernate scripts.

DO NOT DELETE nvidia-powerd.service and nvidia-persistenced.service.

Once you're done with that, do systemctl daemon-reload.

This works! Thanks a lot!

@albertomercurio
Copy link

I'm on Ubuntu 22.04, and after installing CUDA I was unable to suspend. The following steps worked for me:

  • Inside /etc/systemd, delete all of the files that include nvidia and suspend or hibernate. There are three services inside /etc/systemd/system, which I deleted. There are also some other dead nvidia links inside systemd-hibernate.service.requires, systemd-suspend.service.requires, which I deleted.

I wish I knew the exact names of the files that I deleted, but since they're now gone, I can't remember their exact paths. But in a nutshell, go into /etc/systemd, and do find . -iname nv*, and then delete all the of the suspend, resume, and hibernate scripts.

DO NOT DELETE nvidia-powerd.service and nvidia-persistenced.service.

Once you're done with that, do systemctl daemon-reload.

This doesn't worked form me.
I removed all nvidia files you said. Indeed, if i do systemctl list-unit-files | grep nvidia it returns

nvidia-persistenced.service                                               enabled         enabled
nvidia-powerd.service                                                     enabled         enabled

and with find /etc/systemd -iname nv*

/etc/systemd/system/multi-user.target.wants/nvidia-persistenced.service
/etc/systemd/system/multi-user.target.wants/nvidia-powerd.service

but I'm still not able to resume the laptop.

My nvidia-smi is

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| N/A   49C    P8     2W /  N/A |    634MiB /  4096MiB |      8%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      2112      G   /usr/lib/xorg/Xorg                216MiB |
|    0   N/A  N/A      2468      G   /usr/bin/gnome-shell               50MiB |
|    0   N/A  N/A      3944      G   ...589584913286235972,131072      366MiB |
+-----------------------------------------------------------------------------+

@fxmarty
Copy link

fxmarty commented Sep 19, 2022

@bmharper Your solution works perfectly for me (driver 515)!

@mikeshiyan
Copy link

Thanks @bmharper !!! Worked for me too, in the Nvidia On-Demand mode. I haven't tried other modes yet, but I'm fine with this one.

My story is: Linux Mint 20.3 Cinnamon, kernel 5.4.0-126. Recently installed CUDA toolkit, which updated my nvidia driver from 470 (if I'm not mistaken) to 515, which in turn had broken my auto-suspend on lid close. The Quit->Suspend button haven't worked either. Only way I could suspend is by running pm-suspend from terminal.

@yingtanairbussv
Copy link

@bmharper That works for alienware laptop with nvidia driver 515

@yingtanairbussv
Copy link

It works. The power drain I see before is not related to nvidia graphic card.

I tried to put the alienware laptop to airplane mode and pull out usb dondle before put into suspend, and put in the backpack for the whole night. The battery level only down by 9% which is normal, and no extra heat in the backpack.

@yingtanairbussv
Copy link

BTW: I also update the driver to version 520, and upgrade ubuntu to 22.04.1 LTS. Works fine.

@sbwcwso
Copy link

sbwcwso commented Oct 28, 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

worked for me. Thank you very much.

@mtz29
Copy link

mtz29 commented Jan 14, 2023

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.

This does the job. Thank you.

@kolubex
Copy link

kolubex commented Feb 16, 2023

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

Thank you, This worked in my case.

@dnstufff
Copy link

dnstufff commented Mar 8, 2023

The method works. In case you need fresh files install the services, you can get your driver version from NVIDIA. Use nvidia-smi to get the exact version and then run the .run file with --extract-only flag: sudo bash NVIDIA-Linux-x86_64-515.65.01.run --extract-only.

Then you run the given commands setting the TMPL_PATH to the path where you've extracted the files. Keep in mind that the files for this driver (515.65.01) have a slightly different locations as stated in the original post. So the updated commands should be like this:

TMPL_PATH=/home/user/Downloads/NVIDIA-Linux-x86_64-515.65.01/systemd

sudo install --mode 644 "${TMPL_PATH}/system/nvidia-suspend.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/system/nvidia-hibernate.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/system/nvidia-resume.service" /etc/systemd/system
sudo install "${TMPL_PATH}/system-sleep/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

@neufr-docker
Copy link

Thanks! This worked for me for 530.30.02

@gruentee
Copy link

Thanks! This worked for me for 530.30.02

Having troubles to understand what exactly worked for you - enabling or removing the service files? Comments here seem to suggest contradicting solutions.

@392781
Copy link

392781 commented Apr 15, 2023

Thanks! This worked for me for 530.30.02

Having troubles to understand what exactly worked for you - enabling or removing the service files? Comments here seem to suggest contradicting solutions.

Removing. If the symlinks are broken, best you can do is remove.

@Sahas-Ananth
Copy link

Thanks! This worked for me for 530.30.02

I have tried removing too. Driver: 530.41.03. I have been working on this for hours I have 0 clues on how to fix this issue. Just for clarity, When I do sudo systemctl suspend it kinda just logs out and does not enter suspend. Although Initially, I did have a problem where it would just hang when I wake from suspend.

This is what it throws out when I run journalctl -b | grep suspend. Somebody help 😭

May 03 17:57:26 Dennis-Ritchie kernel: nvme 0000:03:00.0: platform quirk: setting simple suspend
May 03 17:57:26 Dennis-Ritchie systemd-udevd[3535]: suspend: Process '/bin/chgrp video /sys/class/backlight/nvidia_0/brightness' failed with exit code 1.
May 03 17:57:26 Dennis-Ritchie systemd-udevd[3535]: suspend: Process '/bin/chmod g+w /sys/class/backlight/nvidia_0/brightness' failed with exit code 1.
May 03 18:21:05 Dennis-Ritchie ModemManager[8316]: <info>  [sleep-monitor] system is about to suspend
May 03 18:21:08 Dennis-Ritchie kernel: PM: suspend entry (deep)
May 03 18:21:12 Dennis-Ritchie kernel: printk: Suspending console(s) (use no_console_suspend to debug)
May 03 18:21:12 Dennis-Ritchie kernel: NVRM: GPU 0000:01:00.0: PreserveVideoMemoryAllocations module parameter is set. System Power Management attempted without driver procfs suspend interface. Please refer to the 'Configuring Power Management Support' section in the driver README.
May 03 18:21:12 Dennis-Ritchie kernel: PM: pci_pm_suspend(): nv_pmops_suspend+0x0/0x30 [nvidia] returns -5
May 03 18:21:12 Dennis-Ritchie kernel: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -5
May 03 18:21:12 Dennis-Ritchie kernel: nvidia 0000:01:00.0: PM: failed to suspend async: error -5
May 03 18:21:12 Dennis-Ritchie kernel: PM: Some devices failed to suspend, or early wake event detected
May 03 18:21:12 Dennis-Ritchie kernel: PM: suspend exit
May 03 18:21:12 Dennis-Ritchie kernel: PM: suspend entry (s2idle)
May 03 18:21:13 Dennis-Ritchie kernel: printk: Suspending console(s) (use no_console_suspend to debug)
May 03 18:21:13 Dennis-Ritchie kernel: NVRM: GPU 0000:01:00.0: PreserveVideoMemoryAllocations module parameter is set. System Power Management attempted without driver procfs suspend interface. Please refer to the 'Configuring Power Management Support' section in the driver README.
May 03 18:21:13 Dennis-Ritchie kernel: PM: pci_pm_suspend(): nv_pmops_suspend+0x0/0x30 [nvidia] returns -5
May 03 18:21:13 Dennis-Ritchie kernel: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -5
May 03 18:21:13 Dennis-Ritchie kernel: nvidia 0000:01:00.0: PM: failed to suspend async: error -5
May 03 18:21:13 Dennis-Ritchie kernel: PM: Some devices failed to suspend, or early wake event detected
May 03 18:21:13 Dennis-Ritchie systemd-sleep[29540]: Failed to suspend system. System resumed again: Input/output error
May 03 18:21:13 Dennis-Ritchie kernel: PM: suspend exit
May 03 18:21:13 Dennis-Ritchie systemd[1]: systemd-suspend.service: Main process exited, code=exited, status=1/FAILURE
May 03 18:21:13 Dennis-Ritchie systemd[1]: systemd-suspend.service: Failed with result 'exit-code'.
May 03 18:21:13 Dennis-Ritchie systemd[1]: suspend.target: Job suspend.target/start failed with result 'dependency'.
May 03 18:21:38 Dennis-Ritchie sudo[30366]:    sahas : TTY=pts/0 ; PWD=/home/sahas ; USER=root ; COMMAND=/usr/bin/systemctl suspend
May 03 18:21:38 Dennis-Ritchie ModemManager[8316]: <info>  [sleep-monitor] system is about to suspend
May 03 18:21:43 Dennis-Ritchie kernel: PM: suspend entry (deep)
May 03 18:21:48 Dennis-Ritchie kernel: printk: Suspending console(s) (use no_console_suspend to debug)
May 03 18:21:48 Dennis-Ritchie kernel: NVRM: GPU 0000:01:00.0: PreserveVideoMemoryAllocations module parameter is set. System Power Management attempted without driver procfs suspend interface. Please refer to the 'Configuring Power Management Support' section in the driver README.
May 03 18:21:48 Dennis-Ritchie kernel: PM: pci_pm_suspend(): nv_pmops_suspend+0x0/0x30 [nvidia] returns -5
May 03 18:21:48 Dennis-Ritchie kernel: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -5
May 03 18:21:48 Dennis-Ritchie kernel: nvidia 0000:01:00.0: PM: failed to suspend async: error -5
May 03 18:21:48 Dennis-Ritchie kernel: PM: Some devices failed to suspend, or early wake event detected
May 03 18:21:48 Dennis-Ritchie kernel: PM: suspend exit
May 03 18:21:48 Dennis-Ritchie kernel: PM: suspend entry (s2idle)
May 03 18:21:50 Dennis-Ritchie kernel: printk: Suspending console(s) (use no_console_suspend to debug)
May 03 18:21:50 Dennis-Ritchie kernel: NVRM: GPU 0000:01:00.0: PreserveVideoMemoryAllocations module parameter is set. System Power Management attempted without driver procfs suspend interface. Please refer to the 'Configuring Power Management Support' section in the driver README.
May 03 18:21:50 Dennis-Ritchie kernel: PM: pci_pm_suspend(): nv_pmops_suspend+0x0/0x30 [nvidia] returns -5
May 03 18:21:50 Dennis-Ritchie kernel: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -5
May 03 18:21:50 Dennis-Ritchie kernel: nvidia 0000:01:00.0: PM: failed to suspend async: error -5
May 03 18:21:50 Dennis-Ritchie kernel: PM: Some devices failed to suspend, or early wake event detected
May 03 18:21:50 Dennis-Ritchie kernel: PM: suspend exit
May 03 18:21:50 Dennis-Ritchie systemd-sleep[30440]: Failed to suspend system. System resumed again: Input/output error
May 03 18:21:50 Dennis-Ritchie systemd[1]: systemd-suspend.service: Main process exited, code=exited, status=1/FAILURE
May 03 18:21:50 Dennis-Ritchie systemd[1]: systemd-suspend.service: Failed with result 'exit-code'.
May 03 18:21:50 Dennis-Ritchie systemd[1]: suspend.target: Job suspend.target/start failed with result 'dependency'.

@wezel
Copy link

wezel commented May 5, 2023

The method works. In case you need fresh files install the services, you can get your driver version from NVIDIA. Use nvidia-smi to get the exact version and then run the .run file with --extract-only flag: sudo bash NVIDIA-Linux-x86_64-515.65.01.run --extract-only.

Then you run the given commands setting the TMPL_PATH to the path where you've extracted the files. Keep in mind that the files for this driver (515.65.01) have a slightly different locations as stated in the original post. So the updated commands should be like this:

TMPL_PATH=/home/user/Downloads/NVIDIA-Linux-x86_64-515.65.01/systemd

sudo install --mode 644 "${TMPL_PATH}/system/nvidia-suspend.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/system/nvidia-hibernate.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/system/nvidia-resume.service" /etc/systemd/system
sudo install "${TMPL_PATH}/system-sleep/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

I have the 530.30.02 drivers and this worked for me thanks! I almost gave up on it.

@Sahas-Ananth
Copy link

The method works. In case you need fresh files install the services, you can get your driver version from NVIDIA. Use nvidia-smi to get the exact version and then run the .run file with --extract-only flag: sudo bash NVIDIA-Linux-x86_64-515.65.01.run --extract-only.
Then you run the given commands setting the TMPL_PATH to the path where you've extracted the files. Keep in mind that the files for this driver (515.65.01) have a slightly different locations as stated in the original post. So the updated commands should be like this:

TMPL_PATH=/home/user/Downloads/NVIDIA-Linux-x86_64-515.65.01/systemd

sudo install --mode 644 "${TMPL_PATH}/system/nvidia-suspend.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/system/nvidia-hibernate.service" /etc/systemd/system
sudo install --mode 644 "${TMPL_PATH}/system/nvidia-resume.service" /etc/systemd/system
sudo install "${TMPL_PATH}/system-sleep/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

I have the 530.30.02 drivers and this worked for me thanks! I almost gave up on it.

Did you change the above command to 530.30.02 (your driver version) or 515.65.01 (The one given in the script)?

@wezel
Copy link

wezel commented May 9, 2023

Sort of. I downloaded the closest driver, to mine, I could "easily" find from the nvidia driver website and used the name of that version in the script. Which means that I changed all instances of 515.65.01 in the above command to 530.41.03. I hope this helps.
(do note: It would probably be better to match the exact version)

@tvld
Copy link

tvld commented Jul 10, 2023

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

This works perfectly

This fails at first for me. Suspend still freezes on my XPS 9560 with Ubuntu 22.04

Edit: But after I restored the link, it seemed to work for a while:

sudo ln -s  /lib/systemd/system/nvidia-hibernate.service /etc/systemd/system/systemd-hibernate.service.requires/nvidia-hibernate.service 
sudo ln -s /lib/systemd/system/nvidia-resume.service /etc/systemd/system/systemd-hibernate.service.requires/nvidia-resume.service  
sudo ln -s /lib/systemd/system/nvidia-resume.service /etc/systemd/system/systemd-suspend.service.requires/nvidia-resume.service  
sudo ln -s  /lib/systemd/system/nvidia-suspend.service /etc/systemd/system/systemd-suspend.service.requires/nvidia-suspend.service 

... but next day same issue: resume after suspend will freeze system. I can login with ssh though...

@pbattin
Copy link

pbattin commented Jul 11, 2023

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

This works perfectly

This fails at first for me. Suspend still freezes on my XPS 9560 with Ubuntu 22.04

Edit: But after I restored the link, it seemed to work for a while:

sudo ln -s  /lib/systemd/system/nvidia-hibernate.service /etc/systemd/system/systemd-hibernate.service.requires/nvidia-hibernate.service 
sudo ln -s /lib/systemd/system/nvidia-resume.service /etc/systemd/system/systemd-hibernate.service.requires/nvidia-resume.service  
sudo ln -s /lib/systemd/system/nvidia-resume.service /etc/systemd/system/systemd-suspend.service.requires/nvidia-resume.service  
sudo ln -s  /lib/systemd/system/nvidia-suspend.service /etc/systemd/system/systemd-suspend.service.requires/nvidia-suspend.service 

... but next day same issue: resume after suspend will freeze system. I can login with ssh though...

Yea same, im running ver. 535.54.03 and it just freezes when I try to start the suspend command manually. When I try to enter from the desktop it just ends up logging out

@tvld
Copy link

tvld commented Jul 12, 2023

Same 535.54.03 for me. As long as I have "Prime select" on "intel", suspend works flawless, by the way. Just Nvidia not.. )

@cryptolake
Copy link

is there any reason this is not set by default? i'm using kubuntu 23.04 with 535 driver and i had to follow this to get suspend working working, although i had to only enable the services.

@tvld
Copy link

tvld commented Jul 13, 2023

is there any reason this is not set by default? i'm using kubuntu 23.04 with 535 driver and i had to follow this to get suspend working working, although i had to only enable the services.

What is "this"... you mean prime-select? ... if it is not on "Nvidia-on-demand" we can not use discrete graphics on the laptop..

@Tanzeel159
Copy link

I currently have prime and Optimus manager installed. Driver version is 535.54.03 . I am facing the suspend issue when laptop is in hybrid or discrete graphics mode but no issue on integrated mode. What steps should I follow to solve this issue?

@shrihari007
Copy link

Hi I'm also facing the same issue on ubuntu 22.10 / Nvidia-driver-535. I'm not sure what exact steps to be taken to resolve the suspend issue. The device wakes up immediately after suspend. If manually suspended, the graphics has issues after wakeup and external monitor does not work post suspend.

@Tanzeel159
Copy link

Tanzeel159 commented Aug 10, 2023

Yeah . I didn't face that issue earlier . It's fairly recent for me. I was on Fedora 37 when I started facing the issue.. I tried everything then but it didn't work . Then I switched to EndeavourOS and followed the steps mentioned in post but the issue didn't resolve. I came across post where they mentioned sometimes having less SWAP partition can cause that issue so I created new SWAP partition and again the issue didn't resolve.

I was earlier dual booting with windows 10, since this issue was not resolved I reverted back to Windows removing the Linux partition. Main issue is without suspend there is constant use of device and there is high power consumption, suspending will reboot system causing loss of work. Suspend works fine on integrated graphics but that's not viable since I can't use my external display . So I switched. Hopefully someone will figure out what exactly is the issue!

@NicolasPrimeau
Copy link

NicolasPrimeau commented Sep 1, 2023

The solution by @ermenkov is the only thing that worked. Ubuntu 22.02 / driver version 535.104.05

The other issue was bluetooth waking up the system immediately after suspend. That was fixed with this script in /lib/systemd/system-sleep/bluetooth-suspend (From stack overflow or a forum, I forget where)

#!/bin/bash
# Makes sure bluetooth service is not running while suspended.

if [ "${1}" == "pre" ]; then
    service bluetooth stop
elif [ "${1}" == "post" ]; then
    service bluetooth start
fi

@Ahwar
Copy link

Ahwar commented Sep 6, 2023

Whoever gave this idea worked for me:

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

My nvidia info using nvidia-smi command:

Wed Sep  6 19:56:52 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.104.05             Driver Version: 535.104.05   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3060 Ti     Off | 00000000:B3:00.0  On |                  N/A |
|  0%   48C    P8              21W / 240W |    345MiB /  8192MiB |     36%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      2404      G   /usr/lib/xorg/Xorg                          179MiB |
|    0   N/A  N/A      2575      G   /usr/bin/gnome-shell                         98MiB |
|    0   N/A  N/A     50045      G   ...2403833,13679958894095400614,262144       58MiB |
+---------------------------------------------------------------------------------------+

System Name:
Dell Inc. Precision 5820 Tower
Ubuntu 22.04.3 LTS

@matbun
Copy link

matbun commented Sep 17, 2023

I'm on Ubuntu 22.04, and after installing CUDA I was unable to suspend. The following steps worked for me:

  • Inside /etc/systemd, delete all of the files that include nvidia and suspend or hibernate. There are three services inside /etc/systemd/system, which I deleted. There are also some other dead nvidia links inside systemd-hibernate.service.requires, systemd-suspend.service.requires, which I deleted.

I wish I knew the exact names of the files that I deleted, but since they're now gone, I can't remember their exact paths. But in a nutshell, go into /etc/systemd, and do find . -iname nv*, and then delete all the of the suspend, resume, and hibernate scripts.

DO NOT DELETE nvidia-powerd.service and nvidia-persistenced.service.

Once you're done with that, do systemctl daemon-reload.

Worked for me as well!

I have a Dell Inspiron 15 5000 with Nvidia driver 470.199.02 on Ubuntu 20.04 LTS.

@BLuFeNiX
Copy link

BLuFeNiX commented Nov 6, 2023

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

This works perfectly

Also worked for me after installing CUDA libraries on Ubuntu 22.04. Prior to this I had Nvidia drivers working with suspend without issue.

@skwzrd
Copy link

skwzrd commented Nov 13, 2023

I know this gist is for NVIDIA drivers with versions <470, but I wanted to if anyone has had any luck getting drivers 525, or 535 to work.

GPU: Nvidia 4060 TI
Driver: 535.129.03
CUDA Version: 12.2
CPU: AMD 5700X
Board: Gigabyte 550 Gaming V2
OS: Ubuntu 22.04.3 LTS

Basically, when I select suspend on Ubuntu, my screens turn off, and my fans spin up to a very high RPM. Then I am unable to wake it up from this state, and must toggle the PSU switch off and on again. After that, the login screen is displayed.

I know this is an Ubuntu related issue because I can put my computer to sleep on Windows 10, and wake it back up again.

What I've tried:

  • Editing /etc/defaults/grub (GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX="nouveau.blacklist=1")
  • Removing all NVIDIA services in /etc/systemd (https://askubuntu.com/a/1409631/1554429)
  • Installing different Nvidia drivers, both open source and proprietary options
  • Setting the Nvidia sleep shell script to only execute exit 0
  • Disabled secure boot in BIOS
  • Disabled CSM in BIOS
  • Enabled mouse and key presses to wake in BIOS
  • Disabling Nvidia systemd state management, https://askubuntu.com/a/1436923/1554429
  • Other stuff...

@7o9
Copy link

7o9 commented Dec 7, 2023

Yes, I got it to run on an IBM Thinkpad P52 with:

GPU: NVIDIA GP107GLM [Quadro P2000 Mobile]
Driver: 535.129.03
CPU: Intel Xeon E-2176M
Distro: Linux Mint 21.2 Victoria
base: Ubuntu 22.04 jammy
Kernel: 5.15.0-89-generic x86_64
Desktop: Xfce 4.18.1

My 'trick' ist to only use:

sudo pm-suspend

Anything related to systemd suspend, closing lid etc. else will fail miserably, end with a hanging OS and a hard reboot. Very disappointing, for quite a long time already.

@l3ifk
Copy link

l3ifk commented Dec 28, 2023

I'm on Ubuntu 22.04, and after installing CUDA I was unable to suspend. The following steps worked for me:

  • Inside /etc/systemd, delete all of the files that include nvidia and suspend or hibernate. There are three services inside /etc/systemd/system, which I deleted. There are also some other dead nvidia links inside systemd-hibernate.service.requires, systemd-suspend.service.requires, which I deleted.

I wish I knew the exact names of the files that I deleted, but since they're now gone, I can't remember their exact paths. But in a nutshell, go into /etc/systemd, and do find . -iname nv*, and then delete all the of the suspend, resume, and hibernate scripts.
DO NOT DELETE nvidia-powerd.service and nvidia-persistenced.service.
Once you're done with that, do systemctl daemon-reload.

Worked for me as well!

I have a Dell Inspiron 15 5000 with Nvidia driver 470.199.02 on Ubuntu 20.04 LTS.

This worked for me too! I have a Razer Blade 14 2022 with Nvidia driver 535.129.03 on Ubuntu 23.10

@jmoraispk
Copy link

jmoraispk commented Apr 8, 2024

This also worked for me on an XPS 15 with a 3050 Ti (Ampere), Ubuntu 22.04, driver 550.

This fixed my pci_pm_suspend() and the PreserveVideoMemory stuff that would pop up and prevent laptop sleep.

If you deleted the service files, like nvidia-powerd.service or nvidia-persistenced.service, you either find them here or you can reinstall the drivers like this.

After reinstalling, I was able to see the service files, and then doing what the OP said worked.

Doing systemctl list-unit-files | grep nvidia now gets me:

joao@joao-XPS-15-9520:~$ systemctl list-unit-files | grep nvidia
nvidia-hibernate.service                                                  enabled         enabled
nvidia-persistenced.service                                               static          -
nvidia-resume.service                                                     enabled         enabled
nvidia-suspend.service                                                    enabled         enabled

Good luck!

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