Skip to contentSkip to conversation

wic: use part_name when defined

RFC PATCH In review [email protected] 3 participants 4 messages Mar 22, 2023 – Apr 6, 2023

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 wic: use part_name when defined

From: Dit Kozmaj <[email protected]>

So far part.label has been used to define GPT partition label even if part.part_name was defined.
Fix the code to use part.part_name whenever available, as it makes sense to have a GPT partition label which is different from the contained filesystem label.

---
 scripts/lib/wic/plugins/imager/direct.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +4 -10
index dfaa901567..1f06b89f8e 100644
@@ -571,11 +571,12 @@ class PartitionedImage():
             self._create_partition(self.path, part.type,
                                    parted_fs_type, part.start, part.size_sec)
 
-            if part.part_name:
+            if part.part_name or part.label:
+                partition_label = part.part_name if part.part_name else part.label
                 logger.debug("partition %d: set name to %s",
-                             part.num, part.part_name)
+                             part.num, partition_label)
                 exec_native_cmd("sgdisk --change-name=%d:%s %s" % \
-                                         (part.num, part.part_name,
+                                         (part.num, partition_label,
                                           self.path), self.native_sysroot)
 
             if part.part_type:
@@ -592,13 +593,6 @@ class PartitionedImage():
                                 (part.num, part.uuid, self.path),
                                 self.native_sysroot)
 
-            if part.label and self.ptable_format == "gpt":
-                logger.debug("partition %d: set name to %s",
-                             part.num, part.label)
-                exec_native_cmd("parted -s %s name %d %s" % \
-                                (self.path, part.num, part.label),
-                                self.native_sysroot)
-
             if part.active:
                 flag_name = "legacy_boot" if self.ptable_format == 'gpt' else "boot"
                 logger.debug("Set '%s' flag for partition '%s' on disk '%s'",
Signature · 1 line
2.34.1
author
#1 lore raw

Hi,
We tested a few combinations of --part-name and --label parameters when creating a WIC image.

When only the --part-name is defined, the GPT partition label is correctly set, and filesystem label is empty.

If both are defined, or only --label is defined, both the filesystem label and the GPT partition label are set to the value of --label.

As it makes sense to have a GPT partition label which is different from the contained filesystem label, our proposal is to fix the case when both are set, and keep the current behavior when only --label is set for compatibility reasons.

If this proposal is ok, we will patch the documentation to document that the GPT partition label is set even when only --label is defined.

Regards

Quoted 57 lines · On Wed, Mar 22, 2023 at 4:54 PM <[email protected]> wrote:

From: Dit Kozmaj <[email protected]>

So far part.label has been used to define GPT partition label even if part.part_name was defined.
Fix the code to use part.part_name whenever available, as it makes sense to have a GPT partition label which is different from the contained filesystem label.

---
 scripts/lib/wic/plugins/imager/direct.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +2 -1
index dfaa901567..1f06b89f8e 100644
@@ -571,11 +571,12 @@ class PartitionedImage():
             self._create_partition(self.path, part.type,
                                    parted_fs_type, part.start,
 part.size_sec)
 
-            if part.part_name:
+            if part.part_name or part.label:
+                partition_label = part.part_name if part.part_name else

part.label
logger.debug("partition %d: set name to %s",

scripts/lib/wic/plugins/imager/direct.py +2 -9
-                             part.num, part.part_name)
+                             part.num, partition_label)
                 exec_native_cmd("sgdisk --change-name=%d:%s %s" % \
-                                         (part.num, part.part_name,
+                                         (part.num, partition_label,
                                           self.path), self.native_sysroot)
 
             if part.part_type:
@@ -592,13 +593,6 @@ class PartitionedImage():
                                 (part.num, part.uuid, self.path),
                                 self.native_sysroot)
 
-            if part.label and self.ptable_format == "gpt":
-                logger.debug("partition %d: set name to %s",
-                             part.num, part.label)
-                exec_native_cmd("parted -s %s name %d %s" % \
-                                (self.path, part.num, part.label),
-                                self.native_sysroot)
-
             if part.active:
                 flag_name = "legacy_boot" if self.ptable_format == 'gpt'

else "boot"
logger.debug("Set '%s' flag for partition '%s' on disk
'%s'",
--
2.34.1

#2 lore raw
In reply to [email protected]
Quoted 38 lines · On Wed, 2023-03-22 at 16:54 +0100, [email protected] wrote:

From: Dit Kozmaj <[email protected]>

So far part.label has been used to define GPT partition label even if part.part_name was defined.
Fix the code to use part.part_name whenever available, as it makes sense to have a GPT partition label which is different from the contained filesystem label.

---
 scripts/lib/wic/plugins/imager/direct.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +4 -3
index dfaa901567..1f06b89f8e 100644
@@ -571,11 +571,12 @@ class PartitionedImage():
             self._create_partition(self.path, part.type,
                                    parted_fs_type, part.start, part.size_sec)
 
-            if part.part_name:
+            if part.part_name or part.label:
+                partition_label = part.part_name if part.part_name else part.label
                 logger.debug("partition %d: set name to %s",
-                             part.num, part.part_name)
+                             part.num, partition_label)
                 exec_native_cmd("sgdisk --change-name=%d:%s %s" % \
-                                         (part.num, part.part_name,
+                                         (part.num, partition_label,
                                           self.path), self.native_sysroot)
 
             if part.part_type:
@@ -592,13 +593,6 @@ class PartitionedImage():
                                 (part.num, part.uuid, self.path),
                                 self.native_sysroot)
 

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 598

Quoted 10 lines
scripts/lib/wic/plugins/imager/direct.py +0 -7
-            if part.label and self.ptable_format == "gpt":
-                logger.debug("partition %d: set name to %s",
-                             part.num, part.label)
-                exec_native_cmd("parted -s %s name %d %s" % \
-                                (self.path, part.num, part.label),
-                                self.native_sysroot)
-
             if part.active:
                 flag_name = "legacy_boot" if self.ptable_format == 'gpt' else "boot"
                 logger.debug("Set '%s' flag for partition '%s' on disk '%s'",

This was flagged on irc as not having a response. We're struggling with a lack of a maintainer for wic at the moment so review is slow and I'm not really a wic expert but I'm all we have :/.

As mentioned, changes to code like this are much more likely if there is a test case included. The existing tests can be run with "oe- selftest -r wic".

Can you confirm this patch doesn't regress the current tests?

Would you be able to add a test so this change doesn't regress in future?

Cheers,

Richard

#3 lore raw

Hi,

Quoted 60 lines · Richard Purdie
Quoted 8 lines · On Wed, 2023-03-22 at 16:54 +0100, [email protected] wrote:

From: Dit Kozmaj <[email protected]>

So far part.label has been used to define GPT partition label even if part.part_name was defined.
Fix the code to use part.part_name whenever available, as it makes sense to have a GPT partition label which is different from the contained filesystem label.

Review

Quoted 7 lines
---
 scripts/lib/wic/plugins/imager/direct.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/scripts/lib/wic/plugins/imager/direct.py

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 572

Quoted 6 lines

index dfaa901567..1f06b89f8e 100644

scripts/lib/wic/plugins/imager/direct.py +0 -0
@@ -571,11 +571,12 @@ class PartitionedImage():
             self._create_partition(self.path, part.type,
                                    parted_fs_type, part.start,

part.size_sec)

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage():

Quoted 4 lines
scripts/lib/wic/plugins/imager/direct.py +2 -1
-            if part.part_name:
+            if part.part_name or part.label:
+                partition_label = part.part_name if part.part_name else

part.label

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage():

Quoted 7 lines
scripts/lib/wic/plugins/imager/direct.py +2 -2
                 logger.debug("partition %d: set name to %s",
-                             part.num, part.part_name)
+                             part.num, partition_label)
                 exec_native_cmd("sgdisk --change-name=%d:%s %s" % \
-                                         (part.num, part.part_name,
+                                         (part.num, partition_label,
                                           self.path),

self.native_sysroot)

Quoted 5 lines
scripts/lib/wic/plugins/imager/direct.py +0 -0
             if part.part_type:
@@ -592,13 +593,6 @@ class PartitionedImage():
                                 (part.num, part.uuid, self.path),
                                 self.native_sysroot)

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 597

Quoted 10 lines
scripts/lib/wic/plugins/imager/direct.py +0 -7
 
-            if part.label and self.ptable_format == "gpt":
-                logger.debug("partition %d: set name to %s",
-                             part.num, part.label)
-                exec_native_cmd("parted -s %s name %d %s" % \
-                                (self.path, part.num, part.label),
-                                self.native_sysroot)
-
             if part.active:
                 flag_name = "legacy_boot" if self.ptable_format ==

'gpt' else "boot"

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 598

Quoted 1 line
scripts/lib/wic/plugins/imager/direct.py +0 -0
                 logger.debug("Set '%s' flag for partition '%s' on disk

'%s'",

This was flagged on irc as not having a response. We're struggling with a lack of a maintainer for wic at the moment so review is slow and I'm not really a wic expert but I'm all we have :/.

Quoted 6 lines

As mentioned, changes to code like this are much more likely if there is a test case included. The existing tests can be run with "oe- selftest -r wic".

Can you confirm this patch doesn't regress the current tests?

We've sent a new patchset that doesn't regress the current tests:
https://patchwork.yoctoproject.org/project/oe-core/list/?series=11822

Quoted 3 lines

Would you be able to add a test so this change doesn't regress in future?

The aforementioned patchset includes a new test for that purpose and updates the documentation to reflect the changes and explain what happens in each case.

This RFC is superseded by the patchset.

Cheers,

Quoted 4 lines

Richard

Cheers,

Diego Rondini
Sr. Embedded Engineer

Kynetics
www.kynetics.com