summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic')
-rw-r--r--scripts/lib/wic/imager/direct.py31
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/partition.py6
-rw-r--r--scripts/lib/wic/utils/partitionedfs.py20
3 files changed, 42 insertions, 15 deletions
diff --git a/scripts/lib/wic/imager/direct.py b/scripts/lib/wic/imager/direct.py
index b1dc3e96f4..38d4e78e62 100644
--- a/scripts/lib/wic/imager/direct.py
+++ b/scripts/lib/wic/imager/direct.py
@@ -74,6 +74,22 @@ class DirectImageCreator(BaseImageCreator):
74 self.kernel_dir = kernel_dir 74 self.kernel_dir = kernel_dir
75 self.native_sysroot = native_sysroot 75 self.native_sysroot = native_sysroot
76 76
77 def __get_part_num(self, num, parts):
78 """calculate the real partition number, accounting for partitions not
79 in the partition table and logical partitions
80 """
81 realnum = 0
82 for n, p in enumerate(parts, 1):
83 if not p.no_table:
84 realnum += 1
85 if n == num:
86 if p.no_table:
87 return 0
88 if self._ptable_format == 'msdos' and realnum > 3:
89 # account for logical partition numbering, ex. sda5..
90 return realnum + 1
91 return realnum
92
77 def __write_fstab(self, image_rootfs): 93 def __write_fstab(self, image_rootfs):
78 """overriden to generate fstab (temporarily) in rootfs. This is called 94 """overriden to generate fstab (temporarily) in rootfs. This is called
79 from _create, make sure it doesn't get called from 95 from _create, make sure it doesn't get called from
@@ -98,7 +114,8 @@ class DirectImageCreator(BaseImageCreator):
98 def _update_fstab(self, fstab_lines, parts): 114 def _update_fstab(self, fstab_lines, parts):
99 """Assume partition order same as in wks""" 115 """Assume partition order same as in wks"""
100 for num, p in enumerate(parts, 1): 116 for num, p in enumerate(parts, 1):
101 if not p.mountpoint or p.mountpoint == "/" or p.mountpoint == "/boot": 117 pnum = self.__get_part_num(num, parts)
118 if not p.mountpoint or p.mountpoint == "/" or p.mountpoint == "/boot" or pnum == 0:
102 continue 119 continue
103 120
104 part = '' 121 part = ''
@@ -106,11 +123,6 @@ class DirectImageCreator(BaseImageCreator):
106 if p.disk.startswith('mmcblk'): 123 if p.disk.startswith('mmcblk'):
107 part = 'p' 124 part = 'p'
108 125
109 pnum = num
110 if self._ptable_format == 'msdos' and pnum > 3:
111 # account for logical partition numbering, ex. sda5..
112 pnum += 1
113
114 device_name = "/dev/" + p.disk + part + str(pnum) 126 device_name = "/dev/" + p.disk + part + str(pnum)
115 127
116 opts = "defaults" 128 opts = "defaults"
@@ -262,6 +274,7 @@ class DirectImageCreator(BaseImageCreator):
262 fsopts = p.fsopts, 274 fsopts = p.fsopts,
263 boot = p.active, 275 boot = p.active,
264 align = p.align, 276 align = p.align,
277 no_table = p.no_table,
265 part_type = p.part_type) 278 part_type = p.part_type)
266 279
267 self.__image.layout_partitions(self._ptable_format) 280 self.__image.layout_partitions(self._ptable_format)
@@ -350,10 +363,8 @@ class DirectImageCreator(BaseImageCreator):
350 if p.disk.startswith('mmcblk'): 363 if p.disk.startswith('mmcblk'):
351 part = 'p' 364 part = 'p'
352 365
353 if self._ptable_format == 'msdos' and num > 3: 366 pnum = self.__get_part_num(num, parts)
354 rootdev = "/dev/%s%s%-d" % (p.disk, part, num + 1) 367 rootdev = "/dev/%s%s%-d" % (p.disk, part, pnum)
355 else:
356 rootdev = "/dev/%s%s%-d" % (p.disk, part, num)
357 root_part_uuid = p.part_type 368 root_part_uuid = p.part_type
358 369
359 return (rootdev, root_part_uuid) 370 return (rootdev, root_part_uuid)
diff --git a/scripts/lib/wic/kickstart/custom_commands/partition.py b/scripts/lib/wic/kickstart/custom_commands/partition.py
index 7a307065f2..9be6b0457b 100644
--- a/scripts/lib/wic/kickstart/custom_commands/partition.py
+++ b/scripts/lib/wic/kickstart/custom_commands/partition.py
@@ -49,6 +49,7 @@ class Wic_PartData(Mic_PartData):
49 self.source = kwargs.get("source", None) 49 self.source = kwargs.get("source", None)
50 self.sourceparams = kwargs.get("sourceparams", None) 50 self.sourceparams = kwargs.get("sourceparams", None)
51 self.rootfs = kwargs.get("rootfs-dir", None) 51 self.rootfs = kwargs.get("rootfs-dir", None)
52 self.no_table = kwargs.get("no-table", False)
52 self.source_file = "" 53 self.source_file = ""
53 self.size = 0 54 self.size = 0
54 55
@@ -61,6 +62,8 @@ class Wic_PartData(Mic_PartData):
61 retval += " --sourceparams=%s" % self.sourceparams 62 retval += " --sourceparams=%s" % self.sourceparams
62 if self.rootfs: 63 if self.rootfs:
63 retval += " --rootfs-dir=%s" % self.rootfs 64 retval += " --rootfs-dir=%s" % self.rootfs
65 if self.no_table:
66 retval += " --no-table"
64 67
65 return retval 68 return retval
66 69
@@ -521,4 +524,7 @@ class Wic_Partition(Mic_Partition):
521 # use specified rootfs path to fill the partition 524 # use specified rootfs path to fill the partition
522 op.add_option("--rootfs-dir", type="string", action="store", 525 op.add_option("--rootfs-dir", type="string", action="store",
523 dest="rootfs", default=None) 526 dest="rootfs", default=None)
527 # wether to add the partition in the partition table
528 op.add_option("--no-table", dest="no_table", action="store_true",
529 default=False)
524 return op 530 return op
diff --git a/scripts/lib/wic/utils/partitionedfs.py b/scripts/lib/wic/utils/partitionedfs.py
index c72bb29b02..87d2929f6c 100644
--- a/scripts/lib/wic/utils/partitionedfs.py
+++ b/scripts/lib/wic/utils/partitionedfs.py
@@ -61,6 +61,7 @@ class Image:
61 self.disks[disk_name] = \ 61 self.disks[disk_name] = \
62 { 'disk': None, # Disk object 62 { 'disk': None, # Disk object
63 'numpart': 0, # Number of allocate partitions 63 'numpart': 0, # Number of allocate partitions
64 'realpart': 0, # Number of partitions in the partition table
64 'partitions': [], # Indexes to self.partitions 65 'partitions': [], # Indexes to self.partitions
65 'offset': 0, # Offset of next partition (in sectors) 66 'offset': 0, # Offset of next partition (in sectors)
66 # Minimum required disk size to fit all partitions (in bytes) 67 # Minimum required disk size to fit all partitions (in bytes)
@@ -85,7 +86,7 @@ class Image:
85 self.__add_disk(part['disk_name']) 86 self.__add_disk(part['disk_name'])
86 87
87 def add_partition(self, size, disk_name, mountpoint, source_file = None, fstype = None, 88 def add_partition(self, size, disk_name, mountpoint, source_file = None, fstype = None,
88 label=None, fsopts = None, boot = False, align = None, 89 label=None, fsopts = None, boot = False, align = None, no_table=False,
89 part_type = None): 90 part_type = None):
90 """ Add the next partition. Prtitions have to be added in the 91 """ Add the next partition. Prtitions have to be added in the
91 first-to-last order. """ 92 first-to-last order. """
@@ -109,6 +110,7 @@ class Image:
109 'num': None, # Partition number 110 'num': None, # Partition number
110 'boot': boot, # Bootable flag 111 'boot': boot, # Bootable flag
111 'align': align, # Partition alignment 112 'align': align, # Partition alignment
113 'no_table' : no_table, # Partition does not appear in partition table
112 'part_type' : part_type } # Partition type 114 'part_type' : part_type } # Partition type
113 115
114 self.__add_partition(part) 116 self.__add_partition(part)
@@ -147,6 +149,8 @@ class Image:
147 # Get the disk where the partition is located 149 # Get the disk where the partition is located
148 d = self.disks[p['disk_name']] 150 d = self.disks[p['disk_name']]
149 d['numpart'] += 1 151 d['numpart'] += 1
152 if not p['no_table']:
153 d['realpart'] += 1
150 d['ptable_format'] = ptable_format 154 d['ptable_format'] = ptable_format
151 155
152 if d['numpart'] == 1: 156 if d['numpart'] == 1:
@@ -156,7 +160,7 @@ class Image:
156 # Skip one sector required for the partitioning scheme overhead 160 # Skip one sector required for the partitioning scheme overhead
157 d['offset'] += overhead 161 d['offset'] += overhead
158 162
159 elif d['numpart'] > 3: 163 if d['realpart'] > 3:
160 # Reserve a sector for EBR for every logical partition 164 # Reserve a sector for EBR for every logical partition
161 # before alignment is performed. 165 # before alignment is performed.
162 if ptable_format == "msdos": 166 if ptable_format == "msdos":
@@ -189,12 +193,15 @@ class Image:
189 d['offset'] += p['size'] 193 d['offset'] += p['size']
190 194
191 p['type'] = 'primary' 195 p['type'] = 'primary'
192 p['num'] = d['numpart'] 196 if not p['no_table']:
197 p['num'] = d['realpart']
198 else:
199 p['num'] = 0
193 200
194 if d['ptable_format'] == "msdos": 201 if d['ptable_format'] == "msdos":
195 if d['numpart'] > 3: 202 if d['realpart'] > 3:
196 p['type'] = 'logical' 203 p['type'] = 'logical'
197 p['num'] = d['numpart'] + 1 204 p['num'] = d['realpart'] + 1
198 205
199 d['partitions'].append(n) 206 d['partitions'].append(n)
200 msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " 207 msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d "
@@ -256,6 +263,9 @@ class Image:
256 msger.debug("Creating partitions") 263 msger.debug("Creating partitions")
257 264
258 for p in self.partitions: 265 for p in self.partitions:
266 if p['num'] == 0:
267 continue
268
259 d = self.disks[p['disk_name']] 269 d = self.disks[p['disk_name']]
260 if d['ptable_format'] == "msdos" and p['num'] == 5: 270 if d['ptable_format'] == "msdos" and p['num'] == 5:
261 # Create an extended partition (note: extended 271 # Create an extended partition (note: extended