Power Management: Difference between revisions
m change lang=sh to shell session to fix syntax highlighting error |
|||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 30: | Line 30: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
systemd.services.your-service-name = { | |||
description = "Service description here"; | |||
wantedBy = [ "post-resume.target" ]; | |||
after = [ "post-resume.target" ]; | |||
script = '' | |||
echo "This should show up in the journal after resuming." | echo "This should show up in the journal after resuming." | ||
''; | |||
serviceConfig.Type = "oneshot"; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 48: | Line 48: | ||
Therefore, an example configuration could look like this:<syntaxhighlight lang="nix"> | Therefore, an example configuration could look like this:<syntaxhighlight lang="nix"> | ||
/ | // I'm hibernating into a logical volume that's also under LUKS. Pretty cool, right? | ||
swapDevices = [ | swapDevices = [ | ||
| Line 59: | Line 57: | ||
boot.resumeDevice = "/dev/dm-7"; | boot.resumeDevice = "/dev/dm-7"; | ||
</syntaxhighlight>Derived from a system with the following output from <code>swapon -s</code> :<syntaxhighlight> | </syntaxhighlight>Derived from a system with the following output from <code>swapon -s</code> :<syntaxhighlight lang="text">Filename Type Size Used Priority | ||
Filename Type Size Used Priority | |||
/dev/dm-7 partition 67108860 00 | /dev/dm-7 partition 67108860 00 | ||
/dev/zram0 partition 32881148 032767 | /dev/zram0 partition 32881148 032767</syntaxhighlight> | ||
</syntaxhighlight> | |||
Test and use hibernation with the following command:<syntaxhighlight lang="nix"> | Test and use hibernation with the following command:<syntaxhighlight lang="nix"> | ||
| Line 141: | Line 136: | ||
After finding out which component is causing unwanted wakeups you can use the sysfs id to find out the "vendor" and "device" fields: | After finding out which component is causing unwanted wakeups you can use the sysfs id to find out the "vendor" and "device" fields: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ cat /sys/class/pci_bus/0000:04/device/0000:04:00.0/vendor | $ cat /sys/class/pci_bus/0000:04/device/0000:04:00.0/vendor | ||
0x1987 | 0x1987 | ||
| Line 155: | Line 150: | ||
''; | ''; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Suspend blocked by <code>pre-sleep.service</code> === | |||
Sometimes, the system appears to suspend (Wi-Fi turns off, screen locks), but the hardware does not actually suspend, and all subsequent <code>systemctl suspend</code> or <code>systemctl reboot</code> commands are met with: | |||
<syntaxhighlight lang="console"> | |||
# systemctl suspend | |||
Call to Suspend failed: Action suspend already in progress, refusing requested suspend operation. | |||
# systemctl reboot | |||
Call to Reboot failed: Action suspend already in progress, refusing requested reboot operation. | |||
</syntaxhighlight> | |||
If directly telling the kernel to suspend as root works: | |||
<syntaxhighlight lang="console"> | |||
# echo mem > /sys/power/state | |||
</syntaxhighlight> | |||
Then a long-running <code>pre-sleep.service</code> might be hanging the sleep. This can be verified with <code>systemctl list-jobs</code>: | |||
<syntaxhighlight lang="console"> | |||
# systemctl list-jobs | |||
JOB UNIT TYPE STATE | |||
12144 suspend.target start waiting | |||
12149 pre-sleep.service start running | |||
12145 systemd-suspend.service start waiting | |||
12268 post-resume.target start waiting | |||
12148 sleep.target start waiting | |||
12269 post-resume.service start waiting | |||
</syntaxhighlight> | |||
Here, the <code>pre-sleep.service</code> is blocking and halting suspend. To see why, we can use <code>systemctl cat pre-sleep.service</code>: | |||
<syntaxhighlight lang="systemd"> | |||
# systemctl cat pre-sleep.service | |||
# /etc/systemd/system/pre-sleep.service | |||
[Unit] | |||
Before=sleep.target | |||
Description=Pre-Sleep Actions | |||
[Service] | |||
# <... Omitted Environment directives PATH, LOCALE_ARCHIVE, TZDIR ...> | |||
ExecStart=/nix/store/yzf7cpiqzq49san2frijxsh160zjy6fp-unit-script-pre-sleep-start/bin/pre-sleep-start | |||
Type=oneshot | |||
[Install] | |||
WantedBy=sleep.target | |||
</syntaxhighlight> | |||
In this case, the <code>pre-sleep-start</code> script referenced by <code>ExecStart</code> contained directives installed by the [[Displaylink]] package, that contained a flush operation which hung the suspend action. Starting <code>dlm.service</code> or running <code>sudo DisplayLinkManager</code> unblocks the script and made suspend work normally. | |||
==== Cancelling an existing suspend action ==== | |||
An existing suspend operation that is hung may be interrupted using <code>'''systemctl cancel'''</code> in case reboots or internet access is needed. | |||
== See also == | == See also == | ||