Merge pull request #16301 from poettering/firstboot-image

Add --image= switch to firstboot, similar to --root= but with support for operating on disk image
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-07-07 19:44:12 +02:00
committed by GitHub
10 changed files with 189 additions and 27 deletions
+2 -3
View File
@@ -58,8 +58,8 @@ int umount_recursive(const char *prefix, int flags) {
if (!path_startswith(path, prefix))
continue;
if (umount2(path, flags) < 0) {
r = log_debug_errno(errno, "Failed to umount %s: %m", path);
if (umount2(path, flags | UMOUNT_NOFOLLOW) < 0) {
log_debug_errno(errno, "Failed to umount %s, ignoring: %m", path);
continue;
}
@@ -70,7 +70,6 @@ int umount_recursive(const char *prefix, int flags) {
break;
}
} while (again);
return n;
+11
View File
@@ -3,7 +3,9 @@
#include <mntent.h>
#include <stdio.h>
#include <unistd.h>
#include "errno-util.h"
#include "macro.h"
/* 4MB for contents of regular files, 64k inodes for directories, symbolic links and device specials,
@@ -53,3 +55,12 @@ int mount_option_mangle(
char **ret_remaining_options);
int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **dest);
/* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */
static inline void umount_and_rmdir_and_free(char *p) {
PROTECT_ERRNO;
(void) umount_recursive(p, 0);
(void) rmdir(p);
free(p);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_rmdir_and_free);
+2 -4
View File
@@ -21,6 +21,7 @@
#include "env-util.h"
#include "fs-util.h"
#include "log.h"
#include "namespace-util.h"
#include "path-util.h"
#include "random-util.h"
#include "strv.h"
@@ -137,10 +138,7 @@ bool have_namespaces(void) {
if (pid == 0) {
/* child */
if (unshare(CLONE_NEWNS) < 0)
_exit(EXIT_FAILURE);
if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL) < 0)
if (detach_mount_namespace() < 0)
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);