Discussion:
[systemd-devel] enable/disable swap before/after hibernation
Lukas Pirl
2016-07-28 17:25:31 UTC
Permalink
Dear list,

I want to enable/disable the swap partition before/after hibernation.

However, it seems I cannot get the service to run early enough to avoid
the error:

Failed to hibernate system via logind: Sleep verb not supported

The .service file looks as follows:

[Unit]
Description=…
StopWhenUnneeded=true
Before=hibernate.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/swapon /my/device
ExecStop=/sbin/swapoff /my/device

[Install]
RequiredBy=hibernate.target

The service file itself works (with StopWhenUnneeded=true removed and
upon manual start/stop and verification).
It was installed by running `systemctl enable /path/to/file.service`

As another variation, I tried to hook against sleep.target and
hibernate.service with no luck.

Any help very much appreciated (this of course includes completely
different approaches).

Best,

Lukas
Lennart Poettering
2016-07-29 10:04:57 UTC
Permalink
Post by Lukas Pirl
Dear list,
I want to enable/disable the swap partition before/after hibernation.
However, it seems I cannot get the service to run early enough to avoid
Failed to hibernate system via logind: Sleep verb not supported
If clients ask logind whether hibernation is available or try to
initiate hibernation we check whether swap is available and refuse if
it isn't. This means if you add the swap only after the hibernation
was already initiated then this will not be able to affect the check
anymore.

You can bypass this check by setting the
SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK env var for the logind service
(add a drop-in using Environment= for it).

See https://github.com/systemd/systemd/pull/3064 and related.

Lennart
--
Lennart Poettering, Red Hat
Lukas Pirl
2016-07-29 11:48:13 UTC
Permalink
Post by Lennart Poettering
If clients ask logind whether hibernation is available or try to
initiate hibernation we check whether swap is available and refuse
if it isn't. This means if you add the swap only after the
hibernation was already initiated then this will not be able to
affect the check anymore.
I expected something like that – thanks for the explanation.
Post by Lennart Poettering
You can bypass this check by setting the
SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK env var for the logind
service (add a drop-in using Environment= for it).
See https://github.com/systemd/systemd/pull/3064 and related.
Excellent pointer! Thanks Lennart!

Loading...