Skip to content

Instantly share code, notes, and snippets.

@dsd
Created January 27, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsd/0a7efb0f5a101346335b to your computer and use it in GitHub Desktop.
Save dsd/0a7efb0f5a101346335b to your computer and use it in GitHub Desktop.
Simplified version of ostree mount setup, which causes an invisible/unmountable /sysroot mount after switch_root
#include <sys/mount.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main(void)
{
/* For some reason the kernel refuses switching root if any file systems
* are mounted MS_SHARED. */
if (mount (NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0)
{
perror ("Failed to make \"/\" private mount");
exit (1);
}
/* Make /fs a bind mount, so we can move it later */
if (mount ("/sysroot/fs", "/sysroot/fs", NULL, MS_BIND, NULL) < 0)
{
perror ("failed to initial bind mount");
exit (1);
}
if (mount ("/sysroot/fs", "/sysroot", NULL, MS_MOVE, NULL) < 0)
{
perror ("failed to MS_MOVE");
exit (1);
}
exit (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment