]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/cryptsetup/cryptsetup-generator.c
cryptsetup-generator: run cryptsetup service before swap unit (#5480)
authorMauricio Faria de Oliveira <mauricio.foliveira@gmail.com>
Tue, 28 Feb 2017 20:30:22 +0000 (17:30 -0300)
committerLennart Poettering <lennart@poettering.net>
Tue, 28 Feb 2017 20:30:22 +0000 (21:30 +0100)
commita6f8786a56c0acba5997e2c58d0df6c80ffde7f1
tree4ff20ff1b42410cc2d9814b4149b5c35b9f9beac
parent9d70cba9879b3526aafe2dd2de7630758477b133
cryptsetup-generator: run cryptsetup service before swap unit (#5480)

If the cryptsetup service unit and swap unit for a swap device
are not strictly ordered, it might happen that the swap 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.
src/cryptsetup/cryptsetup-generator.c