Skip to content

Instantly share code, notes, and snippets.

@bmcbm
Last active April 24, 2024 22:18
Show Gist options
  • Star 68 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
@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!

@the-rich-piana
Copy link

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

...

So far seems to have work on my Lenovo Legion Slim 7 4060 PopOS kernel 6.8, also driver 550. Kind of frustrating because PopOS ships with nvidia drivers and so everytime I have to update OS it updates my drivers 😅 and I have to repeat this process.

nvidia-hibernate.service                         enabled         enabled
nvidia-powerd.service                            enabled         enabled
nvidia-resume.service                            enabled         enabled
nvidia-suspend.service                           enabled         enabled

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