Files
shellscripts/nvidia-suspend-fix.sh
T
2026-07-29 19:08:06 +07:00

45 lines
1.2 KiB
Bash

#!/bin/bash
# Applies NVIDIA suspend/resume blank-screen fix on EndeavourOS (dracut, nvidia-open-dkms).
set -euo pipefail
if [ "$EUID" -eq 0 ]; then
echo "Run this as your normal user, not root (it calls sudo itself)." >&2
exit 1
fi
echo "==> Writing /etc/modprobe.d/nvidia.conf"
sudo tee /etc/modprobe.d/nvidia.conf > /dev/null <<'EOF'
options nvidia-drm modeset=1
options nvidia NVreg_PreserveVideoMemoryAllocations=1
EOF
echo "==> Rebuilding initramfs"
if command -v dracut-rebuild >/dev/null 2>&1; then
sudo dracut-rebuild
else
sudo dracut --force --regenerate-all
fi
echo "==> Enabling nvidia suspend/resume/hibernate services"
sudo systemctl enable nvidia-suspend.service nvidia-resume.service nvidia-hibernate.service
echo "==> Installing systemd-sleep VT-switch hook"
sudo tee /usr/lib/systemd/system-sleep/nvidia-resume-fix.sh > /dev/null <<'EOF'
#!/bin/sh
case "$1" in
post)
CUR=$(cat /sys/class/tty/tty0/active | grep -o '[0-9]*')
ALT=2
[ "$CUR" = "2" ] && ALT=3
chvt "$ALT"
sleep 1
chvt "$CUR"
;;
esac
EOF
sudo chmod +x /usr/lib/systemd/system-sleep/nvidia-resume-fix.sh
echo
echo "Done. A reboot is required for the modeset/initramfs changes to take effect."
echo "Run: sudo reboot"