diff --git a/src/integritysetup/integritysetup-generator.c b/src/integritysetup/integritysetup-generator.c index ab01873cdd..ce7a8ce178 100644 --- a/src/integritysetup/integritysetup-generator.c +++ b/src/integritysetup/integritysetup-generator.c @@ -80,7 +80,11 @@ static int create_disk( "SourcePath=%s\n" "DefaultDependencies=no\n" "IgnoreOnIsolate=true\n" - "After=integritysetup-pre.target systemd-udevd-kernel.socket\n" + /* The systemd-udevd.service ordering is mostly about shutdown, not startup: on stop the dm + * device is detached via an ioctl carrying a udev cookie that blocks in dm_udev_wait() until + * udev releases it (95-dm-notify.rules). Stopping before udevd keeps it around to service the + * cookie; otherwise during soft-reboot/shutdown udevd may exit first and the detach hangs. */ + "After=integritysetup-pre.target systemd-udevd-kernel.socket systemd-udevd.service\n" "Before=blockdev@dev-mapper-%%i.target\n" "Wants=blockdev@dev-mapper-%%i.target\n" "Conflicts=umount.target\n" diff --git a/src/shared/generator.c b/src/shared/generator.c index 36fdff5263..fa5bd25f1f 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -921,7 +921,12 @@ int generator_write_cryptsetup_unit_section(FILE *f, const char *source) { fprintf(f, "\n" "DefaultDependencies=no\n" - "After=cryptsetup-pre.target systemd-udevd-kernel.socket systemd-tpm2-setup-early.service\n" + /* The ordering against systemd-udevd.service is mostly about shutdown, not startup: on stop + * the device is detached via a device-mapper ioctl that carries a udev cookie, and we block in + * dm_udev_wait() until udev releases it (see 95-dm-notify.rules). Ordering After= it means we + * are stopped first, while udevd is still around to service that cookie; otherwise during + * soft-reboot/shutdown udevd may exit first and the detach hangs until the job timeout. */ + "After=cryptsetup-pre.target systemd-udevd-kernel.socket systemd-udevd.service systemd-tpm2-setup-early.service\n" "Before=blockdev@dev-mapper-%%i.target\n" "Wants=blockdev@dev-mapper-%%i.target\n" "IgnoreOnIsolate=true\n"); @@ -993,7 +998,11 @@ int generator_write_veritysetup_unit_section(FILE *f, const char *source) { fprintf(f, "DefaultDependencies=no\n" "IgnoreOnIsolate=true\n" - "After=veritysetup-pre.target systemd-udevd-kernel.socket\n" + /* The systemd-udevd.service ordering is mostly about shutdown, not startup: on stop the dm + * device is detached via an ioctl carrying a udev cookie that blocks in dm_udev_wait() until + * udev releases it (95-dm-notify.rules). Stopping before udevd keeps it around to service the + * cookie; otherwise during soft-reboot/shutdown udevd may exit first and the detach hangs. */ + "After=veritysetup-pre.target systemd-udevd-kernel.socket systemd-udevd.service\n" "Before=blockdev@dev-mapper-%%i.target\n" "Wants=blockdev@dev-mapper-%%i.target\n");