Skip to content

Commit

Permalink
ostree-remount: Don't skip remount if root is composefs
Browse files Browse the repository at this point in the history
When using composefs the root fs will always be read-only, but in this
case we should still continue remounting /sysroot. So, we record a
/run/ostree-composefs-root.stamp file in ostree-prepare-root if composefs
is used, and then react to it in ostree-remount.
  • Loading branch information
alexlarsson committed May 26, 2023
1 parent 809c21c commit fa78974
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/switchroot/ostree-mount-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#define INITRAMFS_MOUNT_VAR "/run/ostree/initramfs-mount-var"
#define _OSTREE_SYSROOT_READONLY_STAMP "/run/ostree-sysroot-ro.stamp"
#define _OSTREE_COMPOSEFS_ROOT_STAMP "/run/ostree-composefs-root.stamp"

static inline int
path_is_on_readonly_fs (const char *path)
Expand Down
9 changes: 8 additions & 1 deletion src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,14 @@ main (int argc, char *argv[])
err (EXIT_FAILURE, "Failed to mount composefs");
}
else
using_composefs = 1;
{
int fd = open (_OSTREE_COMPOSEFS_ROOT_STAMP, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
if (fd < 0)
err (EXIT_FAILURE, "failed to create %s", _OSTREE_COMPOSEFS_ROOT_STAMP);
(void)close (fd);

using_composefs = 1;
}
#else
err (EXIT_FAILURE, "Composefs not supported");
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/switchroot/ostree-remount.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ main (int argc, char *argv[])
if (mount ("none", "/sysroot", NULL, MS_REC | MS_PRIVATE, NULL) < 0)
perror ("warning: While remounting /sysroot MS_PRIVATE");

if (path_is_on_readonly_fs ("/"))
bool root_is_composefs = false;
struct stat stbuf;
if (fstatat (AT_FDCWD, _OSTREE_COMPOSEFS_ROOT_STAMP, &stbuf, 0) == 0)
root_is_composefs = true;

if (path_is_on_readonly_fs ("/") && !root_is_composefs)
{
/* If / isn't writable, don't do any remounts; we don't want
* to clear the readonly flag in that case.
Expand Down

0 comments on commit fa78974

Please sign in to comment.