[systemd-commits] src/core src/nspawn

Kay Sievers kay at kemper.freedesktop.org
Tue Jun 24 09:14:35 PDT 2014


 src/core/switch-root.c |   12 ++++++++++++
 src/nspawn/nspawn.c    |    2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

New commits:
commit 971ff8c78b3a7d94ed2289077f856c6988d18183
Author: Kay Sievers <kay at vrfy.org>
Date:   Tue Jun 24 18:10:30 2014 +0200

    switch-root: create essential base directories at system bootup
    
    This allows us to bootup a rootfs with a /usr directory only.

diff --git a/src/core/switch-root.c b/src/core/switch-root.c
index 518ec1f..f82243f 100644
--- a/src/core/switch-root.c
+++ b/src/core/switch-root.c
@@ -30,6 +30,8 @@
 #include "util.h"
 #include "path-util.h"
 #include "switch-root.h"
+#include "mkdir.h"
+#include "base-filesystem.h"
 #include "missing.h"
 
 int switch_root(const char *new_root) {
@@ -45,6 +47,7 @@ int switch_root(const char *new_root) {
         struct stat new_root_stat;
         bool old_root_remove;
         const char *i, *temporary_old_root;
+        int r;
 
         if (path_equal(new_root, "/"))
                 return 0;
@@ -56,6 +59,7 @@ int switch_root(const char *new_root) {
          * than not that /mnt exists and is suitable as mount point
          * and is on the same fs as the old root dir */
         temporary_old_root = strappenda(new_root, "/mnt");
+        mkdir_p(temporary_old_root, 0755);
 
         old_root_remove = in_initrd();
 
@@ -80,6 +84,8 @@ int switch_root(const char *new_root) {
                 snprintf(new_mount, sizeof(new_mount), "%s%s", new_root, i);
                 char_array_0(new_mount);
 
+                mkdir_parents(new_mount, 0755);
+
                 if ((stat(new_mount, &sb) < 0) ||
                     sb.st_dev != new_root_stat.st_dev) {
 
@@ -99,6 +105,12 @@ int switch_root(const char *new_root) {
                 }
         }
 
+        r = base_filesystem_create(new_root);
+        if (r < 0) {
+                log_error("Failed to create the base filesystem: %s", strerror(-r));
+                return r;
+        }
+
         if (chdir(new_root) < 0) {
                 log_error("Failed to change directory to %s: %m", new_root);
                 return -errno;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 501bcca..0a8dc0c 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3011,7 +3011,7 @@ int main(int argc, char *argv[]) {
 
                         r = base_filesystem_create(arg_directory);
                         if (r < 0) {
-                                log_error("creating base filesystem failed: %s", strerror(-r));
+                                log_error("Failed to create the base filesystem: %s", strerror(-r));
                                 goto child_fail;
                         }
 



More information about the systemd-commits mailing list