mirror of
https://git.yoctoproject.org/poky
synced 2026-06-11 16:30:23 +00:00
wic: add --extra-partition-space option to set unused space
By default, the content of the partition is filled by the filesystem
without leaving any unused free space. The --extra-space flag adds
extra space to the filesystem size, not to the partition.
Unused free space after the filesystem can be useful for some cases,
such as encrypting a partition at runtime.
With --extra-partition-space 32M, we ensure that the last 32M of the
partition is unused: this space does not contain filesystem data and
can store the LUKS2 header.
The implementation sets a difference between the partition and
filesystem size:
- With --fixed-size, the extra part space is removed from the
filesystem size.
- Otherwise (with or without --size flag), the extra part space is
added to the partition size.
(From OE-Core rev: 22fd1702aedf40257aa53963b62b5ef1bbd2818a)
Signed-off-by: Pierre-Loup GOSSE <pierre-loup.gosse@smile.fr>
CC: Alexander Kanavin <alex.kanavin@gmail.com>
CC: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
857bb50a35
commit
21d98bd960
@@ -1166,7 +1166,7 @@ run_wic_cmd() {
|
||||
|
||||
return wkspath
|
||||
|
||||
def _get_wic_partitions(self, wkspath, native_sysroot=None, ignore_status=False):
|
||||
def _get_wic(self, wkspath, ignore_status=False):
|
||||
p = runCmd("wic create %s -e core-image-minimal -o %s" % (wkspath, self.resultdir),
|
||||
ignore_status=ignore_status)
|
||||
|
||||
@@ -1180,7 +1180,13 @@ run_wic_cmd() {
|
||||
if not wicout:
|
||||
return (p, None)
|
||||
|
||||
wicimg = wicout[0]
|
||||
return (p, wicout[0])
|
||||
|
||||
def _get_wic_partitions(self, wkspath, native_sysroot=None, ignore_status=False):
|
||||
p, wicimg = self._get_wic(wkspath, ignore_status)
|
||||
|
||||
if wicimg is None:
|
||||
return (p, None)
|
||||
|
||||
if not native_sysroot:
|
||||
native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
|
||||
@@ -1320,6 +1326,45 @@ run_wic_cmd() {
|
||||
size = int(size[:-3])
|
||||
self.assertGreaterEqual(size, 204800)
|
||||
|
||||
def test_extra_partition_space(self):
|
||||
native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
|
||||
|
||||
with NamedTemporaryFile("w", suffix=".wks") as tempf:
|
||||
tempf.write("bootloader --ptable gpt\n" \
|
||||
"part --ondisk hda --size 10M --extra-partition-space 10M --fstype=ext4\n" \
|
||||
"part --ondisk hda --fixed-size 20M --extra-partition-space 10M --fstype=ext4\n" \
|
||||
"part --source rootfs --ondisk hda --extra-partition-space 10M --fstype=ext4\n" \
|
||||
"part --source rootfs --ondisk hda --fixed-size 200M --extra-partition-space 10M --fstype=ext4\n")
|
||||
tempf.flush()
|
||||
|
||||
_, wicimg = self._get_wic(tempf.name)
|
||||
|
||||
res = runCmd("parted -m %s unit b p" % wicimg,
|
||||
native_sysroot=native_sysroot, stderr=subprocess.PIPE)
|
||||
|
||||
# parse parted output which looks like this:
|
||||
# BYT;\n
|
||||
# /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n
|
||||
# 1:0.00MiB:200MiB:200MiB:ext4::;\n
|
||||
partlns = res.output.splitlines()[2:]
|
||||
|
||||
self.assertEqual(4, len(partlns))
|
||||
|
||||
# Test for each partitions that the extra part space exists
|
||||
for part in range(0, len(partlns)):
|
||||
part_file = os.path.join(self.resultdir, "selftest_img.part%d" % (part + 1))
|
||||
partln = partlns[part].split(":")
|
||||
self.assertEqual(7, len(partln))
|
||||
self.assertRegex(partln[3], r'^[0-9]+B$')
|
||||
part_size = int(partln[3].rstrip("B"))
|
||||
start = int(partln[1].rstrip("B")) / 512
|
||||
length = part_size / 512
|
||||
runCmd("dd if=%s of=%s skip=%d count=%d" %
|
||||
(wicimg, part_file, start, length))
|
||||
res = runCmd("dumpe2fs %s -h | grep \"^Block count\"" % part_file)
|
||||
fs_size = int(res.output.split(":")[1].strip()) * 1024
|
||||
self.assertLessEqual(fs_size + 10485760, part_size, "part file: %s" % part_file)
|
||||
|
||||
# TODO this test could also work on aarch64
|
||||
@skipIfNotArch(['i586', 'i686', 'x86_64'])
|
||||
@OETestTag("runqemu")
|
||||
|
||||
Reference in New Issue
Block a user