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=<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.

(From OE-Core rev: a31453fd52e0a52f3fa02cb9ae0878ea3782c2b7)

Signed-off-by: Steffen Greber <sgreber@lilafast.org>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Steffen Greber
2025-10-21 09:47:38 +00:00
committed by Richard Purdie
parent 06237fd316
commit 213d298940
2 changed files with 6 additions and 3 deletions

View File

@@ -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')

View File

@@ -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)