diff -Nru systemd-232/debian/changelog systemd-232/debian/changelog --- systemd-232/debian/changelog 2017-02-16 16:33:24.000000000 -0600 +++ systemd-232/debian/changelog 2017-02-27 15:29:32.000000000 -0600 @@ -1,3 +1,10 @@ +systemd (232-18ubuntu1cryptswap1) UNRELEASED; urgency=medium + + * debian/patches/cryptsetup-generator-run-service-before-swap.patch: + Run cryptsetup service before swap target for a swap device (LP: #) + + -- Mauricio Faria de Oliveira Mon, 27 Feb 2017 18:29:32 -0300 + systemd (232-18ubuntu1) zesty; urgency=medium [ Martin Pitt ] diff -Nru systemd-232/debian/patches/cryptsetup-generator-run-service-before-swap-target.patch systemd-232/debian/patches/cryptsetup-generator-run-service-before-swap-target.patch --- systemd-232/debian/patches/cryptsetup-generator-run-service-before-swap-target.patch 1969-12-31 18:00:00.000000000 -0600 +++ systemd-232/debian/patches/cryptsetup-generator-run-service-before-swap-target.patch 2017-02-27 15:29:32.000000000 -0600 @@ -0,0 +1,80 @@ +Forwarded: https://github.com/systemd/systemd/pull/5480 +From: Mauricio Faria de Oliveira +Date: Mon, 27 Feb 2017 18:15:03 -0300 +Subject: [PATCH] cryptsetup-generator: run cryptsetup service before swap target + +If the cryptsetup service unit and swap target unit for a swap device +are not strictly ordered, it might happen that the swap target unit +activates/mounts the swap device before its cryptsetup service unit +has a chance to run the 'mkswap' command (that it is programmed to). + +This leads to the following error: + + Starting Cryptography Setup for sda3_crypt... + [ OK ] Found device /dev/mapper/sda3_crypt. + Activating swap /dev/mapper/sda3_crypt... + [ OK ] Activated swap /dev/mapper/sda3_crypt. + [ OK ] Reached target Swap. + [FAILED] Failed to start Cryptography Setup for sda3_crypt. + See 'systemctl status systemd-cryptsetup@sda3_crypt.service' for + details. + [DEPEND] Dependency failed for Encrypted Volumes. + +Which happens because the swap device is already mounted: + + # systemctl status systemd-cryptsetup@sda3_crypt.service + <...> + Active: failed (Result: exit-code) since Mon 2017-02-27 14:21:43 CST; + 54s ago + <...> + + <...> systemd[1]: Starting Cryptography Setup for sda3_crypt... + <...> mkswap[2420]: mkswap: error: /dev/mapper/sda3_crypt is mounted; + will not make swapspace + <...> + +So, modify cryptsetup-generator to include a 'Before=' option for the +respective 'dev-mapper-%i.swap' device in the cryptsetup service unit. + +Now, correct ordering is ensured, and the error no longer occurs: + + Starting Cryptography Setup for sda3_crypt... + [ OK ] Found device /dev/mapper/sda3_crypt. + [ OK ] Started Cryptography Setup for sda3_crypt. + Activating swap /dev/mapper/sda3_crypt... + [ OK ] Reached target Encrypted Volumes. + [ OK ] Activated swap /dev/mapper/sda3_crypt. + [ OK ] Reached target Swap. + +Signed-off-by: Mauricio Faria de Oliveira +--- + src/cryptsetup/cryptsetup-generator.c | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c +index 23bf0149295a..b58b6db7c9c9 100644 +--- a/src/cryptsetup/cryptsetup-generator.c ++++ b/src/cryptsetup/cryptsetup-generator.c +@@ -144,13 +144,17 @@ static int create_disk( + } + } + +- if (is_device_path(u)) ++ if (is_device_path(u)) { + fprintf(f, + "BindsTo=%s\n" + "After=%s\n" + "Before=umount.target\n", + d, d); +- else ++ ++ if (swap) ++ fputs("Before=dev-mapper-%i.swap\n", ++ f); ++ } else + fprintf(f, + "RequiresMountsFor=%s\n", + u); +-- +1.8.3.1 + diff -Nru systemd-232/debian/patches/series systemd-232/debian/patches/series --- systemd-232/debian/patches/series 2017-02-15 10:27:49.000000000 -0600 +++ systemd-232/debian/patches/series 2017-02-27 15:29:32.000000000 -0600 @@ -69,3 +69,4 @@ debian/Revert-core-enable-TasksMax-for-all-services-by-default-a.patch debian/Let-graphical-session-pre.target-be-manually-started.patch debian/Add-env-variable-for-machine-ID-path.patch +cryptsetup-generator-run-service-before-swap-target.patch