chiark / gitweb /
switch-root: create essential base directories at system bootup
authorKay Sievers <kay@vrfy.org>
Tue, 24 Jun 2014 16:10:30 +0000 (18:10 +0200)
committerKay Sievers <kay@vrfy.org>
Tue, 24 Jun 2014 16:12:31 +0000 (18:12 +0200)
This allows us to bootup a rootfs with a /usr directory only.

src/core/switch-root.c
src/nspawn/nspawn.c

index 518ec1f0a70a3e7a7da8f545a36610172e7499e0..f82243f8b1a6ab9616ac0d194f58bbc71174f972 100644 (file)
@@ -30,6 +30,8 @@
 #include "util.h"
 #include "path-util.h"
 #include "switch-root.h"
 #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) {
 #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;
         struct stat new_root_stat;
         bool old_root_remove;
         const char *i, *temporary_old_root;
+        int r;
 
         if (path_equal(new_root, "/"))
                 return 0;
 
         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");
          * 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();
 
 
         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);
 
                 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) {
 
                 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;
         if (chdir(new_root) < 0) {
                 log_error("Failed to change directory to %s: %m", new_root);
                 return -errno;
index 501bccae873e33f95da179220a6135bf67b8bf49..0a8dc0cf301cd7bf047487e75fed5cc33db06c44 100644 (file)
@@ -3011,7 +3011,7 @@ int main(int argc, char *argv[]) {
 
                         r = base_filesystem_create(arg_directory);
                         if (r < 0) {
 
                         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;
                         }
 
                                 goto child_fail;
                         }