[OE-core] Create partition with a subset of a file system with WIC

Patrick Gauvin gauvin.patrick at gmail.com
Thu Sep 19 14:40:10 UTC 2019


Hello,

I added a feature to wic. It can create a partition from a subdirectory of
an image and preserves permissions, the owner and the group of the files.
Here's an exemple on how I use it in a wks file to create a different
partition for the home directory.

part /home --source rootfs --rootfs-dir=core-image-base:/home --size 500
--ondisk mmcblk --fstype=ext4 --label APPS --align 4096

Here is the patch.

diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 3da7e23..580abcb 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -202,7 +202,7 @@ class Partition():
                            (self.mountpoint, self.size, self.fixed_size))

     def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
-                       native_sysroot, real_rootfs = True):
+                       native_sysroot, real_rootfs = True, folder = ""):
         """
         Prepare content for a rootfs partition i.e. create a partition
         and fill it from a /rootfs dir.
@@ -241,7 +241,7 @@ class Partition():

         prefix = "ext" if self.fstype.startswith("ext") else self.fstype
         method = getattr(self, "prepare_rootfs_" + prefix)
-        method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
+        method(rootfs, oe_builddir, rootfs_dir + folder, native_sysroot,
pseudo)
         self.source_file = rootfs

         # get the rootfs size in the right units for kickstart (kB)
diff --git a/scripts/lib/wic/plugins/source/rootfs.py
b/scripts/lib/wic/plugins/source/rootfs.py
index aec720f..8861156 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -81,6 +81,13 @@ class RootfsPlugin(SourcePlugin):
                 raise WicError("Couldn't find --rootfs-dir=%s connection
or "
                                "it is not a valid path, exiting" %
part.rootfs_dir)

+        # You can select the subfolder of an image by using ":" to
separate the image name and the sub folder name.
+        # i.e. --rootfs-dir=core-image-base:/home
+        folder = ""
+        folder_index = rootfs_dir.find(":")
+        if folder_index >= 0:
+            folder = rootfs_dir[folder_index + 1:]
+            rootfs_dir = rootfs_dir[:folder_index]
         part.rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)

         new_rootfs = None
@@ -123,4 +130,4 @@ class RootfsPlugin(SourcePlugin):
                     shutil.rmtree(full_path)

         part.prepare_rootfs(cr_workdir, oe_builddir,
-                            new_rootfs or part.rootfs_dir, native_sysroot)
+                            new_rootfs or part.rootfs_dir, native_sysroot,
True, folder)

I hope you will consider adding it to wic.

Thank you.
-- 
Patrick Gauvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/openembedded-core/attachments/20190919/d2a5fec0/attachment-0001.html>


More information about the Openembedded-core mailing list