Ubuntu 如果插上显示器不使用,一段时间(通常是 20 分钟)后会突然停了。这是由于装 Nvidia Driver 的时候不小心装上了 gnome 的缘故。

当前用户检查电源管理 sleep-inactive-ac-timeout 设置:

$ gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout
1200

疑似这个就是原因。

修改成这样:

$ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0

查看目前所有选项如下:

$ gsettings list-recursively org.gnome.settings-daemon.plugins.power
org.gnome.settings-daemon.plugins.power lid-close-ac-action 'suspend'
org.gnome.settings-daemon.plugins.power time-critical 300
org.gnome.settings-daemon.plugins.power power-button-action 'suspend'
org.gnome.settings-daemon.plugins.power lid-close-suspend-with-external-monitor false
org.gnome.settings-daemon.plugins.power button-hibernate 'hibernate'
org.gnome.settings-daemon.plugins.power idle-dim true
org.gnome.settings-daemon.plugins.power button-power 'suspend'
org.gnome.settings-daemon.plugins.power lid-close-battery-action 'suspend'
org.gnome.settings-daemon.plugins.power priority 0
org.gnome.settings-daemon.plugins.power idle-brightness 30
org.gnome.settings-daemon.plugins.power active true
org.gnome.settings-daemon.plugins.power critical-battery-action 'hibernate'
org.gnome.settings-daemon.plugins.power button-suspend 'suspend'
org.gnome.settings-daemon.plugins.power button-sleep 'hibernate'
org.gnome.settings-daemon.plugins.power percentage-critical 3
org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'suspend'
org.gnome.settings-daemon.plugins.power ambient-enabled true
org.gnome.settings-daemon.plugins.power notify-perhaps-recall true
org.gnome.settings-daemon.plugins.power percentage-low 10
org.gnome.settings-daemon.plugins.power percentage-action 2
org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'suspend'
org.gnome.settings-daemon.plugins.power time-low 1200
org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 1200
org.gnome.settings-daemon.plugins.power time-action 120
org.gnome.settings-daemon.plugins.power use-time-for-policy true

参考 https://ubuntu-mate.community/t/ubuntu-mate-auto-suspend-20-minutes-after-it-restart/17650

但是这个貌似不工作。

停止前 log 依然是

Nov 24 18:50:09 diony NetworkManager[863]: <info>  [1637751009.5098] manager: sleep: sleep requested (sleeping: no  enabled: yes)
Nov 24 18:50:09 diony ModemManager[934]: <info>  [sleep-monitor] system is about to suspend
Nov 24 18:50:09 diony NetworkManager[863]: <info>  [1637751009.5100] manager: NetworkManager state is now ASLEEP
Nov 24 18:50:09 diony gnome-shell[1286]: Screen lock is locked down, not locking
Nov 24 18:50:09 diony systemd[1]: Reached target Sleep.
Nov 24 18:50:09 diony systemd[1]: Starting Record successful boot for GRUB...
Nov 24 18:50:09 diony systemd[1]: Starting Suspend...
Nov 24 18:50:09 diony systemd-sleep[18784]: Suspending system...
Nov 24 18:50:09 diony kernel: [ 1221.038239] PM: suspend entry (deep)
Nov 24 18:50:09 diony systemd[1]: grub-common.service: Succeeded.
Nov 24 18:50:09 diony systemd[1]: Finished Record successful boot for GRUB.
Nov 24 18:50:09 diony systemd[1]: Starting GRUB failed boot detection...
Nov 24 18:50:09 diony systemd[1]: grub-initrd-fallback.service: Succeeded.
Nov 24 18:50:09 diony systemd[1]: Finished GRUB failed boot detection.
Nov 24 18:50:09 diony kernel: [ 1221.097020] Filesystems sync: 0.058 seconds
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (**) Option "fd" "40"
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) event2  - Power Button: device removed
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (**) Option "fd" "43"
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) event1  - Power Button: device removed
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (**) Option "fd" "44"
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) event0  - Sleep Button: device removed
Nov 24 18:50:10 diony kernel: [ 1221.728849] snd_hda_codec_hdmi hdaudioC1D0: HDMI: invalid ELD data byte 0
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) systemd-logind: got pause for 13:65
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) systemd-logind: got pause for 13:64
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) systemd-logind: got pause for 13:66

尝试了下这个: https://www.unixtutorial.org/disable-sleep-on-ubuntu-server/

主要信息:

禁止:

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.

恢复:

$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Removed /etc/systemd/system/sleep.target.
Removed /etc/systemd/system/suspend.target.
Removed /etc/systemd/system/hibernate.target.
Removed /etc/systemd/system/hybrid-sleep.target.
Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

Leave a Reply

Your email address will not be published.