diff --git a/man/systemd.special.xml b/man/systemd.special.xml index 1434ead7d5..fe40da7fbe 100644 --- a/man/systemd.special.xml +++ b/man/systemd.special.xml @@ -41,6 +41,7 @@ hybrid-sleep.target, suspend-then-hibernate.target, initrd.target, + initrd-cryptsetup.target, initrd-fs.target, initrd-root-device.target, initrd-root-fs.target, @@ -182,8 +183,10 @@ cryptsetup.target - A target that pulls in setup services for all - encrypted block devices. + A target that pulls in setup services for local encrypted block devices. + See remote-cryptsetup.target below for the equivalent target for remote + volumes, and initrd-cryptsetup.target below for the equivalent target in the + initrd. @@ -352,12 +355,20 @@ initrd.target - This is the default target in the initramfs, similar to default.target + This is the default target in the initrd, similar to default.target in the main system. It is used to mount the real root and transition to it. See bootup7 for more discussion. + + initrd-cryptsetup.target + + A target that pulls in setup services for all encrypted block devices. See + cryptsetup.target and remote-cryptsetup.target for the + equivalent targets in the real root. + + initrd-fs.target @@ -549,7 +560,9 @@ Similar to cryptsetup.target, but for encrypted devices which are accessed over the network. It is used for crypttab8 - entries marked with . + entries marked with . + See cryptsetup.target for the equivalent target for local volumes, and + initrd-cryptsetup.target for the equivalent target in the initrd. 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; diff --git a/units/initrd-cryptsetup.target b/units/initrd-cryptsetup.target new file mode 100644 index 0000000000..2a2938c895 --- /dev/null +++ b/units/initrd-cryptsetup.target @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# 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=Initrd Encrypted Volumes +Documentation=man:systemd.special(7) +OnFailure=emergency.target +OnFailureJobMode=replace-irreversibly +AssertPathExists=/etc/initrd-release +DefaultDependencies=no +Conflicts=shutdown.target diff --git a/units/meson.build b/units/meson.build index 40ffca5058..a55e717868 100644 --- a/units/meson.build +++ b/units/meson.build @@ -28,6 +28,8 @@ units = [ ['hybrid-sleep.target', 'ENABLE_HIBERNATE'], ['suspend-then-hibernate.target', 'ENABLE_HIBERNATE'], ['initrd-cleanup.service', 'ENABLE_INITRD'], + ['initrd-cryptsetup.target', 'HAVE_LIBCRYPTSETUP ENABLE_INITRD', + 'sysinit.target.wants/'], ['initrd-fs.target', 'ENABLE_INITRD'], ['initrd-parse-etc.service', 'ENABLE_INITRD'], ['initrd-root-device.target', 'ENABLE_INITRD'],