summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-05-06 01:09:53 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-05-10 13:17:57 -0400
commit4dda4e637e4c17a14db6cd265f36f5e8a5050367 (patch)
tree3d0bc2083fbce339adf9bca64a59bc8c42cc653d
parent7703bd4d2874a6becc2be60e284c4a547c28320b (diff)
Generate systemd-fsck-root.service in the initramfs
In the initrafms, generate a systemd-fsck-root.service to replace systemd-fsck@<sysroot-device>.service. This way, after we transition to the real root, systemd-fsck-root.service is marked as already done. This introduces an unnecessary synchronization point, because systemd-fsck@* is ordered after systemd-fsck-root also in the initramfs. In practice this shouldn't be a problem. https://bugzilla.redhat.com/show_bug.cgi?id=1201979 C.f. 956eaf2b8d6c9999024705ddadc7393bc707de02.
-rw-r--r--TODO5
-rw-r--r--src/shared/generator.c65
2 files changed, 60 insertions, 10 deletions
diff --git a/TODO b/TODO
index 23c27f51d2..a94043a81c 100644
--- a/TODO
+++ b/TODO
@@ -111,9 +111,6 @@ Features:
* Maybe add support for the equivalent of "ethtool advertise" to .link files?
http://lists.freedesktop.org/archives/systemd-devel/2015-April/030112.html
-* fstab-generator should generate systemd-fsck-root.service when
- running in the initrd, and operate on the right device.
-
* .timer units should optionally support CLOCK_BOOTTIME in addition to CLOCK_MONOTONIC
* create a btrfs qgroup for /var/lib/machines, and add all container
@@ -151,8 +148,6 @@ Features:
* Introduce $LISTEN_NAMES to complement $LISTEN_FDS, containing a
colon separated list of identifiers for the fds passed.
-* when the fstab-generator runs in the initrd, it should create a /dev/null mask for systemd-fsck-root.service, to avoid that the the root fs is fsck'ed twice.
-
* maybe introduce WantsMountsFor=? Usecase:
http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
diff --git a/src/shared/generator.c b/src/shared/generator.c
index 2dc34bf738..d48b400b31 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -28,8 +28,52 @@
#include "generator.h"
#include "path-util.h"
#include "fstab-util.h"
+#include "fileio.h"
#include "dropin.h"
+static int write_fsck_sysroot_service(const char *dir, const char *what) {
+ const char *unit;
+ _cleanup_free_ char *device = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
+ int r;
+
+ unit = strjoina(dir, "/systemd-fsck-root.service");
+ log_debug("Creating %s", unit);
+
+ r = unit_name_from_path(what, ".device", &device);
+ if (r < 0)
+ return log_error_errno(r, "Failed to convert device \"%s\" to unit name: %m", what);
+
+ f = fopen(unit, "wxe");
+ if (!f)
+ return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
+
+ fprintf(f,
+ "# Automatically generated by %1$s\n\n"
+ "[Unit]\n"
+ "Documentation=man:systemd-fsck-root.service(8)\n"
+ "Description=File System Check on %2$s\n"
+ "DefaultDependencies=no\n"
+ "BindsTo=%3$s\n"
+ "After=%3$s\n"
+ "Before=shutdown.target\n"
+ "\n"
+ "[Service]\n"
+ "Type=oneshot\n"
+ "RemainAfterExit=yes\n"
+ "ExecStart=/usr/lib/systemd/systemd-fsck %2$s\n"
+ "TimeoutSec=0\n",
+ program_invocation_short_name,
+ what,
+ device);
+
+ fflush(f);
+ if (ferror(f))
+ return log_error_errno(errno, "Failed to write unit file %s: %m", unit);
+
+ return 0;
+}
+
int generator_write_fsck_deps(
FILE *f,
const char *dir,
@@ -69,11 +113,22 @@ int generator_write_fsck_deps(
return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
} else {
- _cleanup_free_ char *fsck = NULL;
-
- r = unit_name_from_path_instance("systemd-fsck", what, ".service", &fsck);
- if (r < 0)
- return log_error_errno(r, "Failed to create fsck service name: %m");
+ _cleanup_free_ char *_fsck = NULL;
+ const char *fsck;
+
+ if (in_initrd() && path_equal(where, "/sysroot")) {
+ r = write_fsck_sysroot_service(dir, what);
+ if (r < 0)
+ return r;
+
+ fsck = "systemd-fsck-root.service";
+ } else {
+ r = unit_name_from_path_instance("systemd-fsck", what, ".service", &_fsck);
+ if (r < 0)
+ return log_error_errno(r, "Failed to create fsck service name: %m");
+
+ fsck = _fsck;
+ }
fprintf(f,
"RequiresOverridable=%1$s\n"