Tex*_*xno 8 swap acpi hibernate linux-mint systemd
更新:我在第 4 节中遇到了一些与我的脚本不一致的地方,该脚本旨在在每次唤醒时执行。事实证明,/proc/acpi/wakeup设置只是有时会重置。不是每次关机/重启/休眠/挂起。因此,有时,我的脚本会启用唤醒功能。我已经更新了脚本。现在它检查它是否在任何地方启用,/proc/acpi/wakeup然后才输出给它。
从某种意义上说,这是我未来的备忘录。我不明白为什么 linux 上的休眠不是一个简单的功能,为什么启用它必须如此复杂。我希望它也能帮助那些对冬眠有疑问的人。
sudo swapon --show. 你可能没有足够的。您的交换大小应该比 RAM 大小稍大。网上有一些指南。我在我的 4GB RAM 机器上进行 5GB 交换。/dev/vgmint/root和/dev/vgmint/swap卷。LVM 挂载时无法调整大小,因此您可以从带有 Linux Mint 的 U 盘启动。在那里你可以使用磁盘应用程序来解锁你的加密 LVM 并使用这个漂亮的指南来安全地减小/dev/vgmint/root卷的大小:
sudo e2fsck -f /dev/vgmint/rootsudo resize2fs /dev/vgmint/root 180G。将 180G 替换为您希望最终卷大小的 90%。sudo lvreduce -L 200G /dev/vgmint/root,其中 200G 是卷的最终大小。sudo resize2fs /dev/vgmint/rootsudo lvextend -l 100%FREE /dev/vgmint/swap_1以使用刚刚创建的可用空间扩展交换卷。sudo swapoff -a以禁用所有交换并运行sudo mkswap /dev/vgmint/swap_1以创建一个新交换。sudo pm-hibernate。您的计算机应该休眠。再次启动它并确保它恢复了一切。如果是这样,那么您的硬件支持休眠。sudo -i
cd /var/lib/polkit-1/localauthority/50-local.d/
nano com.ubuntu.enable-hibernate.pkla
Run Code Online (Sandbox Code Playgroud)
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate
ResultActive=yes
Run Code Online (Sandbox Code Playgroud)
sudo apt install dconf-editor)。打开它,转到/org/cinnamon/settings-daemon/plugins/power/或搜索power。sleep-inactive-battery-type就是我所追求的 - 将其设置为“休眠”。在这里,我喜欢关闭use-time-for-policy并使用电池百分比而不是剩余时间来确定“电池电量低”、“电池严重”和“电池动作”状态。电池百分比是实际值,而剩余时间是估计值,可能会有很大差异。percentage-lowpercentage-critical和percentage-action。环顾四周,此选项卡中有一些有趣的设置。不过要小心。sudo cat /proc/acpi/wakeup。您将看到哪些设备已启用,并可能导致从休眠状态中意外唤醒。需要在启动和从挂起/休眠状态返回时禁用导致您出现问题的设备。echo DEVICE_NAME | sudo tee /proc/acpi/wakeup. (感谢这个线程。)#!/bin/bash
filename='/proc/acpi/wakeup'
n=0
fix=false
while read line; do
if [[ "$line" == *"enabled"* ]]; then
fix=true
#break
fi
n=$((n))
done < $filename
if [[ "$fix" == "true" ]]; then
echo RP01 | tee /proc/acpi/wakeup
echo RP02 | tee /proc/acpi/wakeup
echo RP03 | tee /proc/acpi/wakeup
echo RP05 | tee /proc/acpi/wakeup
echo RP06 | tee /proc/acpi/wakeup
echo XHC1 | tee /proc/acpi/wakeup
echo LID0 | tee /proc/acpi/wakeup
fi
Run Code Online (Sandbox Code Playgroud)
不要忘记为 root 设置可执行脚本。sudo su进而chmod +x /your-script.sh
sudo nano /etc/systemd/system/wakeups.service. 文件内容:[Unit]
Description=Fix unwanted wakeups from suspend
[Service]
Type=oneshot
TimeoutSec=0
StandardOutput=syslog
User=root
ExecStart=/path-to-your-script/script.sh
[Install]
WantedBy=multi-user.target suspend.target hibernate.target
Run Code Online (Sandbox Code Playgroud)
systemctl enable wakeups.serviceThe following was originally posted as part of the question, so I (terdon) am reproducing it here.
UPDATE: I have encountered some inconsistencies with my script in section 4 that is meant to be executed on every wake-up. Turns out, /proc/acpi/wakeup settings are only reset sometimes. Not on every shutdown/restart/hibernate/suspend. So, from time to time, my script would enable wakeups. I have updated the script. Now it checks if it says enabled anywhere in /proc/acpi/wakeup and only then outputs to it.
This is, in a way, a memo for myself in the future. I do not understand why hibernation on linux is not a simple feature that just works and why enabling it has to be so complicated. I hope it also helps people having questions about hibernation.
sudo swapon --show. You probably do not have enough. Your swap size should be somewhat larger than you RAM size. There are some guides online. I go for 5GB swap on my 4GB RAM machine./dev/vgmint/root and /dev/vgmint/swap volumes. You cannot resize LVM while it is mounted, so you boot from a USB stick with Linux Mint. There you can use Disks app to unlock your encrypted LVM and use this beautiful guide to safely reduce the size of your /dev/vgmint/root volume:
sudo e2fsck -f /dev/vgmint/rootsudo resize2fs /dev/vgmint/root 180G. Replace 180G with about 90% of the size you want the final volume to be.sudo lvreduce -L 200G /dev/vgmint/root, where 200G is your volume's final size.sudo resize2fs /dev/vgmint/rootsudo lvextend -l 100%FREE /dev/vgmint/swap_1 to extend your swap volume with the free space you have just created.sudo swapoff -a to disable all swaps and run sudo mkswap /dev/vgmint/swap_1 to create a new one.sudo pm-hibernate. Your computer should hibernate. Boot it up again and make sure it restores everything. If it does, then your hardware supports hibernation.sudo -i
cd /var/lib/polkit-1/localauthority/50-local.d/
nano com.ubuntu.enable-hibernate.pkla
Run Code Online (Sandbox Code Playgroud)
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate
ResultActive=yes
Run Code Online (Sandbox Code Playgroud)
sudo apt install dconf-editor)。打开它,转到/org/cinnamon/settings-daemon/plugins/power/或只搜索power。sleep-inactive-battery-type这就是我所追求的 - 将其设置为“休眠”。在这里,我喜欢关闭use-time-for-policy并使用电池百分比而不是剩余时间来确定“电池电量低”、“电池电量严重不足”和“电池操作”状态。电池百分比是实际值,而剩余时间是估计值,可能会有很大差异。您还可以使用percentage-low、percentage-critical和来设置百分比阈值percentage-action。环顾四周,这个选项卡中有一些有趣的设置。不过要小心。sudo cat /proc/acpi/wakeup。您将看到哪些设备已启用并且可能导致从休眠状态中意外唤醒。给您带来麻烦的设备需要在启动时和从挂起/休眠状态返回时禁用。echo DEVICE_NAME | sudo tee /proc/acpi/wakeup。(感谢这个线程。)#!/bin/bash
filename='/proc/acpi/wakeup'
n=0
fix=false
while read line; do
if [[ "$line" == *"enabled"* ]]; then
fix=true
#break
fi
n=$((n))
done < $filename
if [[ "$fix" == "true" ]]; then
echo RP01 | tee /proc/acpi/wakeup
echo RP02 | tee /proc/acpi/wakeup
echo RP03 | tee /proc/acpi/wakeup
echo RP05 | tee /proc/acpi/wakeup
echo RP06 | tee /proc/acpi/wakeup
echo XHC1 | tee /proc/acpi/wakeup
echo LID0 | tee /proc/acpi/wakeup
fi
Run Code Online (Sandbox Code Playgroud)
不要忘记让您的脚本对 root 可执行。sudo su进而chmod +x /your-script.sh
sudo nano /etc/systemd/system/wakeups.service。文件内容:[Unit]
Description=Fix unwanted wakeups from suspend
[Service]
Type=oneshot
TimeoutSec=0
StandardOutput=syslog
User=root
ExecStart=/path-to-your-script/script.sh
[Install]
WantedBy=multi-user.target suspend.target hibernate.target
Run Code Online (Sandbox Code Playgroud)
systemctl enable wakeups.service