[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 5/5] lib/vfscore: Add support to mount initramfs to root



Modify vfscore boot operation to run cpio extraction algorithm on initrd
memory region and mount the resulting filesystem at root.

Signed-off-by: Robert Hrusecky <roberth@xxxxxxxxxxxxx>
Signed-off-by: Omar Jamil <omarj2898@xxxxxxxxx>
Signed-off-by: Sachin Beldona <sachinbeldona@xxxxxxxxxx>
---
 lib/vfscore/Config.uk | 12 ++++++++++++
 lib/vfscore/rootfs.c  | 32 ++++++++++++++++++++++++++------
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/lib/vfscore/Config.uk b/lib/vfscore/Config.uk
index f64810f..e3b305e 100644
--- a/lib/vfscore/Config.uk
+++ b/lib/vfscore/Config.uk
@@ -9,6 +9,18 @@ config LIBVFSCORE
 if LIBVFSCORE
 menu "vfscore: Configuration"
 
+config LIBCPIO
+    bool "cpio: general cpio archive extraction"
+    default n
+
+config LIBINITRAMFS
+    bool "initramfs: extract the given cpio file to /"
+    default n
+    select LIBRAMFS
+    select LIBUKLIBPARAM
+    select LIBVFSCORE_AUTOMOUNT_ROOTFS
+    select LIBCPIO
+
 config LIBVFSCORE_PIPE_SIZE_ORDER
        int "Pipe size order"
        default 16
diff --git a/lib/vfscore/rootfs.c b/lib/vfscore/rootfs.c
index 4b9512a..78dbe3a 100644
--- a/lib/vfscore/rootfs.c
+++ b/lib/vfscore/rootfs.c
@@ -42,6 +42,11 @@
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <uk/init.h>
+#ifdef CONFIG_LIBINITRAMFS
+#include <uk/plat/memory.h>
+#include <uk/cpio.h>
+#include <string.h>
+#endif
 
 static const char *rootfs   = CONFIG_LIBVFSCORE_ROOTFS;
 
@@ -80,17 +85,32 @@ static int vfscore_rootfs(void)
                return -1;
        }
 
+#ifdef CONFIG_LIBINITRAMFS
+       struct ukplat_memregion_desc memregion_desc;
+       int initrd;
+       enum cpio_error error;
+
+       initrd = ukplat_memregion_find_initrd0(&memregion_desc);
+       if (initrd != -1) {
+               ukplat_memregion_get(initrd, &memregion_desc);
+               if (mount("", "/", "ramfs", 0, NULL) < 0)
+                       return -CPIO_MOUNT_FAILED;
+
+               error =
+                   cpio_extract("/", memregion_desc.base, memregion_desc.len);
+               if (error < 0)
+                       uk_pr_err("Failed to mount initrd\n");
+               return error;
+       }
+       uk_pr_err("Failed to mount initrd\n");
+       return -CPIO_NO_MEMREGION;
+#else
        uk_pr_info("Mount %s to /...\n", rootfs);
        if (mount(rootdev, "/", rootfs, rootflags, rootopts) != 0) {
                uk_pr_crit("Failed to mount /: %d\n", errno);
                return -1;
        }
-
-       /*
-        * TODO: Alternatively we could extract an archive found
-        * as initrd to a ramfs '/' if we have got fsname 'initrd'
-        */
-
+#endif
        return 0;
 }
 
-- 
2.24.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.