diff options
author | Jonathan Lebon <jonathan@jlebon.com> | 2020-10-20 16:30:20 -0400 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-10-21 22:08:19 +0200 |
commit | 6c5496c492a8d74e54d22bf8824160cab1e63c10 (patch) | |
tree | 5dd28fa028c3d690e41449870037a24bac6a7152 /src/cryptsetup/cryptsetup-generator.c | |
parent | 69f30d4321c3bc8fa27270e3fd36a7a5b4d0a89e (diff) | |
download | systemd-6c5496c492a8d74e54d22bf8824160cab1e63c10.tar.gz |
units: add initrd-cryptsetup.target
For encrypted block devices that we need to unlock from the initramfs,
we currently rely on dracut shipping `cryptsetup.target`. This works,
but doesn't cover the case where the encrypted block device requires
networking (i.e. the `remote-cryptsetup.target` version). That target
however is traditionally dynamically enabled.
Instead, let's rework things here by adding a `initrd-cryptsetup.target`
specifically for initramfs encrypted block device setup. This plays the
role of both `cryptsetup.target` and `remote-cryptsetup.target` in the
initramfs.
Then, adapt `systemd-cryptsetup-generator` to hook all generated
services to this new unit when running from the initrd. This is
analogous to `systemd-fstab-generator` hooking all mounts to
`initrd-fs.target`, regardless of whether they're network-backed or not.
Diffstat (limited to 'src/cryptsetup/cryptsetup-generator.c')
-rw-r--r-- | src/cryptsetup/cryptsetup-generator.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index df589ec3e4..13e9f3aedd 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -455,10 +455,16 @@ static int create_disk( } } + const char *target; + if (in_initrd()) + target = "initrd-cryptsetup.target"; + else if (netdev) + target = "remote-cryptsetup.target"; + else + target = "cryptsetup.target"; + if (!nofail) - fprintf(f, - "Before=%s\n", - netdev ? "remote-cryptsetup.target" : "cryptsetup.target"); + fprintf(f, "Before=%s\n", target); if (password && !keydev) { r = print_dependencies(f, password); @@ -521,8 +527,7 @@ static int create_disk( return log_error_errno(r, "Failed to write unit file %s: %m", n); if (!noauto) { - r = generator_add_symlink(arg_dest, - netdev ? "remote-cryptsetup.target" : "cryptsetup.target", + r = generator_add_symlink(arg_dest, target, nofail ? "wants" : "requires", n); if (r < 0) return r; |