diff --git a/src/libotcore/otcore-prepare-root.c b/src/libotcore/otcore-prepare-root.c index f76db04a33..ae8b710609 100644 --- a/src/libotcore/otcore-prepare-root.c +++ b/src/libotcore/otcore-prepare-root.c @@ -25,6 +25,24 @@ // which can be used to fully verify the target filesystem tree. #define BINDING_KEYPATH "/etc/ostree/initramfs-root-binding.key" +bool +proc_cmdline_has_key (const char *cmdline, const char *key) +{ + for (const char *iter = cmdline; iter;) + { + if (g_str_equal (iter, key)) + return true; + + iter = strchr (iter, ' '); + if (iter == NULL) + return false; + + iter += strspn (iter, " "); + } + + return false; +} + static bool proc_cmdline_has_key_starting_with (const char *cmdline, const char *key) { diff --git a/src/libotcore/otcore.h b/src/libotcore/otcore.h index fc6b81ca1a..cd4d405240 100644 --- a/src/libotcore/otcore.h +++ b/src/libotcore/otcore.h @@ -43,6 +43,7 @@ bool otcore_ed25519_init (void); gboolean otcore_validate_ed25519_signature (GBytes *data, GBytes *pubkey, GBytes *signature, bool *out_valid, GError **error); +bool proc_cmdline_has_key (const char *cmdline, const char *key); char *otcore_find_proc_cmdline_key (const char *cmdline, const char *key); gboolean otcore_get_ostree_target (const char *cmdline, gboolean *is_aboot, char **out_target, GError **error); diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 4ac4420272..65e46f46f9 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -97,6 +97,20 @@ #include "ostree-mount-util.h" +static bool enable_debug = false; + +__attribute__ ((__format__ (printf, 1, 2))) static void +dbg (const char *format, ...) +{ + if (enable_debug) + { + va_list args; + va_start (args, format); + vprintf (format, args); + va_end (args); + } +} + static bool sysroot_is_configured_ro (const char *sysroot) { @@ -124,6 +138,7 @@ resolve_deploy_path (const char *root_mountpoint) g_autoptr (GError) error = NULL; g_autofree char *ostree_target = NULL; + enable_debug = proc_cmdline_has_key (kernel_cmdline, "ostree-prepare-root.debug"); if (!otcore_get_ostree_target (kernel_cmdline, NULL, &ostree_target, &error)) errx (EXIT_FAILURE, "Failed to determine ostree target: %s", error->message); if (!ostree_target) @@ -564,6 +579,8 @@ main (int argc, char *argv[]) g_autofree char *ovl_options = g_strdup_printf ("lowerdir=%s,upperdir=%s,workdir=%s", lowerdir, upperdir, workdir); + dbg ("mount (\"overlay\", \"" TMP_SYSROOT "/etc\", \"overlay\", MS_SILENT, \"%s\")\n", + ovl_options); if (mount ("overlay", TMP_SYSROOT "/etc", "overlay", MS_SILENT, ovl_options) < 0) err (EXIT_FAILURE, "failed to mount transient etc overlayfs"); } @@ -598,6 +615,9 @@ main (int argc, char *argv[]) // Propagate readonly state if (!sysroot_currently_writable) mflags |= MS_RDONLY; + + dbg ("mount (\"overlay\", \"" TMP_SYSROOT "/usr\", \"overlay\", %lu, \"%s\")\n", mflags, + usr_ovl_options); if (mount ("overlay", TMP_SYSROOT "/usr", "overlay", mflags, usr_ovl_options) < 0) err (EXIT_FAILURE, "failed to mount /usr overlayfs"); }