Patchwork [v2] wic: squashfs partition support

login
register
mail settings
Submitter Maciej Borzecki
Date July 24, 2014, 12:11 p.m.
Message ID <1406203910-16569-1-git-send-email-maciej.borzecki@open-rnd.pl>
Download mbox | patch
Permalink /patch/76583/
State Accepted
Commit 73ce04eb6d538d1a924c6a0867b39cbe44e2f215
Headers show

Comments

Maciej Borzecki - July 24, 2014, 12:11 p.m.
It is possible to instruct wic to create a squashfs partition by setting
--fstype=squashfs in *.wks. For now this is only useable for rootfs
partitions (note that you must have squashfs support in the kernel). An
attempt to create an empty partition will produce a warning.

Signed-off-by: Maciej Borzecki <maciej.borzecki@open-rnd.pl>
---
 .../lib/mic/kickstart/custom_commands/partition.py | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
Tom Zanussi - July 25, 2014, midnight
On Thu, 2014-07-24 at 14:11 +0200, Maciej Borzecki wrote:
> It is possible to instruct wic to create a squashfs partition by setting
> --fstype=squashfs in *.wks. For now this is only useable for rootfs
> partitions (note that you must have squashfs support in the kernel). An
> attempt to create an empty partition will produce a warning.
> 
> Signed-off-by: Maciej Borzecki <maciej.borzecki@open-rnd.pl>

Acked-by: Tom Zanussi <tom.zanussi@intel.com>

> ---
>  .../lib/mic/kickstart/custom_commands/partition.py | 61 ++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py
> index d0f1b78..ce90aa1 100644
> --- a/scripts/lib/mic/kickstart/custom_commands/partition.py
> +++ b/scripts/lib/mic/kickstart/custom_commands/partition.py
> @@ -25,6 +25,8 @@
>  #
>  
>  import shutil
> +import os
> +import tempfile
>  
>  from pykickstart.commands.partition import *
>  from mic.utils.oe.misc import *
> @@ -192,6 +194,10 @@ class Wic_PartData(Mic_PartData):
>              return self.prepare_rootfs_vfat(cr_workdir, oe_builddir,
>                                              rootfs_dir, native_sysroot,
>                                              pseudo)
> +        elif self.fstype.startswith("squashfs"):
> +            return self.prepare_rootfs_squashfs(cr_workdir, oe_builddir,
> +                                                rootfs_dir, native_sysroot,
> +                                                pseudo)
>  
>      def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir,
>                             native_sysroot, pseudo):
> @@ -324,6 +330,28 @@ class Wic_PartData(Mic_PartData):
>          self.set_size(rootfs_size)
>          self.set_source_file(rootfs)
>  
> +    def prepare_rootfs_squashfs(self, cr_workdir, oe_builddir, rootfs_dir,
> +                                native_sysroot, pseudo):
> +        """
> +        Prepare content for a squashfs rootfs partition.
> +        """
> +        image_rootfs = rootfs_dir
> +        rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label ,self.fstype)
> +
> +        squashfs_cmd = "mksquashfs %s %s -noappend" % \
> +                       (image_rootfs, rootfs)
> +        rc, out = exec_native_cmd(pseudo + squashfs_cmd, native_sysroot)
> +
> +        # get the rootfs size in the right units for kickstart (Mb)
> +        du_cmd = "du -Lbms %s" % rootfs
> +        rc, out = exec_cmd(du_cmd)
> +        rootfs_size = out.split()[0]
> +
> +        self.size = rootfs_size
> +        self.source_file = rootfs
> +
> +        return 0
> +
>      def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot):
>          """
>          Prepare an empty partition.
> @@ -337,6 +365,9 @@ class Wic_PartData(Mic_PartData):
>          elif self.fstype.startswith("vfat"):
>              return self.prepare_empty_partition_vfat(cr_workdir, oe_builddir,
>                                                       native_sysroot)
> +        elif self.fstype.startswith("squashfs"):
> +            return self.prepare_empty_partition_squashfs(cr_workdir, oe_builddir,
> +                                                         native_sysroot)
>  
>      def prepare_empty_partition_ext(self, cr_workdir, oe_builddir,
>                                      native_sysroot):
> @@ -398,6 +429,36 @@ class Wic_PartData(Mic_PartData):
>  
>          return 0
>  
> +    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
> +                                         native_sysroot):
> +        """
> +        Prepare an empty squashfs partition.
> +        """
> +        msger.warning("Creating of an empty squashfs %s partition was attempted. " \
> +                      "Proceeding as requested." % self.mountpoint)
> +
> +        fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
> +
> +        # it is not possible to create a squashfs without source data,
> +        # thus prepare an empty temp dir that is used as source
> +        tmpdir = tempfile.mkdtemp()
> +
> +        squashfs_cmd = "mksquashfs %s %s -noappend" % \
> +                       (tmpdir, fs)
> +        rc, out = exec_native_cmd(squashfs_cmd, native_sysroot)
> +
> +        os.rmdir(tmpdir)
> +
> +        # get the rootfs size in the right units for kickstart (Mb)
> +        du_cmd = "du -Lbms %s" % fs
> +        rc, out = exec_cmd(du_cmd)
> +        fs_size = out.split()[0]
> +
> +        self.size = fs_size
> +        self.source_file = fs
> +
> +        return 0
> +
>      def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
>          """
>          Prepare a swap partition.

Patch

diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py
index d0f1b78..ce90aa1 100644
--- a/scripts/lib/mic/kickstart/custom_commands/partition.py
+++ b/scripts/lib/mic/kickstart/custom_commands/partition.py
@@ -25,6 +25,8 @@ 
 #
 
 import shutil
+import os
+import tempfile
 
 from pykickstart.commands.partition import *
 from mic.utils.oe.misc import *
@@ -192,6 +194,10 @@  class Wic_PartData(Mic_PartData):
             return self.prepare_rootfs_vfat(cr_workdir, oe_builddir,
                                             rootfs_dir, native_sysroot,
                                             pseudo)
+        elif self.fstype.startswith("squashfs"):
+            return self.prepare_rootfs_squashfs(cr_workdir, oe_builddir,
+                                                rootfs_dir, native_sysroot,
+                                                pseudo)
 
     def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
@@ -324,6 +330,28 @@  class Wic_PartData(Mic_PartData):
         self.set_size(rootfs_size)
         self.set_source_file(rootfs)
 
+    def prepare_rootfs_squashfs(self, cr_workdir, oe_builddir, rootfs_dir,
+                                native_sysroot, pseudo):
+        """
+        Prepare content for a squashfs rootfs partition.
+        """
+        image_rootfs = rootfs_dir
+        rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label ,self.fstype)
+
+        squashfs_cmd = "mksquashfs %s %s -noappend" % \
+                       (image_rootfs, rootfs)
+        rc, out = exec_native_cmd(pseudo + squashfs_cmd, native_sysroot)
+
+        # get the rootfs size in the right units for kickstart (Mb)
+        du_cmd = "du -Lbms %s" % rootfs
+        rc, out = exec_cmd(du_cmd)
+        rootfs_size = out.split()[0]
+
+        self.size = rootfs_size
+        self.source_file = rootfs
+
+        return 0
+
     def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot):
         """
         Prepare an empty partition.
@@ -337,6 +365,9 @@  class Wic_PartData(Mic_PartData):
         elif self.fstype.startswith("vfat"):
             return self.prepare_empty_partition_vfat(cr_workdir, oe_builddir,
                                                      native_sysroot)
+        elif self.fstype.startswith("squashfs"):
+            return self.prepare_empty_partition_squashfs(cr_workdir, oe_builddir,
+                                                         native_sysroot)
 
     def prepare_empty_partition_ext(self, cr_workdir, oe_builddir,
                                     native_sysroot):
@@ -398,6 +429,36 @@  class Wic_PartData(Mic_PartData):
 
         return 0
 
+    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
+                                         native_sysroot):
+        """
+        Prepare an empty squashfs partition.
+        """
+        msger.warning("Creating of an empty squashfs %s partition was attempted. " \
+                      "Proceeding as requested." % self.mountpoint)
+
+        fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
+
+        # it is not possible to create a squashfs without source data,
+        # thus prepare an empty temp dir that is used as source
+        tmpdir = tempfile.mkdtemp()
+
+        squashfs_cmd = "mksquashfs %s %s -noappend" % \
+                       (tmpdir, fs)
+        rc, out = exec_native_cmd(squashfs_cmd, native_sysroot)
+
+        os.rmdir(tmpdir)
+
+        # get the rootfs size in the right units for kickstart (Mb)
+        du_cmd = "du -Lbms %s" % fs
+        rc, out = exec_cmd(du_cmd)
+        fs_size = out.split()[0]
+
+        self.size = fs_size
+        self.source_file = fs
+
+        return 0
+
     def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
         """
         Prepare a swap partition.