switchroot: Allow letting ostree-prepare-root mount /var
authorJonathan Lebon <jonathan@jlebon.com>
Thu, 7 Jun 2018 18:42:42 +0000 (14:42 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 7 Jun 2018 21:41:32 +0000 (21:41 +0000)
In some scenarios, it might make sense to let `ostree-prepare-root` do
the `/var` mount from the state root as before. For example, one may
want to do some system configuration before the switch root. This of
course comes at the expense of supporting `/var` as a mount point in
`/etc/fstab`.

Closes: #1617
Approved by: cgwalters

src/switchroot/ostree-mount-util.h
src/switchroot/ostree-prepare-root.c
src/switchroot/ostree-system-generator.c

index 08e10f976b76c94afd4b1f774f221f71632f3377..0b40bb4064d1c351d1ef0e9696624990a44ec69d 100644 (file)
@@ -31,6 +31,8 @@
 #include <fcntl.h>
 #include <string.h>
 
+#define INITRAMFS_MOUNT_VAR "/run/ostree/initramfs-mount-var"
+
 static inline int
 path_is_on_readonly_fs (char *path)
 {
index 5ed9b60f6759f4548721081e82b0fcfdb1510dd5..53df463c339b2a0f376f8d7d19e77087942d5d82 100644 (file)
@@ -151,12 +151,17 @@ 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
+  /* 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", "var", NULL, MS_MGC_VAL|MS_BIND, NULL) < 0)
+  if (mount_var && mount ("../../var", "var", NULL, MS_MGC_VAL|MS_BIND, NULL) < 0)
     err (EXIT_FAILURE, "failed to bind mount ../../var to var");
-#endif
 
   char srcpath[PATH_MAX];
   /* If /boot is on the same partition, use a bind mount to make it visible
index 970ef41e4d3b55989cb3ab6363801da2a630ce7d..799a3104b91f2464d067831af74da2d4299dd226 100644 (file)
@@ -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");