diff options
| author | Pierre-Loup GOSSE <pierre-loup.gosse@smile.fr> | 2025-09-03 16:45:27 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-09-08 18:02:39 +0100 |
| commit | 21d98bd960132033b2bbd460a40274d40ea28b60 (patch) | |
| tree | 6ced7d142b61b8adfc270b85c9c332190c025d4a /meta/lib | |
| parent | 857bb50a3533f897290add64706b98b72a0bded2 (diff) | |
| download | poky-21d98bd960132033b2bbd460a40274d40ea28b60.tar.gz | |
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>
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index 44442e402d..c244c9f188 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
| @@ -1166,7 +1166,7 @@ run_wic_cmd() { | |||
| 1166 | 1166 | ||
| 1167 | return wkspath | 1167 | return wkspath |
| 1168 | 1168 | ||
| 1169 | def _get_wic_partitions(self, wkspath, native_sysroot=None, ignore_status=False): | 1169 | def _get_wic(self, wkspath, ignore_status=False): |
| 1170 | p = runCmd("wic create %s -e core-image-minimal -o %s" % (wkspath, self.resultdir), | 1170 | p = runCmd("wic create %s -e core-image-minimal -o %s" % (wkspath, self.resultdir), |
| 1171 | ignore_status=ignore_status) | 1171 | ignore_status=ignore_status) |
| 1172 | 1172 | ||
| @@ -1180,7 +1180,13 @@ run_wic_cmd() { | |||
| 1180 | if not wicout: | 1180 | if not wicout: |
| 1181 | return (p, None) | 1181 | return (p, None) |
| 1182 | 1182 | ||
| 1183 | wicimg = wicout[0] | 1183 | return (p, wicout[0]) |
| 1184 | |||
| 1185 | def _get_wic_partitions(self, wkspath, native_sysroot=None, ignore_status=False): | ||
| 1186 | p, wicimg = self._get_wic(wkspath, ignore_status) | ||
| 1187 | |||
| 1188 | if wicimg is None: | ||
| 1189 | return (p, None) | ||
| 1184 | 1190 | ||
| 1185 | if not native_sysroot: | 1191 | if not native_sysroot: |
| 1186 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | 1192 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
| @@ -1320,6 +1326,45 @@ run_wic_cmd() { | |||
| 1320 | size = int(size[:-3]) | 1326 | size = int(size[:-3]) |
| 1321 | self.assertGreaterEqual(size, 204800) | 1327 | self.assertGreaterEqual(size, 204800) |
| 1322 | 1328 | ||
| 1329 | def test_extra_partition_space(self): | ||
| 1330 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | ||
| 1331 | |||
| 1332 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
| 1333 | tempf.write("bootloader --ptable gpt\n" \ | ||
| 1334 | "part --ondisk hda --size 10M --extra-partition-space 10M --fstype=ext4\n" \ | ||
| 1335 | "part --ondisk hda --fixed-size 20M --extra-partition-space 10M --fstype=ext4\n" \ | ||
| 1336 | "part --source rootfs --ondisk hda --extra-partition-space 10M --fstype=ext4\n" \ | ||
| 1337 | "part --source rootfs --ondisk hda --fixed-size 200M --extra-partition-space 10M --fstype=ext4\n") | ||
| 1338 | tempf.flush() | ||
| 1339 | |||
| 1340 | _, wicimg = self._get_wic(tempf.name) | ||
| 1341 | |||
| 1342 | res = runCmd("parted -m %s unit b p" % wicimg, | ||
| 1343 | native_sysroot=native_sysroot, stderr=subprocess.PIPE) | ||
| 1344 | |||
| 1345 | # parse parted output which looks like this: | ||
| 1346 | # BYT;\n | ||
| 1347 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n | ||
| 1348 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n | ||
| 1349 | partlns = res.output.splitlines()[2:] | ||
| 1350 | |||
| 1351 | self.assertEqual(4, len(partlns)) | ||
| 1352 | |||
| 1353 | # Test for each partitions that the extra part space exists | ||
| 1354 | for part in range(0, len(partlns)): | ||
| 1355 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % (part + 1)) | ||
| 1356 | partln = partlns[part].split(":") | ||
| 1357 | self.assertEqual(7, len(partln)) | ||
| 1358 | self.assertRegex(partln[3], r'^[0-9]+B$') | ||
| 1359 | part_size = int(partln[3].rstrip("B")) | ||
| 1360 | start = int(partln[1].rstrip("B")) / 512 | ||
| 1361 | length = part_size / 512 | ||
| 1362 | runCmd("dd if=%s of=%s skip=%d count=%d" % | ||
| 1363 | (wicimg, part_file, start, length)) | ||
| 1364 | res = runCmd("dumpe2fs %s -h | grep \"^Block count\"" % part_file) | ||
| 1365 | fs_size = int(res.output.split(":")[1].strip()) * 1024 | ||
| 1366 | self.assertLessEqual(fs_size + 10485760, part_size, "part file: %s" % part_file) | ||
| 1367 | |||
| 1323 | # TODO this test could also work on aarch64 | 1368 | # TODO this test could also work on aarch64 |
| 1324 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | 1369 | @skipIfNotArch(['i586', 'i686', 'x86_64']) |
| 1325 | @OETestTag("runqemu") | 1370 | @OETestTag("runqemu") |
