summaryrefslogtreecommitdiffstats
path: root/units
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-03-31 14:52:39 +0200
committerMike Yuan <me@yhndnzj.com>2024-04-03 16:07:43 +0200
commitdfad86b83807fa8696ca94982a5ba591b6d86a80 (patch)
tree1946fe262e29d7c26012ebb48aca1587ef12f532 /units
parenthibernate-resume: introduce --clear for clearing hibernate storage var (diff)
downloadsystemd-dfad86b83807fa8696ca94982a5ba591b6d86a80.tar.xz
systemd-dfad86b83807fa8696ca94982a5ba591b6d86a80.zip
units: introduce systemd-hibernate-clear.service that clears
stale HibernateLocation EFI variable Currently, if the HibernateLocation EFI variable exists, but we failed to resume from it, the boot carries on without clearing the stale variable. Therefore, the subsequent boots would still be waiting for the device timeout, unless the variable is purged manually. There's no point to keep trying to resume after a successful switch-root, because the hibernation image state would have been invalidated by then. OTOH, we don't want to clear the variable prematurely either, i.e. in initrd, since if the resume device is the same as root one, the boot won't succeed and the user might be able to try resuming again. So, let's introduce a unit that only runs after switch-root and clears the var. Fixes #32021
Diffstat (limited to 'units')
-rw-r--r--units/meson.build5
-rw-r--r--units/systemd-hibernate-clear.service.in24
2 files changed, 29 insertions, 0 deletions
diff --git a/units/meson.build b/units/meson.build
index 6fecbea0a1..16a5564086 100644
--- a/units/meson.build
+++ b/units/meson.build
@@ -313,6 +313,11 @@ units = [
{ 'file' : 'systemd-growfs@.service.in' },
{ 'file' : 'systemd-halt.service' },
{
+ 'file' : 'systemd-hibernate-clear.service.in',
+ 'conditions' : ['ENABLE_HIBERNATE', 'ENABLE_EFI'],
+ 'symlinks' : ['sysinit.target.wants/'],
+ },
+ {
'file' : 'systemd-hibernate-resume.service.in',
'conditions' : ['ENABLE_HIBERNATE'],
},
diff --git a/units/systemd-hibernate-clear.service.in b/units/systemd-hibernate-clear.service.in
new file mode 100644
index 0000000000..2e8587e692
--- /dev/null
+++ b/units/systemd-hibernate-clear.service.in
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of systemd.
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+[Unit]
+Description=Clear Stale Hibernate Storage Info
+Documentation=man:systemd-hibernate-clear.service(8)
+
+ConditionPathExists=/sys/firmware/efi/efivars/HibernateLocation-8cf2644b-4b0b-428f-9387-6d876050dc67
+ConditionPathExists=!/etc/initrd-release
+
+DefaultDependencies=no
+Before=sysinit.target shutdown.target
+Conflicts=shutdown.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart={{LIBEXECDIR}}/systemd-hibernate-resume --clear