[systemd-devel] [PATCH 3/3] Use a stamp file to avoid running systemd-fsck-root.service twice
Andrei Borzenkov
arvidjaar at gmail.com
Sat May 2 10:26:25 PDT 2015
В Sat, 2 May 2015 13:16:59 -0400
Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl> пишет:
> In the initramfs, we run systemd-fsck@<sysroot-device>.service.
> In the real system we run systemd-fsck-root.service. It is hard
> to pass the information that the latter should not run if the first
> succeeded using unit state only.
>
> - in the real system, we need a synchronization point between the fsck
> for root and other fscks, to express the dependency to run this
> systemd-fsck at .service "before all other systemd-fsck@ units". We
> cannot express it directly, because there are no wildcard
> dependencies. We could use a target as a sychronization point, but
> then we would have to provide drop-ins to order
> systemd-fsck at -.service before the target, and all others after it,
> which becomes messy. The currently used alternative of having a
> special unit (systemd-fsck-root.service) makes it easy to express
> this dependency, and seems to be the best solution.
>
> - we cannot use systemd-fsck-root.service in the initramfs, because
> other fsck units should not be ordered after it. In the real system,
> the root device is always checked and mounted before other filesystems,
> but in the initramfs this doesn't have to be true: /sysroot might be
> stacked on other filesystems and devices.
>
> - the name of the root device can legitimately be specified in a
> different way in the initramfs (on the kernel command line, or
> automatically discovered through GPT), and in the real fs (in /etc/fstab).
> Even if we didn't need systemd-fsck-root.service as a synchronization
> point, it would be hard to ensure the same instance parameter is
> provided for systemd-fsck at .service in the initrams and the real
> system.
>
> Let's use a "side channel" to pass this information.
> /run/systemd/fsck-root-done is touched after fsck in the initramfs
> succeeds, through an ExecStartPost line in a drop-in for
> systemd-fsck at sysroot.service.
You probably should mention that it effectively reverts
956eaf2b8d6c9999024705ddadc7393bc707de02.
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1201979
> ---
> src/shared/generator.c | 7 +++++++
> units/systemd-fsck-root.service.in | 1 +
> 2 files changed, 8 insertions(+)
>
> diff --git a/src/shared/generator.c b/src/shared/generator.c
> index 7b2f846175..a71222d1cb 100644
> --- a/src/shared/generator.c
> +++ b/src/shared/generator.c
> @@ -78,6 +78,13 @@ int generator_write_fsck_deps(
> "RequiresOverridable=%1$s\n"
> "After=%1$s\n",
> fsck);
> +
> + if (in_initrd() && path_equal(where, "/sysroot"))
> + return write_drop_in_format(dir, fsck, 50, "stamp",
> + "# Automatically generated by %s\n\n"
> + "[Service]\n"
> + "ExecStartPost=-/bin/touch /run/systemd/fsck-root-done\n",
> + program_invocation_short_name);
> }
>
> return 0;
> diff --git a/units/systemd-fsck-root.service.in b/units/systemd-fsck-root.service.in
> index 3617abf04a..48dacc841c 100644
> --- a/units/systemd-fsck-root.service.in
> +++ b/units/systemd-fsck-root.service.in
> @@ -11,6 +11,7 @@ Documentation=man:systemd-fsck-root.service(8)
> DefaultDependencies=no
> Before=local-fs.target shutdown.target
> ConditionPathIsReadWrite=!/
> +ConditionPathExists=!/run/systemd/fsck-root-done
>
> [Service]
> Type=oneshot
More information about the systemd-devel
mailing list