Fix for suspend not working on some instances of Ubuntu 22 w/Nvidia drivers
Issue referenced here:
- https://bugs.launchpad.net/ubuntu/+source/mutter/+bug/1876632
- https://gitlab.gnome.org/GNOME/mutter/-/issues/1942
Amazing solution, found on Nvidia forums, created by devyn.cairns
gnome-shell is trying to talk to the NVIDIA driver after it has already gone into suspend, so it can’t respond. Linux tries to freeze the task, but fails because gnome-shell is waiting for a response from the driver and can’t be frozen.
The solution is to manually suspend gnome-shell using the STOP signal before the NVIDIA driver goes to suspend. Then use the CONT signal on resume.
sudo vim /usr/local/bin/suspend-gnome-shell.sh
chmod +x /usr/local/bin/suspend-gnome-shell.sh
#!/bin/bash
case "$1" in
suspend)
killall -STOP gnome-shell
;;
resume)
killall -CONT gnome-shell
;;
esac
/etc/systemd/system/gnome-shell-suspend.service
[Unit]
Description=Suspend gnome-shell
Before=systemd-suspend.service
Before=systemd-hibernate.service
Before=nvidia-suspend.service
Before=nvidia-hibernate.service
[Service]
Type=oneshot
#some machines could run into race condition / black screen / freezed screen. add delay to successfully return after suspend/hibernate.
ExecStartPre=/bin/sleep 3
ExecStart=/usr/local/bin/suspend-gnome-shell.sh suspend
[Install]
WantedBy=systemd-suspend.service
WantedBy=systemd-hibernate.service
/etc/systemd/system/gnome-shell-resume.service
[Unit]
Description=Resume gnome-shell
After=systemd-suspend.service
After=systemd-hibernate.service
After=nvidia-resume.service
[Service]
Type=oneshot
#some machines could run into race condition / black screen / freezed screen. add delay to successfully return after suspend/hibernate.
ExecStartPre=/bin/sleep 3
ExecStart=/usr/local/bin/suspend-gnome-shell.sh resume
[Install]
WantedBy=systemd-suspend.service
WantedBy=systemd-hibernate.service
systemctl daemon-reload
systemctl enable gnome-shell-suspend
systemctl enable gnome-shell-resume