Skip to contentSkip to conversation

wic: add 'part-name' argument for naming GPT partitions

PATCH In review Artur Mądrzak 2 participants 2 messages Nov 7, 2017 – Nov 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wic: add 'part-name' argument for naming GPT partitions

The WIC's 'part' can now give a name for GPT partition in WKS file. It's similar to '--label', but is naming partintions instead file systems. It's required by some bootloaders to partitions have specified names.

Backport from master to be able generate SD card image for Dragonboard410c.

---
 scripts/lib/wic/help.py                |  2 ++
 scripts/lib/wic/imager/direct.py       |  1 +
 scripts/lib/wic/ksparser.py            |  1 +
 scripts/lib/wic/partition.py           |  1 +
 scripts/lib/wic/utils/partitionedfs.py | 15 ++++++++++++++-
 5 files changed, 19 insertions(+), 1 deletion(-)
scripts/lib/wic/help.py +2 -0
index e5347ec4b7..324499e438 100644
@@ -727,6 +727,8 @@ DESCRIPTION
                             equal to 1.
                             The default value is 1.3.
 
+         --part-name: This option is specific to wic. It specifies name for GPT partitions.
+
          --part-type: This option is specific to wic. It specifies partition
                       type GUID for GPT partitions.
                       List of partition type GUIDS can be found here:
scripts/lib/wic/imager/direct.py +1 -0
index 4c547e04a6..6cb209aa88 100644
@@ -299,6 +299,7 @@ class DirectImageCreator(BaseImageCreator):
                                        boot=part.active,
                                        align=part.align,
                                        no_table=part.no_table,
+                                       part_name=part.part_name,
                                        part_type=part.part_type,
                                        uuid=part.uuid,
                                        system_id=part.system_id)
scripts/lib/wic/ksparser.py +1 -0
index 0894e2b199..3c99136144 100644
@@ -134,6 +134,7 @@ class KickStart():
         part.add_argument('--no-table', action='store_true')
         part.add_argument('--ondisk', '--ondrive', dest='disk')
         part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
+        part.add_argument('--part-name')
         part.add_argument('--part-type')
         part.add_argument('--rootfs-dir')
         part.add_argument('--size', type=sizetype, default=0)
scripts/lib/wic/partition.py +1 -0
index ec3aa6622c..2ffe7e3350 100644
@@ -51,6 +51,7 @@ class Partition():
         self.mountpoint = args.mountpoint
         self.no_table = args.no_table
         self.overhead_factor = args.overhead_factor
+        self.part_name = args.part_name
         self.part_type = args.part_type
         self.rootfs_dir = args.rootfs_dir
         self.size = args.size
scripts/lib/wic/utils/partitionedfs.py +14 -1
index 9ea4a30cbb..d18fa1d489 100644
@@ -91,7 +91,7 @@ class Image():
 
     def add_partition(self, size, disk_name, mountpoint, source_file=None, fstype=None,
                       label=None, fsopts=None, boot=False, align=None, no_table=False,
-                      part_type=None, uuid=None, system_id=None):
+                      part_name=None, part_type=None, uuid=None, system_id=None):
         """ Add the next partition. Partitions have to be added in the
         first-to-last order. """
 
@@ -113,6 +113,7 @@ class Image():
                 'boot': boot, # Bootable flag
                 'align': align, # Partition alignment
                 'no_table' : no_table, # Partition does not appear in partition table
+                'part_name' : part_name, # Partition name
                 'part_type' : part_type, # Partition type
                 'uuid': uuid, # Partition UUID
                 'system_id': system_id} # Partition system id
@@ -146,6 +147,11 @@ class Image():
                 raise ImageError("setting custom partition type is not " \
                                  "implemented for msdos partitions")
 
+            if ptable_format == 'msdos' and part['part_name']:
+                raise ImageError("setting custom partition name is not " \
+                                 "implemented for msdos partitions")
+
+
             # Get the disk where the partition is located
             disk = self.disks[part['disk_name']]
             disk['numpart'] += 1
@@ -301,6 +307,13 @@ class Image():
             self.__create_partition(disk['disk'].device, part['type'],
                                     parted_fs_type, part['start'], part['size'])
 
+            if part['part_name']:
+                msger.debug("partition %d: set  name to %s" % \
+                            (part['num'], part['part_name']))
+                exec_native_cmd("sgdisk --change-name=%d:%s %s" % \
+                                         (part['num'], part['part_name'],
+                                          disk['disk'].device), self.native_sysroot)
+
             if part['part_type']:
                 msger.debug("partition %d: set type UID to %s" % \
                             (part['num'], part['part_type']))
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw

+Armin.

Quoted 7 lines · Artur Mądrzak

The WIC's 'part' can now give a name for GPT partition in WKS file. It's similar to '--label', but is naming partintions instead file systems. It's required by some bootloaders to partitions have specified names.

Backport from master to be able generate SD card image for Dragonboard410c.

Quoted 107 lines
---
 scripts/lib/wic/help.py                |  2 ++
 scripts/lib/wic/imager/direct.py       |  1 +
 scripts/lib/wic/ksparser.py            |  1 +
 scripts/lib/wic/partition.py           |  1 +
 scripts/lib/wic/utils/partitionedfs.py | 15 ++++++++++++++-
 5 files changed, 19 insertions(+), 1 deletion(-)
scripts/lib/wic/help.py +2 -0
index e5347ec4b7..324499e438 100644
@@ -727,6 +727,8 @@ DESCRIPTION
                             equal to 1.
                             The default value is 1.3.
 
+         --part-name: This option is specific to wic. It specifies name for GPT partitions.
+
          --part-type: This option is specific to wic. It specifies partition
                       type GUID for GPT partitions.
                       List of partition type GUIDS can be found here:
scripts/lib/wic/imager/direct.py +1 -0
index 4c547e04a6..6cb209aa88 100644
@@ -299,6 +299,7 @@ class DirectImageCreator(BaseImageCreator):
                                        boot=part.active,
                                        align=part.align,
                                        no_table=part.no_table,
+                                       part_name=part.part_name,
                                        part_type=part.part_type,
                                        uuid=part.uuid,
                                        system_id=part.system_id)
scripts/lib/wic/ksparser.py +1 -0
index 0894e2b199..3c99136144 100644
@@ -134,6 +134,7 @@ class KickStart():
         part.add_argument('--no-table', action='store_true')
         part.add_argument('--ondisk', '--ondrive', dest='disk')
         part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
+        part.add_argument('--part-name')
         part.add_argument('--part-type')
         part.add_argument('--rootfs-dir')
         part.add_argument('--size', type=sizetype, default=0)
scripts/lib/wic/partition.py +1 -0
index ec3aa6622c..2ffe7e3350 100644
@@ -51,6 +51,7 @@ class Partition():
         self.mountpoint = args.mountpoint
         self.no_table = args.no_table
         self.overhead_factor = args.overhead_factor
+        self.part_name = args.part_name
         self.part_type = args.part_type
         self.rootfs_dir = args.rootfs_dir
         self.size = args.size
scripts/lib/wic/utils/partitionedfs.py +14 -2
index 9ea4a30cbb..d18fa1d489 100644
@@ -91,7 +91,7 @@ class Image():
 
     def add_partition(self, size, disk_name, mountpoint, source_file=None, fstype=None,
                       label=None, fsopts=None, boot=False, align=None, no_table=False,
-                      part_type=None, uuid=None, system_id=None):
+                      part_name=None, part_type=None, uuid=None, system_id=None):
         """ Add the next partition. Partitions have to be added in the
         first-to-last order. """
 
@@ -113,6 +113,7 @@ class Image():
                 'boot': boot, # Bootable flag
                 'align': align, # Partition alignment
                 'no_table' : no_table, # Partition does not appear in partition table
+                'part_name' : part_name, # Partition name
                 'part_type' : part_type, # Partition type
                 'uuid': uuid, # Partition UUID
                 'system_id': system_id} # Partition system id
@@ -146,6 +147,11 @@ class Image():
                 raise ImageError("setting custom partition type is not " \
                                  "implemented for msdos partitions")
 
+            if ptable_format == 'msdos' and part['part_name']:
+                raise ImageError("setting custom partition name is not " \
+                                 "implemented for msdos partitions")
+
+
             # Get the disk where the partition is located
             disk = self.disks[part['disk_name']]
             disk['numpart'] += 1
@@ -301,6 +307,13 @@ class Image():
             self.__create_partition(disk['disk'].device, part['type'],
                                     parted_fs_type, part['start'], part['size'])
 
+            if part['part_name']:
+                msger.debug("partition %d: set  name to %s" % \
+                            (part['num'], part['part_name']))
+                exec_native_cmd("sgdisk --change-name=%d:%s %s" % \
+                                         (part['num'], part['part_name'],
+                                          disk['disk'].device), self.native_sysroot)
+
             if part['part_type']:
                 msger.debug("partition %d: set type UID to %s" % \
                             (part['num'], part['part_type']))
--

2.13.6