diff options
Diffstat (limited to 'scripts/lib/wic/plugins/imager/direct.py')
| -rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index d0a1cad43b..ffe6c8406d 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
| @@ -74,6 +74,19 @@ class DirectPlugin(ImagerPlugin): | |||
| 74 | self.ptable_format = self.ks.bootloader.ptable | 74 | self.ptable_format = self.ks.bootloader.ptable |
| 75 | self.parts = self.ks.partitions | 75 | self.parts = self.ks.partitions |
| 76 | 76 | ||
| 77 | # calculate the real partition number, accounting for partitions not | ||
| 78 | # in the partition table and logical partitions | ||
| 79 | realnum = 0 | ||
| 80 | for part in self.parts: | ||
| 81 | if part.no_table: | ||
| 82 | part.realnum = 0 | ||
| 83 | else: | ||
| 84 | realnum += 1 | ||
| 85 | if self.ptable_format == 'msdos' and realnum > 3: | ||
| 86 | part.realnum = realnum + 1 | ||
| 87 | continue | ||
| 88 | part.realnum = realnum | ||
| 89 | |||
| 77 | def do_create(self): | 90 | def do_create(self): |
| 78 | """ | 91 | """ |
| 79 | Plugin entry point. | 92 | Plugin entry point. |
| @@ -86,22 +99,6 @@ class DirectPlugin(ImagerPlugin): | |||
| 86 | finally: | 99 | finally: |
| 87 | self.cleanup() | 100 | self.cleanup() |
| 88 | 101 | ||
| 89 | def _get_part_num(self, num, parts): | ||
| 90 | """calculate the real partition number, accounting for partitions not | ||
| 91 | in the partition table and logical partitions | ||
| 92 | """ | ||
| 93 | realnum = 0 | ||
| 94 | for pnum, part in enumerate(parts, 1): | ||
| 95 | if not part.no_table: | ||
| 96 | realnum += 1 | ||
| 97 | if pnum == num: | ||
| 98 | if part.no_table: | ||
| 99 | return 0 | ||
| 100 | if self.ptable_format == 'msdos' and realnum > 3: | ||
| 101 | # account for logical partition numbering, ex. sda5.. | ||
| 102 | return realnum + 1 | ||
| 103 | return realnum | ||
| 104 | |||
| 105 | def _write_fstab(self, image_rootfs): | 102 | def _write_fstab(self, image_rootfs): |
| 106 | """overriden to generate fstab (temporarily) in rootfs. This is called | 103 | """overriden to generate fstab (temporarily) in rootfs. This is called |
| 107 | from _create, make sure it doesn't get called from | 104 | from _create, make sure it doesn't get called from |
| @@ -128,15 +125,14 @@ class DirectPlugin(ImagerPlugin): | |||
| 128 | def _update_fstab(self, fstab_lines, parts): | 125 | def _update_fstab(self, fstab_lines, parts): |
| 129 | """Assume partition order same as in wks""" | 126 | """Assume partition order same as in wks""" |
| 130 | updated = False | 127 | updated = False |
| 131 | for num, part in enumerate(parts, 1): | 128 | for part in parts: |
| 132 | pnum = self._get_part_num(num, parts) | 129 | if not part.realnum or not part.mountpoint \ |
| 133 | if not pnum or not part.mountpoint \ | ||
| 134 | or part.mountpoint in ("/", "/boot"): | 130 | or part.mountpoint in ("/", "/boot"): |
| 135 | continue | 131 | continue |
| 136 | 132 | ||
| 137 | # mmc device partitions are named mmcblk0p1, mmcblk0p2.. | 133 | # mmc device partitions are named mmcblk0p1, mmcblk0p2.. |
| 138 | prefix = 'p' if part.disk.startswith('mmcblk') else '' | 134 | prefix = 'p' if part.disk.startswith('mmcblk') else '' |
| 139 | device_name = "/dev/%s%s%d" % (part.disk, prefix, pnum) | 135 | device_name = "/dev/%s%s%d" % (part.disk, prefix, part.realnum) |
| 140 | 136 | ||
| 141 | opts = part.fsopts if part.fsopts else "defaults" | 137 | opts = part.fsopts if part.fsopts else "defaults" |
| 142 | line = "\t".join([device_name, part.mountpoint, part.fstype, | 138 | line = "\t".join([device_name, part.mountpoint, part.fstype, |
| @@ -164,7 +160,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 164 | self._image = PartitionedImage(image_path, self.ptable_format, | 160 | self._image = PartitionedImage(image_path, self.ptable_format, |
| 165 | self.native_sysroot) | 161 | self.native_sysroot) |
| 166 | 162 | ||
| 167 | for num, part in enumerate(self.parts, 1): | 163 | for part in self.parts: |
| 168 | # as a convenience, set source to the boot partition source | 164 | # as a convenience, set source to the boot partition source |
| 169 | # instead of forcing it to be set via bootloader --source | 165 | # instead of forcing it to be set via bootloader --source |
| 170 | if not self.ks.bootloader.source and part.mountpoint == "/boot": | 166 | if not self.ks.bootloader.source and part.mountpoint == "/boot": |
| @@ -175,8 +171,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 175 | if self.ptable_format == 'gpt': | 171 | if self.ptable_format == 'gpt': |
| 176 | part.uuid = str(uuid.uuid4()) | 172 | part.uuid = str(uuid.uuid4()) |
| 177 | else: # msdos partition table | 173 | else: # msdos partition table |
| 178 | part.uuid = '%0x-%02d' % (self._image.identifier, | 174 | part.uuid = '%0x-%02d' % (self._image.identifier, part.realnum) |
| 179 | self._get_part_num(num, self.parts)) | ||
| 180 | 175 | ||
| 181 | fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) | 176 | fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) |
| 182 | 177 | ||
| @@ -277,14 +272,13 @@ class DirectPlugin(ImagerPlugin): | |||
| 277 | 272 | ||
| 278 | Assume partition order same as in wks | 273 | Assume partition order same as in wks |
| 279 | """ | 274 | """ |
| 280 | for num, part in enumerate(self.parts, 1): | 275 | for part in self.parts: |
| 281 | if part.mountpoint == "/": | 276 | if part.mountpoint == "/": |
| 282 | if part.uuid: | 277 | if part.uuid: |
| 283 | return "PARTUUID=%s" % part.uuid | 278 | return "PARTUUID=%s" % part.uuid |
| 284 | else: | 279 | else: |
| 285 | suffix = 'p' if part.disk.startswith('mmcblk') else '' | 280 | suffix = 'p' if part.disk.startswith('mmcblk') else '' |
| 286 | pnum = self._get_part_num(num, self.parts) | 281 | return "/dev/%s%s%-d" % (part.disk, suffix, part.realnum) |
| 287 | return "/dev/%s%s%-d" % (part.disk, suffix, pnum) | ||
| 288 | 282 | ||
| 289 | def cleanup(self): | 283 | def cleanup(self): |
| 290 | if self._image: | 284 | if self._image: |
