public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [OE-Core][PATCH v1] wic: implement reproducible Disk GUID
@ 2024-01-22 12:25 Adithya Balakumar
  2024-01-26 14:22 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Adithya Balakumar @ 2024-01-22 12:25 UTC (permalink / raw)
  To: openembedded-core
  Cc: Adithya Balakumar, shivanand.kunijadar, sai.sathujoda,
	dinesh.kumar, kazuhiro3.hayashi, jan.kiszka

From: Adithya Balakumar <adithya.balakumar@toshiba-tsip.com>

GPT based disks have a disk guid apart from the 32-bit disk identifier.
This commit implements reproducible disk guid by using SOURCE_DATE_EPOCH (if available) value as a random seed

Signed-off-by: Adithya Balakumar <adithya.balakumar@toshiba-tsip.com>
---
 scripts/lib/wic/plugins/imager/direct.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 9b619e41c1..d0f8481c2e 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -530,6 +530,21 @@ class PartitionedImage():
         exec_native_cmd("parted -s %s mklabel %s" % (device, ptable_format),
                         self.native_sysroot)
 
+    def _write_disk_guid(self):
+        if os.getenv('SOURCE_DATE_EPOCH'):
+            if self.ptable_format in ('gpt', 'gpt-hybrid'):
+                self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
+            elif self.ptable_format == "msdos":
+                self.disk_guid = '0x' + str(uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH'))).int & 0xFFFFFFFF)[:8]
+        else:
+            if self.ptable_format in ('gpt', 'gpt-hybrid'):
+                self.disk_guid = uuid.uuid4()
+            elif self.ptable_format == "msdos":
+                self.disk_guid = '0x' + str(uuid.uuid4())[:8]
+
+        logger.debug("Set disk guid %s", self.disk_guid)
+        sfdisk_cmd = "sfdisk --disk-id %s %s" % (self.path, self.disk_guid)
+        exec_native_cmd(sfdisk_cmd, self.native_sysroot)
 
     def create(self):
         self._make_disk(self.path,
@@ -537,6 +552,7 @@ class PartitionedImage():
                         self.min_size)
 
         self._write_identifier(self.path, self.identifier)
+        self._write_disk_guid()
 
         if self.ptable_format == "gpt-hybrid":
             mbr_path = self.path + ".mbr"
-- 
2.39.2




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-26 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22 12:25 [OE-Core][PATCH v1] wic: implement reproducible Disk GUID Adithya Balakumar
2024-01-26 14:22 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox