]> code.ossystems Code Review - openembedded-core.git/commitdiff
wic: Add extra-space argument
authorKristian Klausen <kristian@klausen.dk>
Fri, 3 Sep 2021 13:52:53 +0000 (15:52 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 4 Sep 2021 14:05:48 +0000 (15:05 +0100)
This allows extra space to be added after the last partition and is
especially useful when free space is needed for ex: adding partitions on
first boot with ex: systemd-repart[1] and the image is tested in QEMU.

[1] https://www.freedesktop.org/software/systemd/man/systemd-repart.html

Signed-off-by: Kristian Klausen <kristian@klausen.dk>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/selftest/cases/wic.py
scripts/lib/wic/plugins/imager/direct.py
scripts/wic

index 3b4143414feb75200c15aad6dc7ab7385b9674f0..dc7b9e637ea6c844e0c410ad169841bf33095682 100644 (file)
@@ -744,6 +744,17 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
                                       % (wks_file, self.resultdir), ignore_status=True).status)
         os.remove(wks_file)
 
+    def test_extra_space(self):
+        """Test --extra-space wks option."""
+        extraspace = 1024**3
+        runCmd("wic create wictestdisk "
+                                   "--image-name core-image-minimal "
+                                   "--extra-space %i -o %s" % (extraspace ,self.resultdir))
+        wicout = glob(self.resultdir + "wictestdisk-*.direct")
+        self.assertEqual(1, len(wicout))
+        size = os.path.getsize(wicout[0])
+        self.assertTrue(size > extraspace)
+
 class Wic2(WicTestCase):
 
     def test_bmap_short(self):
index 96168aadb4c297c7a51eac4c0bdfbee311c2db7c..9d10ec01d087fa2db586ced711fe402fa4846406 100644 (file)
@@ -77,7 +77,8 @@ class DirectPlugin(ImagerPlugin):
 
         image_path = self._full_path(self.workdir, self.parts[0].disk, "direct")
         self._image = PartitionedImage(image_path, self.ptable_format,
-                                       self.parts, self.native_sysroot)
+                                       self.parts, self.native_sysroot,
+                                       options.extra_space)
 
     def setup_workdir(self, workdir):
         if workdir:
@@ -293,7 +294,7 @@ class PartitionedImage():
     Partitioned image in a file.
     """
 
-    def __init__(self, path, ptable_format, partitions, native_sysroot=None):
+    def __init__(self, path, ptable_format, partitions, native_sysroot=None, extra_space=0):
         self.path = path  # Path to the image file
         self.numpart = 0  # Number of allocated partitions
         self.realpart = 0 # Number of partitions in the partition table
@@ -314,6 +315,7 @@ class PartitionedImage():
         self.sector_size = SECTOR_SIZE
         self.native_sysroot = native_sysroot
         num_real_partitions = len([p for p in self.partitions if not p.no_table])
+        self.extra_space = extra_space
 
         # calculate the real partition number, accounting for partitions not
         # in the partition table and logical partitions
@@ -483,6 +485,7 @@ class PartitionedImage():
             self.min_size += GPT_OVERHEAD
 
         self.min_size *= self.sector_size
+        self.min_size += self.extra_space
 
     def _create_partition(self, device, parttype, fstype, start, size):
         """ Create a partition on an image described by the 'device' object. """
index a741aed364bff816fb3e97a397c772f7f9832900..57197c204800222470b4d592343932c5f470f0e0 100755 (executable)
@@ -346,6 +346,8 @@ def wic_init_parser_create(subparser):
                       default=False, help="output debug information")
     subparser.add_argument("-i", "--imager", dest="imager",
                       default="direct", help="the wic imager plugin")
+    subparser.add_argument("--extra-space", type=int, dest="extra_space",
+                      default=0, help="additional free disk space to add to the image")
     return