Skip to content

Commit

Permalink
prepare-root: bind mount var under deployment for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Jan 3, 2025
1 parent d472e60 commit cd0d48e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,23 @@ main (int argc, char *argv[])

const char *var_dir = OTCORE_RUN_OSTREE_PRIVATE "/var";

/* Bind-mount /var, and remount as writable. */
if (mkdirat (AT_FDCWD, var_dir, 0) < 0)
err (EXIT_FAILURE, "failed to mkdir %s", var_dir);
if (mount ("../../var", var_dir, NULL, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to prepare /var bind-mount at %s", var_dir);
if (mount (var_dir, var_dir, NULL, MS_BIND | MS_REMOUNT | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to make writable /var bind-mount at %s", var_dir);
/* Prepare /var.
* When a read-only sysroot is configured, this adds a dedicated bind-mount (to itself)
* so that the stateroot location stays writable. */
if (sysroot_readonly)
{
/* Bind-mount /var (at stateroot path), and remount as writable. */
if (mount ("../../var", "../../var", NULL, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to prepare /var bind-mount at %s", srcpath);
if (mount ("../../var", "../../var", NULL, MS_BIND | MS_REMOUNT | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to make writable /var bind-mount at %s", srcpath);
}

/* Bind-mount var to var_dir */
if (mount ("../../var", var_dir, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to bind mount %s", var_dir);
if (mount (NULL, var_dir, MS_SLAVE | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to change %s to slave mount", var_dir);

/* When running under systemd, /var will be handled by a 'var.mount' unit outside
* of initramfs.
Expand Down

0 comments on commit cd0d48e

Please sign in to comment.