<para>Use <literal>bind:…</literal> to bind mount another directory as operating system root
filesystems (added in v258). Expects an absolute path name referencing an existing directory within the initrd's file
- hierarchy to boot into.</para>
+ hierarchy to boot into. Since the resulting root file system is supposed to behave like a regular OS
+ root, the bind mount is established with the <option>dev</option>, <option>suid</option> and
+ <option>exec</option> options (i.e. the <option>nodev</option>, <option>nosuid</option> and
+ <option>noexec</option> flags that would otherwise be inherited from the file system the source
+ directory resides on, such as <filename>/run/</filename>, are cleared), unless overridden via
+ <varname>rootflags=</varname>.</para>
<para>Set to <literal>off</literal> to turn off mounting of a root file system.</para>
if (!strextend_with_separator(&combined_options, ",", extra_opts))
return log_oom();
+ /* A bind mount inherits the mount flags (nosuid, nodev, noexec, …) of the file system the source
+ * directory is located on. The source typically lives below /run/ (e.g. a freshly unpacked tar image
+ * in /run/machines/), which is mounted nosuid,nodev, and these flags would then propagate to our root
+ * file system, breaking suid binaries (e.g. sudo) and device nodes. Since this is supposed to become a
+ * regular OS root file system, default to dev,suid,exec instead, unless the user explicitly requested
+ * otherwise. */
+ if (bind) {
+ static const char* const defaults[] = {
+ "suid", "suid\0" "nosuid\0",
+ "dev", "dev\0" "nodev\0",
+ "exec", "exec\0" "noexec\0",
+ NULL,
+ };
+
+ STRV_FOREACH_PAIR(add, test, defaults)
+ if (!fstab_test_option(combined_options, *test))
+ if (!strextend_with_separator(&combined_options, ",", *add))
+ return log_oom();
+ }
+
log_debug("Found entry what=%s where=/sysroot type=%s opts=%s", what, strna(fstype), strempty(combined_options));
/* Only honor x-systemd.makefs and .validatefs here, others are not relevant in initrd/not used
--- /dev/null
+# Automatically generated by systemd-fstab-generator
+
+[Unit]
+Documentation=man:fstab(5) man:systemd-fstab-generator(8)
+SourcePath=/proc/cmdline
+Before=initrd-root-fs.target
+After=imports.target
+
+[Mount]
+What=/run/machines/root
+Where=/sysroot
+Options=rw,bind,suid,dev,exec