Merge pull request #3129 from cgwalters/fix-unlock-composefs-compat
authorColin Walters <walters@verbum.org>
Thu, 4 Jan 2024 15:40:09 +0000 (10:40 -0500)
committerGitHub <noreply@github.com>
Thu, 4 Jan 2024 15:40:09 +0000 (10:40 -0500)
prepare-root: Fix composefs + ostree admin unlock --hotfix compat

1  2 
src/switchroot/ostree-prepare-root.c

index 5f4d213286b31f6c31efacd87c4ae8e30614e545,d7c44e97ec765aa80d1908556ce98129b7be55e2..bde698b00e5db568a7f0c67afc5718256115662c
@@@ -641,21 -637,13 +641,14 @@@ main (int argc, char *argv[]
      {
        /* Do we have a persistent overlayfs for /usr?  If so, mount it now. */
        const char usr_ovl_options[]
 -          = "lowerdir=" TMP_SYSROOT "/usr,upperdir=.usr-ovl-upper,workdir=.usr-ovl-work";
 +          = "lowerdir=" TMP_SYSROOT
 +            "/usr,upperdir=.usr-ovl-upper,workdir=" OTCORE_HOTFIX_USR_OVL_WORK;
  
-       /* Except overlayfs barfs if we try to mount it on a read-only
-        * filesystem.  For this use case I think admins are going to be
-        * okay if we remount the rootfs here, rather than waiting until
-        * later boot and `systemd-remount-fs.service`.
-        */
-       if (path_is_on_readonly_fs (TMP_SYSROOT))
-         {
-           if (mount (TMP_SYSROOT, TMP_SYSROOT, NULL, MS_REMOUNT | MS_SILENT, NULL) < 0)
-             err (EXIT_FAILURE, "failed to remount rootfs writable (for overlayfs)");
-         }
-       if (mount ("overlay", TMP_SYSROOT "/usr", "overlay", MS_SILENT, usr_ovl_options) < 0)
+       unsigned long mflags = MS_SILENT;
+       // Propagate readonly state
+       if (!sysroot_currently_writable)
+         mflags |= MS_RDONLY;
+       if (mount ("overlay", TMP_SYSROOT "/usr", "overlay", mflags, usr_ovl_options) < 0)
          err (EXIT_FAILURE, "failed to mount /usr overlayfs");
      }
    else if (!using_composefs)