diff options
author | Jason Wessel <jason.wessel@windriver.com> | 2019-08-08 13:23:58 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-08-12 16:23:57 +0100 |
commit | 351a10ccd6f197ff105b207ea25d936c3e12044d (patch) | |
tree | 3a73d5356848248afc52523fe2b4748a74a0e2c9 /scripts/lib/wic | |
parent | b209d4117d3bf016c9681aa2312259ce3b572cbf (diff) | |
download | poky-351a10ccd6f197ff105b207ea25d936c3e12044d.tar.gz |
wic: Add partition type for msdos partition tables
In order to create a msdos partition table disk image that can auto
expand after the image is copied to an SD card, wic needs the ability
to have a primary partition as the last entry. The desired use case
is to be able to create an A/B update partition image scheme with a
/var volume that can be auto expanded to the remainder of the SD card
at run time.
The typical .wks file will look similar to the following:
bootloader --ptable msdos
part / --source rawcopy --sourceparams="file=u-boot.imx" \
--ondisk mmcblk --no-table --align 1 --size 1
part /boot --source bootimg-partition \
--ondisk mmcblk --fstype=vfat --label boot --active --align 4 --size 16
part / --source rawcopy --sourceparams="file=imx6_boot.otaimg" \
--ondisk mmcblk --fstype=ext4 --label otaboot --align 4 --type logical
part / --source rawcopy --sourceparams="file=imx6.otaimg" \
--ondisk mmcblk --fstype=ext4 --label otaroot --align 4 --type logical
part / --source rawcopy --sourceparams="file=imx6_boot.otaimg" \
--ondisk mmcblk --fstype=ext4 --label otaboot_b --align 4 --type logical
part / --source rawcopy --sourceparams="file=imx6.otaimg" \
--ondisk mmcblk --fstype=ext4 --label otaroot_b --align 4 --type logical
part /var --source rawcopy --sourceparams="file=imx6_var.otaimg" \
--ondisk mmcblk --fstype=ext4 --label fluxdata --align 4
Without the patch applied, wic will generate an SD card image that looks like:
Disk boot.img: 890940s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 2056s 48001s 45946s primary fat16 lba
2 48008s 132467s 84460s primary ext4
3 132472s 454467s 321996s primary ext4
4 454471s 890939s 436469s extended lba
5 454472s 538931s 84460s logical ext4
6 538936s 860931s 321996s logical ext4
7 860936s 890939s 30004s logical ext4 boot
With the patch applied a primary partition can be created at the end
of the image which can be expanded to fill the free space on the media
where the image has been copied, which looks like:
Disk boot.img: 890940s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 2056s 48001s 45946s primary fat16 lba
2 48007s 860931s 812925s extended lba
5 48008s 132467s 84460s logical ext4
6 132472s 454467s 321996s logical ext4
7 454472s 538931s 84460s logical ext4
8 538936s 860931s 321996s logical ext4
3 860936s 890939s 30004s primary ext4 boot
(From OE-Core rev: 56add7cc547e0113cdf980579d1421b14cc233e5)
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic')
-rw-r--r-- | scripts/lib/wic/ksparser.py | 2 | ||||
-rw-r--r-- | scripts/lib/wic/partition.py | 1 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 37 |
3 files changed, 29 insertions, 11 deletions
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py index 3e670033ba..6a643ba3af 100644 --- a/scripts/lib/wic/ksparser.py +++ b/scripts/lib/wic/ksparser.py | |||
@@ -151,6 +151,8 @@ class KickStart(): | |||
151 | part.add_argument('--part-name') | 151 | part.add_argument('--part-name') |
152 | part.add_argument('--part-type') | 152 | part.add_argument('--part-type') |
153 | part.add_argument('--rootfs-dir') | 153 | part.add_argument('--rootfs-dir') |
154 | part.add_argument('--type', default='primary', | ||
155 | choices = ('primary', 'logical')) | ||
154 | 156 | ||
155 | # --size and --fixed-size cannot be specified together; options | 157 | # --size and --fixed-size cannot be specified together; options |
156 | # ----extra-space and --overhead-factor should also raise a parser | 158 | # ----extra-space and --overhead-factor should also raise a parser |
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index 01466b258d..f427c8101b 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py | |||
@@ -50,6 +50,7 @@ class Partition(): | |||
50 | self.use_uuid = args.use_uuid | 50 | self.use_uuid = args.use_uuid |
51 | self.uuid = args.uuid | 51 | self.uuid = args.uuid |
52 | self.fsuuid = args.fsuuid | 52 | self.fsuuid = args.fsuuid |
53 | self.type = args.type | ||
53 | 54 | ||
54 | self.lineno = lineno | 55 | self.lineno = lineno |
55 | self.source_file = "" | 56 | self.source_file = "" |
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index 91fc5e70f6..3ce6ad55b8 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
@@ -300,6 +300,10 @@ class PartitionedImage(): | |||
300 | self.path = path # Path to the image file | 300 | self.path = path # Path to the image file |
301 | self.numpart = 0 # Number of allocated partitions | 301 | self.numpart = 0 # Number of allocated partitions |
302 | self.realpart = 0 # Number of partitions in the partition table | 302 | self.realpart = 0 # Number of partitions in the partition table |
303 | self.primary_part_num = 0 # Number of primary partitions (msdos) | ||
304 | self.extendedpart = 0 # Create extended partition before this logical partition (msdos) | ||
305 | self.extended_size_sec = 0 # Size of exteded partition (msdos) | ||
306 | self.logical_part_cnt = 0 # Number of total logical paritions (msdos) | ||
303 | self.offset = 0 # Offset of next partition (in sectors) | 307 | self.offset = 0 # Offset of next partition (in sectors) |
304 | self.min_size = 0 # Minimum required disk size to fit | 308 | self.min_size = 0 # Minimum required disk size to fit |
305 | # all partitions (in bytes) | 309 | # all partitions (in bytes) |
@@ -391,12 +395,16 @@ class PartitionedImage(): | |||
391 | # Skip one sector required for the partitioning scheme overhead | 395 | # Skip one sector required for the partitioning scheme overhead |
392 | self.offset += overhead | 396 | self.offset += overhead |
393 | 397 | ||
394 | if self.realpart > 3 and num_real_partitions > 4: | 398 | if self.ptable_format == "msdos": |
399 | if self.primary_part_num > 3 or \ | ||
400 | (self.extendedpart == 0 and self.primary_part_num >= 3 and num_real_partitions > 4): | ||
401 | part.type = 'logical' | ||
395 | # Reserve a sector for EBR for every logical partition | 402 | # Reserve a sector for EBR for every logical partition |
396 | # before alignment is performed. | 403 | # before alignment is performed. |
397 | if self.ptable_format == "msdos": | 404 | if part.type == 'logical': |
398 | self.offset += 1 | 405 | self.offset += 1 |
399 | 406 | ||
407 | align_sectors = 0 | ||
400 | if part.align: | 408 | if part.align: |
401 | # If not first partition and we do have alignment set we need | 409 | # If not first partition and we do have alignment set we need |
402 | # to align the partition. | 410 | # to align the partition. |
@@ -422,18 +430,25 @@ class PartitionedImage(): | |||
422 | part.start = self.offset | 430 | part.start = self.offset |
423 | self.offset += part.size_sec | 431 | self.offset += part.size_sec |
424 | 432 | ||
425 | part.type = 'primary' | ||
426 | if not part.no_table: | 433 | if not part.no_table: |
427 | part.num = self.realpart | 434 | part.num = self.realpart |
428 | else: | 435 | else: |
429 | part.num = 0 | 436 | part.num = 0 |
430 | 437 | ||
431 | if self.ptable_format == "msdos": | 438 | if self.ptable_format == "msdos" and not part.no_table: |
432 | # only count the partitions that are in partition table | 439 | if part.type == 'logical': |
433 | if num_real_partitions > 4: | 440 | self.logical_part_cnt += 1 |
434 | if self.realpart > 3: | 441 | part.num = self.logical_part_cnt + 4 |
435 | part.type = 'logical' | 442 | if self.extendedpart == 0: |
436 | part.num = self.realpart + 1 | 443 | # Create extended partition as a primary partition |
444 | self.primary_part_num += 1 | ||
445 | self.extendedpart = part.num | ||
446 | else: | ||
447 | self.extended_size_sec += align_sectors | ||
448 | self.extended_size_sec += part.size_sec + 1 | ||
449 | else: | ||
450 | self.primary_part_num += 1 | ||
451 | part.num = self.primary_part_num | ||
437 | 452 | ||
438 | logger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " | 453 | logger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " |
439 | "sectors (%d bytes).", part.mountpoint, part.disk, | 454 | "sectors (%d bytes).", part.mountpoint, part.disk, |
@@ -483,7 +498,7 @@ class PartitionedImage(): | |||
483 | if part.num == 0: | 498 | if part.num == 0: |
484 | continue | 499 | continue |
485 | 500 | ||
486 | if self.ptable_format == "msdos" and part.num == 5: | 501 | if self.ptable_format == "msdos" and part.num == self.extendedpart: |
487 | # Create an extended partition (note: extended | 502 | # Create an extended partition (note: extended |
488 | # partition is described in MBR and contains all | 503 | # partition is described in MBR and contains all |
489 | # logical partitions). The logical partitions save a | 504 | # logical partitions). The logical partitions save a |
@@ -497,7 +512,7 @@ class PartitionedImage(): | |||
497 | # room for all logical partitions. | 512 | # room for all logical partitions. |
498 | self._create_partition(self.path, "extended", | 513 | self._create_partition(self.path, "extended", |
499 | None, part.start - 1, | 514 | None, part.start - 1, |
500 | self.offset - part.start + 1) | 515 | self.extended_size_sec) |
501 | 516 | ||
502 | if part.fstype == "swap": | 517 | if part.fstype == "swap": |
503 | parted_fs_type = "linux-swap" | 518 | parted_fs_type = "linux-swap" |