永久应用 proc/acpi/wakeup 设置

永久应用 proc/acpi/wakeup 设置

为了使设置在 Linux 系统中永久存在,批处理脚本方式是标准吗?

今天我发现自己在检查计算机唤醒设置在重启计算机后被重置了。我开始在 Google 上搜索我需要设置一个批处理脚本才能使更改保留下来。现在,这种建议在这些类型的“罕见配置”中很普遍。让我非常紧张的是,没有人谈论任何配置或负责唤醒功能的软件,相反 - 一些看起来很便宜的批处理脚本解决方案被抛出,这些解决方案应该在计算机启动时设置设置。

我是否必须设置批处理脚本,并且在 /etc/ 或任何其他文件夹中没有唤醒配置来设置关机或重启后保留的永久更改?

我提供更多信息:

naudotojas@naudotojas-N53SV:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.04
Release:    19.04
Codename:   disco
naudotojas@naudotojas-N53SV:~$ 

我希望禁用这些设置重新启动 Ubuntu 后,即保持永久状态:

naudotojas@naudotojas-N53SV:~$ cat /proc/acpi/wakeup | grep enabled
EHC1      S3    *enabled   pci:0000:00:1d.0
EHC2      S3    *enabled   pci:0000:00:1a.0
XHCI      S3    *enabled   pci:0000:04:00.0

这是我希望在重启后看到的最终结果:

EHC1      S3    *disabled   pci:0000:00:1d.0
EHC2      S3    *disabled   pci:0000:00:1a.0
XHCI      S3    *disabled   pci:0000:04:00.0

答案1

首选方法是使用servicesystemd 创建。
添加脚本rc.local是已弃用的方法。

  1. 在您希望的任何位置创建脚本文件。例如:~/scripts/disable-devices-as-wakeup.sh
#!/bin/bash

declare -a devices=(EHC1 EHC2 XHCI) # <-- Add your entries here
for device in "${devices[@]}"; do
    if grep -qw ^$device.*enabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done
  1. 通过从终端执行来测试它。

  2. 如果一切顺利的话我们就提供服务吧。

$ touch ~/scripts/disable-devices-as-wakeup.service

〜/脚本/禁用设备作为唤醒.服务-

[Unit]
Description=Disable devices as wakeup

[Service]
ExecStart=/home/username/scripts/disable-devices-as-wakeup.sh
Type=oneshot

[Install]
WantedBy=multi-user.target
  1. 将服务复制或移动到/etc/systemd/system/
$ sudo cp ~/scripts/disable-devices-as-wakeup.service /etc/systemd/system/
  1. 启用该服务。
$ systemctl enable disable-devices-as-wakeup.service
  1. 重新启动操作系统并检查状态。
$ systemctl status disable-devices-as-wakeup.service

详细解释见https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/chap-managing_services_with_systemd

答案2

非常感谢 Hrishikesh 的解释。我在我的系统中使用过这个。虽然代码中有一个小错误。我不是程序员,但其他人指出了这一点。所以供其他人参考。引号不应该出现在第一行。应该是:

#!/bin/bash
declare -a devices=( LID0 XHC1 )
for device in "${devices[@]}"; do
    if grep -qw ^$device.*disabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done

或者“启用”正是您想要实现的功能。

相关内容