diff --git a/src/switchroot/ostree-mount-util.h b/src/switchroot/ostree-mount-util.h index 08e10f97..0b40bb40 100644 --- a/src/switchroot/ostree-mount-util.h +++ b/src/switchroot/ostree-mount-util.h @@ -31,6 +31,8 @@ #include #include +#define INITRAMFS_MOUNT_VAR "/run/ostree/initramfs-mount-var" + static inline int path_is_on_readonly_fs (char *path) { diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 5ed9b60f..53df463c 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -151,13 +151,18 @@ main(int argc, char *argv[]) if (chdir (deploy_path) < 0) err (EXIT_FAILURE, "failed to chdir to deploy_path"); - /* In the systemd case, this is handled by ostree-system-generator */ + bool mount_var = true; + /* In the systemd case, this is handled by ostree-system-generator by default */ #ifndef HAVE_SYSTEMD_AND_LIBMOUNT - /* Link to the deployment's /var */ - if (mount ("../../var", "var", NULL, MS_MGC_VAL|MS_BIND, NULL) < 0) - err (EXIT_FAILURE, "failed to bind mount ../../var to var"); + /* file in /run can override that behaviour */ + if (lstat (INITRAMFS_MOUNT_VAR, &stbuf) < 0) + mount_var = false; #endif + /* Link to the deployment's /var */ + if (mount_var && mount ("../../var", "var", NULL, MS_MGC_VAL|MS_BIND, NULL) < 0) + err (EXIT_FAILURE, "failed to bind mount ../../var to var"); + char srcpath[PATH_MAX]; /* If /boot is on the same partition, use a bind mount to make it visible * at /boot inside the deployment. */ diff --git a/src/switchroot/ostree-system-generator.c b/src/switchroot/ostree-system-generator.c index 970ef41e..799a3104 100644 --- a/src/switchroot/ostree-system-generator.c +++ b/src/switchroot/ostree-system-generator.c @@ -49,6 +49,16 @@ main(int argc, char *argv[]) exit (EXIT_SUCCESS); } + /* We conflict with the magic ostree-mount-deployment-var file for ostree-prepare-root */ + { struct stat stbuf; + if (fstatat (AT_FDCWD, INITRAMFS_MOUNT_VAR, &stbuf, 0) == 0) + { + if (unlinkat (AT_FDCWD, INITRAMFS_MOUNT_VAR, 0) < 0) + err (EXIT_FAILURE, "Can't unlink " INITRAMFS_MOUNT_VAR); + exit (EXIT_SUCCESS); + } + } + if (argc > 1 && argc != 4) errx (EXIT_FAILURE, "This program takes three or no arguments");