Discussion:
[PATCHv6 0/3] hibernate-resume: implement support for resuming from hibernation
(too old to reply)
Ivan Shapovalov
2014-08-26 20:17:42 UTC
Permalink
This patchset allows systemd to parse resume= kernel command line parameter
and initiate resume from the specified device.

It adds:
- a 'systemd-hibernate-resume' tool which takes path to a device node and
writes its major:minor to /sys/power/resume;
- a corresponding 'systemd-hibernate-***@.service' templated unit;
- a 'systemd-hibernate-resume-generator' generator which parses the kernel
command line and instantiates the unit as necessary.

This functionality already exists in-kernel, but only for "/dev/sdXY"-style
pathes. Implementing it in userspace allows to use arbitrary udev-created
symlinks, e. g. persistent block device pathes ("/dev/disk/by-foo/bar") or
fstab-like specifiers ("FOO=bar").

Userspace parsing of resume= kernel command line parameter has been
traditionally done in initramfs via shell scripts (for Arch Linux, this is
"resume" mkinitcpio hook), so I feel that this feature has its place within
systemd.

Due to the nature of hibernation, the resume unit must be activated before
any modifications to filesystems take place. This can happen only in initramfs
before mounting anything.

So, first patch orders all non-root fsck after local-fs-pre.target, which in
turn allows to order the resume unit before those fsck instances.

Second and third patches add the tool, the unit and the generator.

Thanks for reviewing!

v2: fix issues pointed out by Andrei:
- don't RemainAfterExit because it's useless
- don't attempt to resume outside of initramfs because it's unsafe
(reiserfs replays journal even if mounted RO)

v3: fix mistakes spotted by Thomas:
- return 0 in main path of resume.c:process_resume()
- fix type and add missing cleanup attribute in resume-generator.c:main()

v4: drop the [RFC] prefix as there are no more issues with this approach;
incorporate feedback from Lennart:
- fix indentation in resume-generator.c:parse_proc_cmdline_item()
- remove overly aggressive 80-column line breaks
- don't Before=usr.mount and After=systemd-udevd.service
as the respective configurations are deemed broken
- reword the "Failed to resume" message and downgrade it to log_info()

v5: add the binaries and preprocessed unit to respective .gitignore files
incorporate feedback from Lennart:
- rename systemd-resume-* to systemd-hibernate-resume-*
incorporate feedback from Dave:
- use fstab_node_to_udev_node() in the generator to also handle fstab-like
specifiers

v6: rebase against master

Ivan Shapovalov (3):
units: order systemd-***@.service after local-fs-pre.target.
hibernate-resume: add a tool to write a device node's major:minor to /sys/power/resume.
hibernate-resume-generator: add a generator for instantiating the resume unit.

.gitignore | 2 +
Makefile-man.am | 9 +++
Makefile.am | 28 +++++++--
man/kernel-command-line.xml | 14 ++++-
man/systemd-hibernate-resume-generator.xml | 93 +++++++++++++++++++++++++++++
man/systemd-hibernate-***@.service.xml | 81 +++++++++++++++++++++++++
src/hibernate-resume/Makefile | 1 +
src/hibernate-resume/hibernate-resume.c | 81 +++++++++++++++++++++++++
src/resume-generator/Makefile | 1 +
src/resume-generator/resume-generator.c | 95 ++++++++++++++++++++++++++++++
units/.gitignore | 1 +
units/systemd-***@.service.in | 2 +-
units/systemd-hibernate-***@.service.in | 20 +++++++
13 files changed, 422 insertions(+), 6 deletions(-)
create mode 100644 man/systemd-hibernate-resume-generator.xml
create mode 100644 man/systemd-hibernate-***@.service.xml
create mode 120000 src/hibernate-resume/Makefile
create mode 100644 src/hibernate-resume/hibernate-resume.c
create mode 120000 src/resume-generator/Makefile
create mode 100644 src/resume-generator/resume-generator.c
create mode 100644 units/systemd-hibernate-***@.service.in
--
2.1.0
Ivan Shapovalov
2014-08-26 20:17:43 UTC
Permalink
With this change, it becomes possible to order a unit to activate before any
modifications to the file systems. This is especially useful for supporting
resume from hibernation.
---
units/systemd-***@.service.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/units/systemd-***@.service.in b/units/systemd-***@.service.in
index c12efa8..d2cda6a 100644
--- a/units/systemd-***@.service.in
+++ b/units/systemd-***@.service.in
@@ -10,7 +10,7 @@ Description=File System Check on %f
Documentation=man:systemd-***@.service(8)
DefaultDependencies=no
BindsTo=%i.device
-After=systemd-readahead-collect.service systemd-readahead-replay.service %i.device systemd-fsck-root.service
+After=systemd-readahead-collect.service systemd-readahead-replay.service %i.device systemd-fsck-root.service local-fs-pre.target
Before=shutdown.target

[Service]
--
2.1.0
Ivan Shapovalov
2014-08-26 20:17:45 UTC
Permalink
hibernate-resume-generator understands resume= kernel command line parameter
and instantiates the systemd-***@.service accordingly if it is passed.

This enables resume from hibernation using device specified on the kernel
command line, and it may be specified either as "/dev/disk/by-foo/bar"
or "FOO=bar", not only "/dev/sdXY" which is understood by the in-kernel
implementation.

So now resume= is brought on par with root= in terms of possible ways to
specify a device.
---
.gitignore | 1 +
Makefile-man.am | 2 +
Makefile.am | 11 +++-
man/kernel-command-line.xml | 14 ++++-
man/systemd-hibernate-resume-generator.xml | 93 +++++++++++++++++++++++++++++
src/resume-generator/Makefile | 1 +
src/resume-generator/resume-generator.c | 95 ++++++++++++++++++++++++++++++
7 files changed, 215 insertions(+), 2 deletions(-)
create mode 100644 man/systemd-hibernate-resume-generator.xml
create mode 120000 src/resume-generator/Makefile
create mode 100644 src/resume-generator/resume-generator.c

diff --git a/.gitignore b/.gitignore
index 0b5608c..8aed0b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -76,6 +76,7 @@
/systemd-gnome-ask-password-agent
/systemd-gpt-auto-generator
/systemd-hibernate-resume
+/systemd-hibernate-resume-generator
/systemd-hostnamed
/systemd-inhibit
/systemd-initctl
diff --git a/Makefile-man.am b/Makefile-man.am
index 09a1038..5c27937 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -70,6 +70,7 @@ MANPAGES += \
man/systemd-getty-generator.8 \
man/systemd-gpt-auto-generator.8 \
man/systemd-halt.service.8 \
+ man/systemd-hibernate-resume-generator.8 \
man/systemd-hibernate-***@.service.8 \
man/systemd-inhibit.1 \
man/systemd-initctl.service.8 \
@@ -1625,6 +1626,7 @@ EXTRA_DIST += \
man/systemd-getty-generator.xml \
man/systemd-gpt-auto-generator.xml \
man/systemd-halt.service.xml \
+ man/systemd-hibernate-resume-generator.xml \
man/systemd-hibernate-***@.service.xml \
man/systemd-hostnamed.service.xml \
man/systemd-inhibit.xml \
diff --git a/Makefile.am b/Makefile.am
index a487caa..cbdf551 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -385,7 +385,8 @@ systemgenerator_PROGRAMS = \
systemd-getty-generator \
systemd-fstab-generator \
systemd-system-update-generator \
- systemd-debug-generator
+ systemd-debug-generator \
+ systemd-hibernate-resume-generator

dist_bashcompletion_DATA = \
shell-completion/bash/busctl \
@@ -2146,6 +2147,14 @@ systemd_system_update_generator_LDADD = \
libsystemd-label.la \
libsystemd-shared.la

+# ------------------------------------------------------------------------------
+systemd_hibernate_resume_generator_SOURCES = \
+ src/resume-generator/resume-generator.c
+
+systemd_hibernate_resume_generator_LDADD = \
+ libsystemd-label.la \
+ libsystemd-shared.la
+
if ENABLE_EFI
# ------------------------------------------------------------------------------
systemgenerator_PROGRAMS += \
diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml
index 36428aa..d872e6d 100644
--- a/man/kernel-command-line.xml
+++ b/man/kernel-command-line.xml
@@ -351,6 +351,17 @@
</listitem>
</varlistentry>

+ <varlistentry>
+ <term><varname>resume=</varname></term>
+
+ <listitem>
+ <para>Enables resume from hibernation
+ using the specified device.
+ All <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>-like
+ pathes are supported. For details, see
+ <citerefentry><refentrytitle>systemd-hibernate-resume-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
+ </listitem>
+ </varlistentry>
</variablelist>

</refsect1>
@@ -373,7 +384,8 @@
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-modules-load.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-***@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>systemd-***@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>systemd-***@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>systemd-hibernate-resume-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
</para>
</refsect1>

diff --git a/man/systemd-hibernate-resume-generator.xml b/man/systemd-hibernate-resume-generator.xml
new file mode 100644
index 0000000..1a4b99c
--- /dev/null
+++ b/man/systemd-hibernate-resume-generator.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0"?>
+<!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<!--
+ This file is part of systemd.
+
+ Copyright 2014 Ivan Shapovalov
+
+ 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.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+<refentry id="systemd-hibernate-resume-generator">
+
+ <refentryinfo>
+ <title>systemd-hibernate-resume-generator</title>
+ <productname>systemd</productname>
+
+ <authorgroup>
+ <author>
+ <contrib>Developer</contrib>
+ <firstname>Ivan</firstname>
+ <surname>Shapovalov</surname>
+ <email>***@gmail.com</email>
+ </author>
+ </authorgroup>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>systemd-hibernate-resume-generator</refentrytitle>
+ <manvolnum>8</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>systemd-hibernate-resume-generator</refname>
+ <refpurpose>Unit generator for resume= kernel parameter</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <para><filename>/usr/lib/systemd/system-generators/systemd-hibernate-resume-generator</filename></para>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para><filename>systemd-hibernate-resume-generator</filename> is
+ a generator that instantiates
+ <citerefentry><refentrytitle>systemd-hibernate-***@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ unit according to the value of <option>resume=</option>
+ parameter specified on the kernel command line.</para>
+ </refsect1>
+
+ <refsect1>
+ <title>Kernel Command Line</title>
+
+ <para><filename>systemd-hibernate-resume-generator</filename> understands
+ the following kernel command line parameters:</para>
+
+ <variablelist class='kernel-commandline-options'>
+
+ <varlistentry>
+ <term><varname>resume=</varname></term>
+
+ <listitem><para>Takes a path to the resume
+ device. Both persistent block device pathes like
+ <filename>/dev/disk/by-foo/bar</filename> and
+ <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>-style
+ specifiers like <literal>FOO=bar</literal>
+ are supported.</para></listitem>
+ </varlistentry>
+
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>See Also</title>
+ <para>
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>systemd-hibernate-***@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ </para>
+ </refsect1>
+
+</refentry>
diff --git a/src/resume-generator/Makefile b/src/resume-generator/Makefile
new file mode 120000
index 0000000..d0b0e8e
--- /dev/null
+++ b/src/resume-generator/Makefile
@@ -0,0 +1 @@
+../Makefile
\ No newline at end of file
diff --git a/src/resume-generator/resume-generator.c b/src/resume-generator/resume-generator.c
new file mode 100644
index 0000000..f407216
--- /dev/null
+++ b/src/resume-generator/resume-generator.c
@@ -0,0 +1,95 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Ivan Shapovalov
+
+ 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.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdio.h>
+#include <errno.h>
+
+#include "log.h"
+#include "util.h"
+#include "special.h"
+#include "mkdir.h"
+#include "unit-name.h"
+
+static const char *arg_dest = "/tmp";
+static char *arg_resume_dev = NULL;
+
+static int parse_proc_cmdline_item(const char *key, const char *value) {
+ if (streq(key, "resume") && value) {
+ free(arg_resume_dev);
+ arg_resume_dev = fstab_node_to_udev_node(value);
+ if (!arg_resume_dev)
+ return log_oom();
+ }
+
+ return 0;
+}
+
+static int process_resume(void) {
+ _cleanup_free_ char *name = NULL, *lnk = NULL;
+
+ name = unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_dev, ".service");
+ if (!name)
+ return log_oom();
+
+ lnk = strjoin(arg_dest, "/" SPECIAL_SYSINIT_TARGET ".wants/", name, NULL);
+ if (!lnk)
+ return log_oom();
+
+ mkdir_parents_label(lnk, 0755);
+ if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-hibernate-***@.service", lnk) < 0) {
+ log_error("Failed to create symlink %s: %m", lnk);
+ return -errno;
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ int r = 0;
+
+ if (argc > 1 && argc != 4) {
+ log_error("This program takes three or no arguments.");
+ return EXIT_FAILURE;
+ }
+
+ if (argc > 1)
+ arg_dest = argv[1];
+
+ log_set_target(LOG_TARGET_SAFE);
+ log_parse_environment();
+ log_open();
+
+ umask(0022);
+
+ /* Don't even consider resuming outside of initramfs. */
+ if (!in_initrd())
+ return EXIT_SUCCESS;
+
+ if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
+ return EXIT_FAILURE;
+
+ if (arg_resume_dev != NULL)
+ r = process_resume();
+
+ free(arg_resume_dev);
+
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}
--
2.1.0
Ivan Shapovalov
2014-08-26 20:17:44 UTC
Permalink
This can be used to initiate a resume from hibernation by path to a swap
device containing the hibernation image.

The respective templated unit is also added. It is instantiated using
path to the desired resume device.
---
.gitignore | 1 +
Makefile-man.am | 7 +++
Makefile.am | 17 +++++--
man/systemd-hibernate-***@.service.xml | 81 ++++++++++++++++++++++++++++++
src/hibernate-resume/Makefile | 1 +
src/hibernate-resume/hibernate-resume.c | 81 ++++++++++++++++++++++++++++++
units/.gitignore | 1 +
units/systemd-hibernate-***@.service.in | 20 ++++++++
8 files changed, 206 insertions(+), 3 deletions(-)
create mode 100644 man/systemd-hibernate-***@.service.xml
create mode 120000 src/hibernate-resume/Makefile
create mode 100644 src/hibernate-resume/hibernate-resume.c
create mode 100644 units/systemd-hibernate-***@.service.in

diff --git a/.gitignore b/.gitignore
index 8189da7..0b5608c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@
/systemd-getty-generator
/systemd-gnome-ask-password-agent
/systemd-gpt-auto-generator
+/systemd-hibernate-resume
/systemd-hostnamed
/systemd-inhibit
/systemd-initctl
diff --git a/Makefile-man.am b/Makefile-man.am
index 562ecba..09a1038 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -70,6 +70,7 @@ MANPAGES += \
man/systemd-getty-generator.8 \
man/systemd-gpt-auto-generator.8 \
man/systemd-halt.service.8 \
+ man/systemd-hibernate-***@.service.8 \
man/systemd-inhibit.1 \
man/systemd-initctl.service.8 \
man/systemd-journald.service.8 \
@@ -199,6 +200,7 @@ MANPAGES_ALIAS += \
man/systemd-firstboot.service.1 \
man/systemd-fsck-root.service.8 \
man/systemd-fsck.8 \
+ man/systemd-hibernate-resume.8 \
man/systemd-hibernate.service.8 \
man/systemd-hybrid-sleep.service.8 \
man/systemd-initctl.8 \
@@ -305,6 +307,7 @@ man/systemd-ask-password-wall.service.8: man/systemd-ask-password-console.servic
man/systemd-firstboot.service.1: man/systemd-firstboot.1
man/systemd-fsck-root.service.8: man/systemd-***@.service.8
man/systemd-fsck.8: man/systemd-***@.service.8
+man/systemd-hibernate-resume.8: man/systemd-hibernate-***@.service.8
man/systemd-hibernate.service.8: man/systemd-suspend.service.8
man/systemd-hybrid-sleep.service.8: man/systemd-suspend.service.8
man/systemd-initctl.8: man/systemd-initctl.service.8
@@ -567,6 +570,9 @@ man/systemd-fsck-root.service.html: man/systemd-***@.service.html
man/systemd-fsck.html: man/systemd-***@.service.html
$(html-alias)

+man/systemd-hibernate-resume.html: man/systemd-hibernate-***@.service.html
+ $(html-alias)
+
man/systemd-hibernate.service.html: man/systemd-suspend.service.html
$(html-alias)

@@ -1619,6 +1625,7 @@ EXTRA_DIST += \
man/systemd-getty-generator.xml \
man/systemd-gpt-auto-generator.xml \
man/systemd-halt.service.xml \
+ man/systemd-hibernate-***@.service.xml \
man/systemd-hostnamed.service.xml \
man/systemd-inhibit.xml \
man/systemd-initctl.service.xml \
diff --git a/Makefile.am b/Makefile.am
index cbf98bd..a487caa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -378,7 +378,8 @@ rootlibexec_PROGRAMS = \
systemd-sleep \
systemd-bus-proxyd \
systemd-socket-proxyd \
- systemd-update-done
+ systemd-update-done \
+ systemd-hibernate-resume

systemgenerator_PROGRAMS = \
systemd-getty-generator \
@@ -528,7 +529,8 @@ nodist_systemunit_DATA = \
units/initrd-udevadm-cleanup-db.service \
units/initrd-switch-root.service \
units/systemd-***@.service \
- units/systemd-update-done.service
+ units/systemd-update-done.service \
+ units/systemd-hibernate-***@.service

dist_userunit_DATA = \
units/user/basic.target \
@@ -575,7 +577,8 @@ EXTRA_DIST += \
units/initrd-udevadm-cleanup-db.service.in \
units/initrd-switch-root.service.in \
units/systemd-***@.service.in \
- units/systemd-update-done.service.in
+ units/systemd-update-done.service.in \
+ units/systemd-hibernate-***@.service.in

CLEANFILES += \
units/console-shell.service.m4 \
@@ -2103,6 +2106,14 @@ systemd_delta_LDADD = \
libsystemd-shared.la

# ------------------------------------------------------------------------------
+systemd_hibernate_resume_SOURCES = \
+ src/hibernate-resume/hibernate-resume.c
+
+systemd_hibernate_resume_LDADD = \
+ libsystemd-internal.la \
+ libsystemd-shared.la
+
+# ------------------------------------------------------------------------------
systemd_getty_generator_SOURCES = \
src/getty-generator/getty-generator.c

diff --git a/man/systemd-hibernate-***@.service.xml b/man/systemd-hibernate-***@.service.xml
new file mode 100644
index 0000000..9b188b0
--- /dev/null
+++ b/man/systemd-hibernate-***@.service.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0"?>
+<!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<!--
+ This file is part of systemd.
+
+ Copyright 2014 Ivan Shapovalov
+
+ 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.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+<refentry id="systemd-hibernate-***@.service">
+
+ <refentryinfo>
+ <title>systemd-hibernate-***@.service</title>
+ <productname>systemd</productname>
+
+ <authorgroup>
+ <author>
+ <contrib>Developer</contrib>
+ <firstname>Ivan</firstname>
+ <surname>Shapovalov</surname>
+ <email>***@gmail.com</email>
+ </author>
+ </authorgroup>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>systemd-hibernate-***@.service</refentrytitle>
+ <manvolnum>8</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>systemd-hibernate-***@.service</refname>
+ <refname>systemd-hibernate-resume</refname>
+ <refpurpose>Resume from hibernation</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <para><filename>systemd-hibernate-***@.service</filename></para>
+ <para><filename>/usr/lib/systemd/systemd-hibernate-resume</filename></para>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para><filename>systemd-hibernate-***@.service</filename> is a
+ service that initiates hibernation resume from a device
+ containing the resume image. It is instantiated for each
+ device that is configured for resuming from.</para>
+
+ <para><filename>systemd-hibernate-resume</filename> only supports
+ the in-kernel hibernation implementation, known as swsusp.
+ Internally, it works by writing the major:minor of specified
+ device node to <filename>/sys/power/resume</filename>.</para>
+
+ <para>Failing to initiate a resume is not an error condition.
+ It may mean that there was no resume image (e. g. if the
+ system has been simply powered off and not hibernated). In
+ such case, the boot is ordinarily continued.</para>
+ </refsect1>
+
+ <refsect1>
+ <title>See Also</title>
+ <para>
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>systemd-hibernate-resume-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ </para>
+ </refsect1>
+
+</refentry>
diff --git a/src/hibernate-resume/Makefile b/src/hibernate-resume/Makefile
new file mode 120000
index 0000000..d0b0e8e
--- /dev/null
+++ b/src/hibernate-resume/Makefile
@@ -0,0 +1 @@
+../Makefile
\ No newline at end of file
diff --git a/src/hibernate-resume/hibernate-resume.c b/src/hibernate-resume/hibernate-resume.c
new file mode 100644
index 0000000..8f68f81
--- /dev/null
+++ b/src/hibernate-resume/hibernate-resume.c
@@ -0,0 +1,81 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Ivan Shapovalov
+
+ 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.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "log.h"
+#include "util.h"
+#include "fileio.h"
+
+int main(int argc, char *argv[]) {
+ struct stat st;
+ const char *device;
+ _cleanup_free_ char *major_minor = NULL;
+ int r;
+
+ if (argc != 2) {
+ log_error("This program expects one argument.");
+ return EXIT_FAILURE;
+ }
+
+ log_set_target(LOG_TARGET_AUTO);
+ log_parse_environment();
+ log_open();
+
+ umask(0022);
+
+ device = argv[1];
+
+ if (stat(device, &st) < 0) {
+ log_error("Failed to stat '%s': %m", device);
+ return EXIT_FAILURE;
+ }
+
+ if (!S_ISBLK(st.st_mode)) {
+ log_error("Resume device '%s' is not a block device.", device);
+ return EXIT_FAILURE;
+ }
+
+ if (asprintf(&major_minor, "%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) {
+ log_oom();
+ return EXIT_FAILURE;
+ }
+
+ r = write_string_file("/sys/power/resume", major_minor);
+ if (r < 0) {
+ log_error("Failed to write '%s' to /sys/power/resume: %s", major_minor, strerror(-r));
+ return EXIT_FAILURE;
+ }
+
+ /*
+ * The write above shall not return.
+ *
+ * However, failed resume is a normal condition (may mean that there is
+ * no hibernation image).
+ */
+
+ log_info("Could not resume from '%s' (%s).", device, major_minor);
+ return EXIT_SUCCESS;
+}
diff --git a/units/.gitignore b/units/.gitignore
index d9b60ac..c60f357 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -54,6 +54,7 @@
/systemd-reboot.service
/systemd-remount-fs.service
/systemd-resolved.service
+/systemd-hibernate-***@.service
/systemd-***@.service
/systemd-shutdownd.service
/systemd-suspend.service
diff --git a/units/systemd-hibernate-***@.service.in b/units/systemd-hibernate-***@.service.in
new file mode 100644
index 0000000..6db584d
--- /dev/null
+++ b/units/systemd-hibernate-***@.service.in
@@ -0,0 +1,20 @@
+# 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=Resume from hibernation using device %f
+Documentation=man:systemd-hibernate-***@.service(8)
+DefaultDependencies=no
+BindsTo=%i.device
+Wants=local-fs-pre.target
+After=%i.device
+Before=local-fs-pre.target systemd-remount-fs.service systemd-fsck-root.service
+ConditionPathExists=/etc/initrd-release
+
+[Service]
+Type=oneshot
+ExecStart=@rootlibexecdir@/systemd-hibernate-resume %f
--
2.1.0
Thomas Bächler
2014-08-27 06:18:38 UTC
Permalink
Post by Ivan Shapovalov
This can be used to initiate a resume from hibernation by path to a swap
device containing the hibernation image.
The respective templated unit is also added. It is instantiated using
path to the desired resume device.
Really great stuff, this was really missing from systemd initrd. I only
saw this because of your posting to the arch-projects list, so I am late
to the party. Anyway, although this is commited to systemd.git, there's
no reason it can't still be improved.
Post by Ivan Shapovalov
new file mode 100644
index 0000000..6db584d
--- /dev/null
@@ -0,0 +1,20 @@
+# 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=Resume from hibernation using device %f
+DefaultDependencies=no
+BindsTo=%i.device
What's the purpose of BindsTo= as opposed to Requires= here. They are
both the same for a oneshot service, but the former is more confusing.
Post by Ivan Shapovalov
+Wants=local-fs-pre.target
+After=%i.device
+Before=local-fs-pre.target systemd-remount-fs.service systemd-fsck-root.service
The part of ordering this Before=local-fs-pre.target is so crucial, it
can't be stressed enough. If _anything_ writes to _any_ file system
before this service runs, your system is broken and your data is lost.
That said, are you sure that all services are properly ordered against
the target?

What's the purpose of ordering this against systemd-fsck-root.service?
This service is not run in initrd ever, because it checks
'ConditionPathIsReadWrite=!/', which always fails in initrd.
Post by Ivan Shapovalov
+ConditionPathExists=/etc/initrd-release
We should have and use ConditionInitrd=. I am surprised that this
doesn't exist, but it really should.
Andrei Borzenkov
2014-08-27 06:59:15 UTC
Permalink
Post by Thomas Bächler
Post by Ivan Shapovalov
+[Unit]
+Description=Resume from hibernation using device %f
+DefaultDependencies=no
+BindsTo=%i.device
What's the purpose of BindsTo= as opposed to Requires= here. They are
both the same for a oneshot service, but the former is more confusing.
Semantic of Requires is simply wrong for device - you cannot "start"
device, you can only passively wait for it. Requisite is more
appropriate to express "cannot start until device is available". But I
think, BindsTo is established usage for devices and is quite clear
here.
Post by Thomas Bächler
Post by Ivan Shapovalov
+Wants=local-fs-pre.target
+After=%i.device
+Before=local-fs-pre.target systemd-remount-fs.service systemd-fsck-root.service
The part of ordering this Before=local-fs-pre.target is so crucial, it
can't be stressed enough. If _anything_ writes to _any_ file system
before this service runs, your system is broken and your data is lost.
That said, are you sure that all services are properly ordered against
the target?
What's the purpose of ordering this against systemd-fsck-root.service?
I suppose it is leftover from the first version which was intended to
support non-initrd case as well.
Lennart Poettering
2014-08-27 18:57:27 UTC
Permalink
Post by Andrei Borzenkov
Post by Thomas Bächler
Post by Ivan Shapovalov
+[Unit]
+Description=Resume from hibernation using device %f
+DefaultDependencies=no
+BindsTo=%i.device
What's the purpose of BindsTo= as opposed to Requires= here. They are
both the same for a oneshot service, but the former is more confusing.
Semantic of Requires is simply wrong for device - you cannot "start"
device, you can only passively wait for it. Requisite is more
appropriate to express "cannot start until device is available". But I
think, BindsTo is established usage for devices and is quite clear
here.
Well, "starting" a device means waitinf for it. Requires and Requisite
really have the same effect here...

Lennart
--
Lennart Poettering, Red Hat
Ivan Shapovalov
2014-08-27 07:22:09 UTC
Permalink
Post by Thomas Bächler
Post by Ivan Shapovalov
This can be used to initiate a resume from hibernation by path to a swap
device containing the hibernation image.
The respective templated unit is also added. It is instantiated using
path to the desired resume device.
Really great stuff, this was really missing from systemd initrd. I only
saw this because of your posting to the arch-projects list, so I am late
to the party. Anyway, although this is commited to systemd.git, there's
no reason it can't still be improved.
Post by Ivan Shapovalov
new file mode 100644
index 0000000..6db584d
--- /dev/null
@@ -0,0 +1,20 @@
+# 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=Resume from hibernation using device %f
+DefaultDependencies=no
+BindsTo=%i.device
What's the purpose of BindsTo= as opposed to Requires= here. They are
both the same for a oneshot service, but the former is more confusing.
This is just because systemd-***@.service does the same. Seems like it's
the "established usage", as Andrei says.
Post by Thomas Bächler
Post by Ivan Shapovalov
+Wants=local-fs-pre.target
+After=%i.device
+Before=local-fs-pre.target systemd-remount-fs.service systemd-fsck-root.service
The part of ordering this Before=local-fs-pre.target is so crucial, it
can't be stressed enough. If _anything_ writes to _any_ file system
before this service runs, your system is broken and your data is lost.
That said, are you sure that all services are properly ordered against
the target?
I've spent quite some time verifying this. The only thing not covered
is usr.mount (not sysroot-usr.mount), but Lennart says any configuration
with initramfs's /usr split off is broken.

(Yes, I assume that lvm2, mdadm/mdmon, dm-event and so on don't write
to filesystems. If I'm wrong -- this needs to be fixed...)
Post by Thomas Bächler
What's the purpose of ordering this against systemd-fsck-root.service?
This service is not run in initrd ever, because it checks
'ConditionPathIsReadWrite=!/', which always fails in initrd.
Just a leftover, indeed. These services do not exist in initramfs.
They probably should be removed in a separate commit.
Post by Thomas Bächler
Post by Ivan Shapovalov
+ConditionPathExists=/etc/initrd-release
We should have and use ConditionInitrd=. I am surprised that this
doesn't exist, but it really should.
Would you accept a patch adding that (using in_initrd()) and converting
all uses of ConditionPathExists=/etc/initrd-release to this new
condition statement?

Thanks for review!
--
Ivan Shapovalov / intelfx /
Thomas Bächler
2014-08-27 07:35:45 UTC
Permalink
Post by Ivan Shapovalov
Post by Thomas Bächler
Post by Ivan Shapovalov
+[Unit]
+Description=Resume from hibernation using device %f
+DefaultDependencies=no
+BindsTo=%i.device
What's the purpose of BindsTo= as opposed to Requires= here. They are
both the same for a oneshot service, but the former is more confusing.
the "established usage", as Andrei says.
BindsTo=
Configures requirement dependencies, very similar in style to
Requires=, however in addition to this behavior, it also declares that
this unit is stopped when any of the units listed suddenly disappears.

"Stopping" a oneshot unit makes no sense, that's why I find BindsTo
confusing. If systemd-***@.service does the same, then we should do the
same thing here.
Post by Ivan Shapovalov
Post by Thomas Bächler
The part of ordering this Before=local-fs-pre.target is so crucial, it
can't be stressed enough. If _anything_ writes to _any_ file system
before this service runs, your system is broken and your data is lost.
That said, are you sure that all services are properly ordered against
the target?
I've spent quite some time verifying this. The only thing not covered
is usr.mount (not sysroot-usr.mount), but Lennart says any configuration
with initramfs's /usr split off is broken.
I've never heard of such a configuration.
Post by Ivan Shapovalov
(Yes, I assume that lvm2, mdadm/mdmon, dm-event and so on don't write
to filesystems. If I'm wrong -- this needs to be fixed...)
They really shouldn't. And they may be required for resuming (you can
resume from swap on lvm on an encrypted container, which is a rather
common setup).
Post by Ivan Shapovalov
Post by Thomas Bächler
Post by Ivan Shapovalov
+ConditionPathExists=/etc/initrd-release
We should have and use ConditionInitrd=. I am surprised that this
doesn't exist, but it really should.
Would you accept a patch adding that (using in_initrd()) and converting
all uses of ConditionPathExists=/etc/initrd-release to this new
condition statement?
I am not the one to accept patches here, but I'd love to see this
implemented.
Lennart Poettering
2014-08-27 18:55:48 UTC
Permalink
Post by Thomas Bächler
Post by Ivan Shapovalov
+[Unit]
+Description=Resume from hibernation using device %f
+DefaultDependencies=no
+BindsTo=%i.device
What's the purpose of BindsTo= as opposed to Requires= here. They are
both the same for a oneshot service, but the former is more confusing.
Yeah, I figure Requires= might be slightly more appropriate for this,
given that it fails on its own if the device ends up not being available
anymore...
Post by Thomas Bächler
What's the purpose of ordering this against systemd-fsck-root.service?
This service is not run in initrd ever, because it checks
'ConditionPathIsReadWrite=!/', which always fails in initrd.
I think for most purposes we should consider the initrd mostly
read-only, hence I wouldn't rely on this check, even though it might
effectively make the dep unnecessary...
Post by Thomas Bächler
Post by Ivan Shapovalov
+ConditionPathExists=/etc/initrd-release
We should have and use ConditionInitrd=. I am surprised that this
doesn't exist, but it really should.
Why?

Lennart
--
Lennart Poettering, Red Hat
Lennart Poettering
2014-08-26 20:21:59 UTC
Permalink
On Wed, 27.08.14 00:17, Ivan Shapovalov (***@gmail.com) wrote:

Applied all three! Thanks!
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line parameter
and initiate resume from the specified device.
- a 'systemd-hibernate-resume' tool which takes path to a device node and
writes its major:minor to /sys/power/resume;
- a 'systemd-hibernate-resume-generator' generator which parses the kernel
command line and instantiates the unit as necessary.
This functionality already exists in-kernel, but only for "/dev/sdXY"-style
pathes. Implementing it in userspace allows to use arbitrary udev-created
symlinks, e. g. persistent block device pathes ("/dev/disk/by-foo/bar") or
fstab-like specifiers ("FOO=bar").
Userspace parsing of resume= kernel command line parameter has been
traditionally done in initramfs via shell scripts (for Arch Linux, this is
"resume" mkinitcpio hook), so I feel that this feature has its place within
systemd.
Due to the nature of hibernation, the resume unit must be activated before
any modifications to filesystems take place. This can happen only in initramfs
before mounting anything.
So, first patch orders all non-root fsck after local-fs-pre.target, which in
turn allows to order the resume unit before those fsck instances.
Second and third patches add the tool, the unit and the generator.
Thanks for reviewing!
- don't RemainAfterExit because it's useless
- don't attempt to resume outside of initramfs because it's unsafe
(reiserfs replays journal even if mounted RO)
- return 0 in main path of resume.c:process_resume()
- fix type and add missing cleanup attribute in resume-generator.c:main()
v4: drop the [RFC] prefix as there are no more issues with this approach;
- fix indentation in resume-generator.c:parse_proc_cmdline_item()
- remove overly aggressive 80-column line breaks
- don't Before=usr.mount and After=systemd-udevd.service
as the respective configurations are deemed broken
- reword the "Failed to resume" message and downgrade it to log_info()
v5: add the binaries and preprocessed unit to respective .gitignore files
- rename systemd-resume-* to systemd-hibernate-resume-*
- use fstab_node_to_udev_node() in the generator to also handle fstab-like
specifiers
v6: rebase against master
hibernate-resume: add a tool to write a device node's major:minor to /sys/power/resume.
hibernate-resume-generator: add a generator for instantiating the resume unit.
.gitignore | 2 +
Makefile-man.am | 9 +++
Makefile.am | 28 +++++++--
man/kernel-command-line.xml | 14 ++++-
man/systemd-hibernate-resume-generator.xml | 93 +++++++++++++++++++++++++++++
src/hibernate-resume/Makefile | 1 +
src/hibernate-resume/hibernate-resume.c | 81 +++++++++++++++++++++++++
src/resume-generator/Makefile | 1 +
src/resume-generator/resume-generator.c | 95 ++++++++++++++++++++++++++++++
units/.gitignore | 1 +
13 files changed, 422 insertions(+), 6 deletions(-)
create mode 100644 man/systemd-hibernate-resume-generator.xml
create mode 120000 src/hibernate-resume/Makefile
create mode 100644 src/hibernate-resume/hibernate-resume.c
create mode 120000 src/resume-generator/Makefile
create mode 100644 src/resume-generator/resume-generator.c
Lennart
--
Lennart Poettering, Red Hat
Zbigniew Jędrzejewski-Szmek
2014-08-27 01:16:10 UTC
Permalink
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line parameter
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?

Zbyszek
Ivan Shapovalov
2014-08-27 09:17:05 UTC
Permalink
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line parameter
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.

After a cursory search, I could not find a mechanism to initiate a resume with
offset from userspace. In Arch, it was never implemented even if possible.

--
Ivan Shapovalov / intelfx /
Lennart Poettering
2014-08-27 18:53:09 UTC
Permalink
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line parameter
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.
After a cursory search, I could not find a mechanism to initiate a resume with
offset from userspace. In Arch, it was never implemented even if possible.
I wouldn't bother until somebody actually really runs into this. And
even then I'd be careful whether we really want to support that...

Lennart
--
Lennart Poettering, Red Hat
Jan Janssen
2014-08-28 06:25:51 UTC
Permalink
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line parameter
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.
After a cursory search, I could not find a mechanism to initiate a resume with
offset from userspace. In Arch, it was never implemented even if possible.
I'm a heavy user of this myself. It's especially useful because you can just
have a single luks encrypted ext4 without a lvm in between for a swap
partition or (even more yuck) using a separate (encrypted) swap partition.

Arch does support this, mostly because as far as I know, the resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution waits
for the device to show up in /dev/ (and especially /dev/mapper/ for my
case), this should work out.

Here's information to set this up. Imho more people should be aware this is
possible:
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file

Jan
Ivan Shapovalov
2014-08-28 07:33:44 UTC
Permalink
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line
parameter
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.
After a cursory search, I could not find a mechanism to initiate a resume with
offset from userspace. In Arch, it was never implemented even if possible.
I'm a heavy user of this myself. It's especially useful because you can just
have a single luks encrypted ext4 without a lvm in between for a swap
partition or (even more yuck) using a separate (encrypted) swap partition.
Arch does support this, mostly because as far as I know, the resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution waits
for the device to show up in /dev/ (and especially /dev/mapper/ for my
case), this should work out.
Here's information to set this up. Imho more people should be aware this is
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file
Jan
Hmm, so is resume_offset= parsed independently of resume=? If that's the
case, and resume_offset= can be parsed by kernel while resume= is parsed
by userspace, then yes, I was wrong and this should work.

Actually, it should work _just like before_, sans tuxonice support.
--
Ivan Shapovalov / intelfx /
Jan Janssen
2014-08-28 17:36:53 UTC
Permalink
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line
parameter
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.
After a cursory search, I could not find a mechanism to initiate a
resume with offset from userspace. In Arch, it was never implemented
even if possible.>
I'm a heavy user of this myself. It's especially useful because you can
just have a single luks encrypted ext4 without a lvm in between for a
swap partition or (even more yuck) using a separate (encrypted) swap
partition.
Arch does support this, mostly because as far as I know, the
resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution
waits for the device to show up in /dev/ (and especially /dev/mapper/ for
my case), this should work out.
Here's information to set this up. Imho more people should be aware this is
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file
Jan
Hmm, so is resume_offset= parsed independently of resume=? If that's the
case, and resume_offset= can be parsed by kernel while resume= is parsed
by userspace, then yes, I was wrong and this should work.
Actually, it should work _just like before_, sans tuxonice support.
I gave it a try and resume works for me with that sd-resume hook in arch. But I'm not too sure whether fsck is delayed properly:

systemd[1]: Started Cryptography Setup for luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Found device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Starting File System Check on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
systemd[1]: Starting Resume from hibernation using device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
systemd-fsck[135]: fsck.ext4 doesn't exist, not checking file system on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78
systemd[1]: Starting Encrypted Volumes.
systemd[1]: Reached target Encrypted Volumes.
systemd[1]: Starting System Initialization.
systemd[1]: Reached target System Initialization.
systemd[1]: Starting Basic System.
systemd[1]: Reached target Basic System.
systemd[1]: Started File System Check on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
kernel: PM: Starting manual resume from disk
kernel: PM: Hibernation image partition 254:0 present
kernel: PM: Looking for hibernation image.
systemd-hibernate-resume[137]: Could not resume from '/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78' (254:0).
systemd[1]: Started Resume from hibernation using device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.

If I read this correctly, the moment the plaintext device appears, the resume and fsck are racing each other. And in this case,
fsck won (good thing my fsck binaries are not in the systemd initrd for now).

Jan
Andrei Borzenkov
2014-08-29 02:28:09 UTC
Permalink
В Thu, 28 Aug 2014 19:36:53 +0200
Post by Jan Janssen
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line
parameter
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.
After a cursory search, I could not find a mechanism to initiate a
resume with offset from userspace. In Arch, it was never implemented
even if possible.>
I'm a heavy user of this myself. It's especially useful because you can
just have a single luks encrypted ext4 without a lvm in between for a
swap partition or (even more yuck) using a separate (encrypted) swap
partition.
Arch does support this, mostly because as far as I know, the resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution
waits for the device to show up in /dev/ (and especially /dev/mapper/ for
my case), this should work out.
Here's information to set this up. Imho more people should be aware this is
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file
Jan
Hmm, so is resume_offset= parsed independently of resume=? If that's the
case, and resume_offset= can be parsed by kernel while resume= is parsed
by userspace, then yes, I was wrong and this should work.
Actually, it should work _just like before_, sans tuxonice support.
systemd[1]: Started Cryptography Setup for luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Found device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Starting File System Check on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
Hmm ... it is not systemd-fsck-root.service. Do you have
local-fs-pre.target installed in initrd? What units are there at all?
Post by Jan Janssen
systemd[1]: Starting Resume from hibernation using device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
systemd-fsck[135]: fsck.ext4 doesn't exist, not checking file system on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78
systemd[1]: Starting Encrypted Volumes.
systemd[1]: Reached target Encrypted Volumes.
systemd[1]: Starting System Initialization.
systemd[1]: Reached target System Initialization.
systemd[1]: Starting Basic System.
systemd[1]: Reached target Basic System.
systemd[1]: Started File System Check on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
kernel: PM: Starting manual resume from disk
kernel: PM: Hibernation image partition 254:0 present
kernel: PM: Looking for hibernation image.
systemd-hibernate-resume[137]: Could not resume from '/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78' (254:0).
systemd[1]: Started Resume from hibernation using device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
If I read this correctly, the moment the plaintext device appears, the resume and fsck are racing each other. And in this case,
fsck won (good thing my fsck binaries are not in the systemd initrd for now).
Jan
_______________________________________________
systemd-devel mailing list
http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Jan Janssen
2014-08-29 13:15:12 UTC
Permalink
Post by Andrei Borzenkov
В Thu, 28 Aug 2014 19:36:53 +0200
Post by Jan Janssen
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
This patchset allows systemd to parse resume= kernel command line
parameter
Post by Ivan Shapovalov
Post by Zbigniew Jędrzejewski-Szmek
Post by Ivan Shapovalov
and initiate resume from the specified device.
What about swap files with the resume_offset= parameter? Are they still
being used?
I don't know if somebody uses that, but for now it's missing functionality.
After a cursory search, I could not find a mechanism to initiate a
resume with offset from userspace. In Arch, it was never implemented
even if possible.>
I'm a heavy user of this myself. It's especially useful because you can
just have a single luks encrypted ext4 without a lvm in between for a
swap partition or (even more yuck) using a separate (encrypted) swap
partition.
Arch does support this, mostly because as far as I know, the resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution
waits for the device to show up in /dev/ (and especially /dev/mapper/ for
my case), this should work out.
Here's information to set this up. Imho more people should be aware this is
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file
Jan
Hmm, so is resume_offset= parsed independently of resume=? If that's the
case, and resume_offset= can be parsed by kernel while resume= is parsed
by userspace, then yes, I was wrong and this should work.
Actually, it should work _just like before_, sans tuxonice support.
systemd[1]: Started Cryptography Setup for luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Found device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Starting File System Check on /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
Hmm ... it is not systemd-fsck-root.service. Do you have
local-fs-pre.target installed in initrd? What units are there at all?
never mind, I failed to update the system-***@.service that had the new
dependency.

Jan

Loading...