* [PATCH v2] wic: add option to specify the diskid
@ 2025-10-27 14:46 Steffen Greber
2025-10-27 17:09 ` [OE-core] " Mathieu Dubois-Briand
0 siblings, 1 reply; 4+ messages in thread
From: Steffen Greber @ 2025-10-27 14:46 UTC (permalink / raw)
To: openembedded-core; +Cc: Steffen Greber, Ross Burton
This adds a feature to specify the disk ID when creating a disk with
the wic tool. This is useful when using the DOS partition scheme and
booting with root=PARTUUID=<partuuid>. In DOS partitions, the partition
ID is <diskid>-<partition-number>, so it makes sense to let the user
define the disk ID.
You can specify it in the kickstart file using the --diskid argument
to the bootloader command. The value can be given in decimal or
hexadecimal format (e.g. 3735928559 or 0xdeadbeef). If omitted, the
previous behaviour does not change.
Signed-off-by: Steffen Greber <sgreber@lilafast.org>
Add WIC tests and support setting GPT diskid
Add unit tests for wic.py to cover previous patch review.
Also extend implementation to allow defining the diskid for GPT partitions.
CC: Ross Burton <Ross.Burton@arm.com>
Signed-off-by: Steffen Greber <sgreber@lilafast.org>
---
changes in v2:
- add diskid support for gpt tabels
- add wic tests as requested by the reviewer
---
meta/lib/oeqa/selftest/cases/wic.py | 36 ++++++++++++++++++++++++
scripts/lib/wic/ksparser.py | 20 +++++++++++++
scripts/lib/wic/plugins/imager/direct.py | 20 +++++++------
3 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index bb4ac23ebf..d7a9b14658 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -1905,6 +1905,42 @@ INITRAMFS_IMAGE = "core-image-initramfs-boot"
self.assertIn("Source parameter 'fill' only works with the '--fixed-size' option, exiting.", result.output)
self.assertNotEqual(0, result.status)
+ def test_diskid_on_msdos_partition(self):
+ """Test diksid on msdos partions"""
+ img = 'core-image-minimal'
+ diskid = "0xdeadbbef"
+ with NamedTemporaryFile("w", suffix=".wks") as wks:
+ wks.writelines(['bootloader --ptable msdos --diskid %s\n' % diskid,
+ 'part /boot --size=100M --active --fstype=ext4 --label boot\n'
+ 'part / --source rootfs --fstype=ext4 --label root\n'])
+ wks.flush()
+ cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
+ runCmd(cmd)
+ wksname = os.path.splitext(os.path.basename(wks.name))[0]
+ out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
+ self.assertEqual(1, len(out))
+ sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
+ result = runCmd("%s/usr/sbin/sfdisk -l %s | grep 'Disk identifier:'" % (sysroot, out[0]))
+ self.assertEqual("Disk identifier: %s" % diskid.lower(), result.output)
+
+ def test_diskid_on_gpt_partition(self):
+ """Test diksid on gpt partions"""
+ img = 'core-image-minimal'
+ diskid = "deadbeef-cafe-babe-f00d-cec2ea4eface"
+ with NamedTemporaryFile("w", suffix=".wks") as wks:
+ wks.writelines(['bootloader --ptable gpt --diskid %s\n' % diskid,
+ 'part /boot --size=100M --active --fstype=ext4 --label boot\n'
+ 'part / --source rootfs --fstype=ext4 --label root\n'])
+ wks.flush()
+ cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
+ runCmd(cmd)
+ wksname = os.path.splitext(os.path.basename(wks.name))[0]
+ out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
+ self.assertEqual(1, len(out))
+ sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
+ result = runCmd("%s/usr/sbin/sfdisk -l %s | grep 'Disk identifier:'" % (sysroot, out[0]))
+ self.assertEqual("Disk identifier: %s" % diskid.upper(), result.output)
+
class ModifyTests(WicTestCase):
def test_wic_ls(self):
"""Test listing image content using 'wic ls'"""
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index a762d3b6cf..4ccd70dc55 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -16,6 +16,7 @@ import os
import shlex
import logging
import re
+import uuid
from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
@@ -196,6 +197,7 @@ class KickStart():
bootloader.add_argument('--configfile')
bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'),
default='msdos')
+ bootloader.add_argument('--diskid')
bootloader.add_argument('--timeout', type=int)
bootloader.add_argument('--source')
@@ -296,6 +298,24 @@ class KickStart():
if append_var:
self.bootloader.append = ' '.join(filter(None, \
(self.bootloader.append, append_var)))
+ if parsed.diskid:
+ if parsed.ptable == "msdos":
+ try:
+ self.bootloader.diskid = int(parsed.diskid, 0)
+ except ValueError:
+ err = "with --ptbale msdos only 32bit integers " \
+ "are allowed for --diskid. %s could not " \
+ "be parsed" % self.ptable
+ raise KickStartError(err)
+ else:
+ try:
+ self.bootloader.diskid = uuid.UUID(parsed.diskid)
+ except ValueError:
+ err = "with --ptable %s only valid uuids are " \
+ "allowed for --diskid. %s could not be " \
+ "parsed" % (parsed.ptable, parsed.diskid)
+ raise KickStartError(err)
+
else:
err = "%s:%d: more than one bootloader specified" \
% (confpath, lineno)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 6e1f1c8cba..ad922cfbf1 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -76,7 +76,7 @@ class DirectPlugin(ImagerPlugin):
break
image_path = self._full_path(self.workdir, self.parts[0].disk, "direct")
- self._image = PartitionedImage(image_path, self.ptable_format,
+ self._image = PartitionedImage(image_path, self.ptable_format, self.ks.bootloader.diskid,
self.parts, self.native_sysroot,
options.extra_space)
@@ -302,7 +302,7 @@ class PartitionedImage():
Partitioned image in a file.
"""
- def __init__(self, path, ptable_format, partitions, native_sysroot=None, extra_space=0):
+ def __init__(self, path, ptable_format, disk_id, 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
@@ -315,7 +315,16 @@ class PartitionedImage():
# all partitions (in bytes)
self.ptable_format = ptable_format # Partition table format
# Disk system identifier
- if os.getenv('SOURCE_DATE_EPOCH'):
+ if disk_id and ptable_format in ('gpt', 'gpt-hybrid'):
+ self.disk_guid = disk_id
+ elif os.getenv('SOURCE_DATE_EPOCH'):
+ self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
+ else:
+ self.disk_guid = uuid.uuid4()
+
+ if disk_id and ptable_format == 'msdos':
+ self.identifier = disk_id
+ elif os.getenv('SOURCE_DATE_EPOCH'):
self.identifier = random.Random(int(os.getenv('SOURCE_DATE_EPOCH'))).randint(1, 0xffffffff)
else:
self.identifier = random.SystemRandom().randint(1, 0xffffffff)
@@ -543,11 +552,6 @@ class PartitionedImage():
def _write_disk_guid(self):
if self.ptable_format in ('gpt', 'gpt-hybrid'):
- if os.getenv('SOURCE_DATE_EPOCH'):
- self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
- else:
- self.disk_guid = uuid.uuid4()
-
logger.debug("Set disk guid %s", self.disk_guid)
sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \
(self.sector_size, self.path, self.disk_guid)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [OE-core] [PATCH v2] wic: add option to specify the diskid
2025-10-27 14:46 [PATCH v2] wic: add option to specify the diskid Steffen Greber
@ 2025-10-27 17:09 ` Mathieu Dubois-Briand
2025-10-27 17:58 ` Steffen Greber
0 siblings, 1 reply; 4+ messages in thread
From: Mathieu Dubois-Briand @ 2025-10-27 17:09 UTC (permalink / raw)
To: Steffen Greber, openembedded-core; +Cc: Ross Burton
On Mon Oct 27, 2025 at 3:46 PM CET, Steffen Greber wrote:
> This adds a feature to specify the disk ID when creating a disk with
> the wic tool. This is useful when using the DOS partition scheme and
> booting with root=PARTUUID=<partuuid>. In DOS partitions, the partition
> ID is <diskid>-<partition-number>, so it makes sense to let the user
> define the disk ID.
>
> You can specify it in the kickstart file using the --diskid argument
> to the bootloader command. The value can be given in decimal or
> hexadecimal format (e.g. 3735928559 or 0xdeadbeef). If omitted, the
> previous behaviour does not change.
>
> Signed-off-by: Steffen Greber <sgreber@lilafast.org>
>
> Add WIC tests and support setting GPT diskid
>
> Add unit tests for wic.py to cover previous patch review.
> Also extend implementation to allow defining the diskid for GPT partitions.
>
> CC: Ross Burton <Ross.Burton@arm.com>
> Signed-off-by: Steffen Greber <sgreber@lilafast.org>
> ---
Hi Steffen,
Thanks for the v2, but it looks like the v1 was merged. Can you rebase
on master and make a separate patch for tests and GPT partitions
handling?
Thanks,
Mathieu
--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] wic: add option to specify the diskid
2025-10-27 17:09 ` [OE-core] " Mathieu Dubois-Briand
@ 2025-10-27 17:58 ` Steffen Greber
2025-10-27 18:05 ` [OE-core] " Alexander Kanavin
0 siblings, 1 reply; 4+ messages in thread
From: Steffen Greber @ 2025-10-27 17:58 UTC (permalink / raw)
To: openembedded-core
[-- Attachment #1: Type: text/plain, Size: 141 bytes --]
Sure, I can do. Btw I am asking myself if I should also add some documentation? Or will this be done by someone else?
regards
Steffen
[-- Attachment #2: Type: text/html, Size: 214 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [OE-core] [PATCH v2] wic: add option to specify the diskid
2025-10-27 17:58 ` Steffen Greber
@ 2025-10-27 18:05 ` Alexander Kanavin
0 siblings, 0 replies; 4+ messages in thread
From: Alexander Kanavin @ 2025-10-27 18:05 UTC (permalink / raw)
To: sgreber; +Cc: openembedded-core
On Mon, 27 Oct 2025 at 18:58, Steffen Greber via
lists.openembedded.org <sgreber=lilafast.org@lists.openembedded.org>
wrote:
> Sure, I can do. Btw I am asking myself if I should also add some documentation? Or will this be done by someone else?
It's better if you can send a patch for the docs as well.
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-27 18:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 14:46 [PATCH v2] wic: add option to specify the diskid Steffen Greber
2025-10-27 17:09 ` [OE-core] " Mathieu Dubois-Briand
2025-10-27 17:58 ` Steffen Greber
2025-10-27 18:05 ` [OE-core] " Alexander Kanavin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.