summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/utils/partitionedfs.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/mic/utils/partitionedfs.py')
-rw-r--r--scripts/lib/mic/utils/partitionedfs.py58
1 files changed, 8 insertions, 50 deletions
diff --git a/scripts/lib/mic/utils/partitionedfs.py b/scripts/lib/mic/utils/partitionedfs.py
index 83ce869860..0c4c9ecfa0 100644
--- a/scripts/lib/mic/utils/partitionedfs.py
+++ b/scripts/lib/mic/utils/partitionedfs.py
@@ -24,13 +24,10 @@ from mic import msger
24from mic.utils import runner 24from mic.utils import runner
25from mic.utils.errors import MountError 25from mic.utils.errors import MountError
26from mic.utils.fs_related import * 26from mic.utils.fs_related import *
27from mic.utils.gpt_parser import GptParser
28from mic.utils.oe.misc import * 27from mic.utils.oe.misc import *
29 28
30# Overhead of the MBR partitioning scheme (just one sector) 29# Overhead of the MBR partitioning scheme (just one sector)
31MBR_OVERHEAD = 1 30MBR_OVERHEAD = 1
32# Overhead of the GPT partitioning scheme
33GPT_OVERHEAD = 34
34 31
35# Size of a sector in bytes 32# Size of a sector in bytes
36SECTOR_SIZE = 512 33SECTOR_SIZE = 512
@@ -148,21 +145,20 @@ class PartitionedMount(Mount):
148 'num': None, # Partition number 145 'num': None, # Partition number
149 'boot': boot, # Bootable flag 146 'boot': boot, # Bootable flag
150 'align': align, # Partition alignment 147 'align': align, # Partition alignment
151 'part_type' : part_type, # Partition type 148 'part_type' : part_type } # Partition type
152 'partuuid': None } # Partition UUID (GPT-only)
153 149
154 self.__add_partition(part) 150 self.__add_partition(part)
155 151
156 def layout_partitions(self, ptable_format = "msdos"): 152 def layout_partitions(self, ptable_format = "msdos"):
157 """ Layout the partitions, meaning calculate the position of every 153 """ Layout the partitions, meaning calculate the position of every
158 partition on the disk. The 'ptable_format' parameter defines the 154 partition on the disk. The 'ptable_format' parameter defines the
159 partition table format, and may be either "msdos" or "gpt". """ 155 partition table format and may be "msdos". """
160 156
161 msger.debug("Assigning %s partitions to disks" % ptable_format) 157 msger.debug("Assigning %s partitions to disks" % ptable_format)
162 158
163 if ptable_format not in ('msdos', 'gpt'): 159 if ptable_format not in ('msdos'):
164 raise MountError("Unknown partition table format '%s', supported " \ 160 raise MountError("Unknown partition table format '%s', supported " \
165 "formats are: 'msdos' and 'gpt'" % ptable_format) 161 "formats are: 'msdos'" % ptable_format)
166 162
167 if self._partitions_layed_out: 163 if self._partitions_layed_out:
168 return 164 return
@@ -177,12 +173,12 @@ class PartitionedMount(Mount):
177 raise MountError("No disk %s for partition %s" \ 173 raise MountError("No disk %s for partition %s" \
178 % (p['disk_name'], p['mountpoint'])) 174 % (p['disk_name'], p['mountpoint']))
179 175
180 if p['part_type'] and ptable_format != 'gpt': 176 if p['part_type']:
181 # The --part-type can also be implemented for MBR partitions, 177 # The --part-type can also be implemented for MBR partitions,
182 # in which case it would map to the 1-byte "partition type" 178 # in which case it would map to the 1-byte "partition type"
183 # filed at offset 3 of the partition entry. 179 # filed at offset 3 of the partition entry.
184 raise MountError("setting custom partition type is only " \ 180 raise MountError("setting custom partition type is not " \
185 "imlemented for GPT partitions") 181 "implemented for msdos partitions")
186 182
187 # Get the disk where the partition is located 183 # Get the disk where the partition is located
188 d = self.disks[p['disk_name']] 184 d = self.disks[p['disk_name']]
@@ -192,8 +188,6 @@ class PartitionedMount(Mount):
192 if d['numpart'] == 1: 188 if d['numpart'] == 1:
193 if ptable_format == "msdos": 189 if ptable_format == "msdos":
194 overhead = MBR_OVERHEAD 190 overhead = MBR_OVERHEAD
195 else:
196 overhead = GPT_OVERHEAD
197 191
198 # Skip one sector required for the partitioning scheme overhead 192 # Skip one sector required for the partitioning scheme overhead
199 d['offset'] += overhead 193 d['offset'] += overhead
@@ -250,9 +244,6 @@ class PartitionedMount(Mount):
250 # minumim disk sizes. 244 # minumim disk sizes.
251 for disk_name, d in self.disks.items(): 245 for disk_name, d in self.disks.items():
252 d['min_size'] = d['offset'] 246 d['min_size'] = d['offset']
253 if d['ptable_format'] == 'gpt':
254 # Account for the backup partition table at the end of the disk
255 d['min_size'] += GPT_OVERHEAD
256 247
257 d['min_size'] *= self.sector_size 248 d['min_size'] *= self.sector_size
258 249
@@ -339,10 +330,7 @@ class PartitionedMount(Mount):
339 parted_fs_type, p['start'], p['size']) 330 parted_fs_type, p['start'], p['size'])
340 331
341 if p['boot']: 332 if p['boot']:
342 if d['ptable_format'] == 'gpt': 333 flag_name = "boot"
343 flag_name = "legacy_boot"
344 else:
345 flag_name = "boot"
346 msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \ 334 msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \
347 (flag_name, p['num'], d['disk'].device)) 335 (flag_name, p['num'], d['disk'].device))
348 self.__run_parted(["-s", d['disk'].device, "set", 336 self.__run_parted(["-s", d['disk'].device, "set",
@@ -358,36 +346,6 @@ class PartitionedMount(Mount):
358 self.__run_parted(["-s", d['disk'].device, "set", 346 self.__run_parted(["-s", d['disk'].device, "set",
359 "%d" % p['num'], "lba", "off"]) 347 "%d" % p['num'], "lba", "off"])
360 348
361 # If the partition table format is "gpt", find out PARTUUIDs for all
362 # the partitions. And if users specified custom parition type UUIDs,
363 # set them.
364 for disk_name, disk in self.disks.items():
365 if disk['ptable_format'] != 'gpt':
366 continue
367
368 pnum = 0
369 gpt_parser = GptParser(d['disk'].device, SECTOR_SIZE)
370 # Iterate over all GPT partitions on this disk
371 for entry in gpt_parser.get_partitions():
372 pnum += 1
373 # Find the matching partition in the 'self.partitions' list
374 for n in d['partitions']:
375 p = self.partitions[n]
376 if p['num'] == pnum:
377 # Found, fetch PARTUUID (partition's unique ID)
378 p['partuuid'] = entry['part_uuid']
379 msger.debug("PARTUUID for partition %d on disk '%s' " \
380 "(mount point '%s') is '%s'" % (pnum, \
381 disk_name, p['mountpoint'], p['partuuid']))
382 if p['part_type']:
383 entry['type_uuid'] = p['part_type']
384 msger.debug("Change type of partition %d on disk " \
385 "'%s' (mount point '%s') to '%s'" % \
386 (pnum, disk_name, p['mountpoint'],
387 p['part_type']))
388 gpt_parser.change_partition(entry)
389
390 del gpt_parser
391 349
392 def __map_partitions(self): 350 def __map_partitions(self):
393 """Load it if dm_snapshot isn't loaded. """ 351 """Load it if dm_snapshot isn't loaded. """