-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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