From 122860f10225a8d7c82df73af5ef8316a8e134b6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Apr 2021 11:19:29 +0200 Subject: [PATCH 1/2] generator: exit early when asked to generate fsck unit for / and /usr in initrd Let's exit early if we are invoked to generate an fsck unit for the rootfs or /usr of the initrd itself. The "systemd-root-fsck.service" and "systemd-usr-fsck.service" units are after all for the host file systems, and the initrd file hierarchy is from an unpacked cpio anyway. Hence, this semantically doesn't really make sense, so quickly exit if we detect this case. This allows us to remove some checks further down the codepath. --- src/shared/generator.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shared/generator.c b/src/shared/generator.c index 5b9c432527..7d00c9ef0d 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -138,6 +138,13 @@ int generator_write_fsck_deps( assert(what); assert(where); + /* Let's do an early exit if we are invoked for the root and /usr/ trees in the initrd, to avoid + * generating confusing log messages */ + if (in_initrd() && PATH_IN_SET(where, "/", "/usr")) { + log_debug("Skipping fsck for %s in initrd.", where); + return 0; + } + if (!is_device_path(what)) { log_warning("Checking was requested for \"%s\", but it is not a device.", what); return 0; @@ -180,7 +187,7 @@ int generator_write_fsck_deps( * Requires= from /usr onto a fsck@.service unit and that unit is shut down, then * we'd have to unmount /usr too. */ - dep = !in_initrd() && path_equal(where, "/usr") ? "Wants" : "Requires"; + dep = path_equal(where, "/usr") ? "Wants" : "Requires"; r = unit_name_from_path_instance("systemd-fsck", what, ".service", &_fsck); if (r < 0) From 599aee40a3e626e59e4e2d7cca465b5bb96e1cdb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Apr 2021 11:21:50 +0200 Subject: [PATCH 2/2] generator: explain why systemd-root-fsck.service exists in a comment --- src/shared/generator.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/generator.c b/src/shared/generator.c index 7d00c9ef0d..1daa9e7de8 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -164,6 +164,11 @@ int generator_write_fsck_deps( if (path_equal(where, "/")) { const char *lnk; + /* We support running the fsck instance for the root fs while it is already mounted, for + * compatibility with non-initrd boots. It's ugly, but it is how it is. Since – unlike for + * regular file systems – this means the ordering is reversed (i.e. mount *before* fsck) we + * have a separate fsck unit for this, independent of systemd-fsck@.service. */ + lnk = strjoina(dir, "/" SPECIAL_LOCAL_FS_TARGET ".wants/" SPECIAL_FSCK_ROOT_SERVICE); (void) mkdir_parents(lnk, 0755);