switchroot: Allow letting ostree-prepare-root mount /var

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
This commit is contained in:
Jonathan Lebon 2018-06-07 14:42:42 -04:00 committed by Atomic Bot
parent 6f3b5620de
commit ecdebeb20e
3 changed files with 21 additions and 4 deletions

View File

@ -31,6 +31,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#define INITRAMFS_MOUNT_VAR "/run/ostree/initramfs-mount-var"
static inline int static inline int
path_is_on_readonly_fs (char *path) path_is_on_readonly_fs (char *path)
{ {

View File

@ -151,13 +151,18 @@ main(int argc, char *argv[])
if (chdir (deploy_path) < 0) if (chdir (deploy_path) < 0)
err (EXIT_FAILURE, "failed to chdir to deploy_path"); 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 #ifndef HAVE_SYSTEMD_AND_LIBMOUNT
/* Link to the deployment's /var */ /* file in /run can override that behaviour */
if (mount ("../../var", "var", NULL, MS_MGC_VAL|MS_BIND, NULL) < 0) if (lstat (INITRAMFS_MOUNT_VAR, &stbuf) < 0)
err (EXIT_FAILURE, "failed to bind mount ../../var to var"); mount_var = false;
#endif #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]; char srcpath[PATH_MAX];
/* If /boot is on the same partition, use a bind mount to make it visible /* If /boot is on the same partition, use a bind mount to make it visible
* at /boot inside the deployment. */ * at /boot inside the deployment. */

View File

@ -49,6 +49,16 @@ main(int argc, char *argv[])
exit (EXIT_SUCCESS); 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) if (argc > 1 && argc != 4)
errx (EXIT_FAILURE, "This program takes three or no arguments"); errx (EXIT_FAILURE, "This program takes three or no arguments");