From a31453fd52e0a52f3fa02cb9ae0878ea3782c2b7 Mon Sep 17 00:00:00 2001 From: Steffen Greber Date: Tue, 21 Oct 2025 09:47:38 +0000 Subject: [PATCH] wic: add option to specify the diskid 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=. In DOS partitions, the partition ID is -, 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 Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- scripts/lib/wic/ksparser.py | 1 + scripts/lib/wic/plugins/imager/direct.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py index a762d3b6cf..48b5b09ddd 100644 --- a/scripts/lib/wic/ksparser.py +++ b/scripts/lib/wic/ksparser.py @@ -196,6 +196,7 @@ class KickStart(): bootloader.add_argument('--configfile') bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'), default='msdos') + bootloader.add_argument('--diskid', type=lambda x: int(x, 0)) bootloader.add_argument('--timeout', type=int) bootloader.add_argument('--source') diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index 6e1f1c8cba..f40f033a3d 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,9 @@ 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: + 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) -- 2.47.3