Bug 12840 - wic write --expand auto fails
Summary: wic write --expand auto fails
Status: RESOLVED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: Scripts and Tools (show other bugs)
Version: 2.5.1
Hardware: x86 Multiple
: Medium normal
Target Milestone: 2.6
Assignee: Anuj Mittal
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2018-07-02 16:01 UTC by Ross Burton
Modified: 2018-07-18 10:43 UTC (History)
2 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Burton 2018-07-02 16:01:22 UTC
Trying to use wic write --expand=auto is failing.  By making wic print the output of sfdisk we can see why:

$ sudo ../scripts/wic write -e auto /data/poky-tmp/pristine/deploy/images/intel-corei7-64/kpi-image-intel-corei7-64.wic  /dev/sdc
GPT PMBR size mismatch (21448585 != 62533295) will be corrected by w(rite).
Partition #1 contains a vfat signature.
Partition #2 contains a ext4 signature.
Partition #1 contains a vfat signature.
The last usable GPT sector is 62533262, but 62533508 is requested.
Failed to add #3 partition: Invalid argument
b"Disk /dev/sdc: 29.8 GiB, 32017047552 bytes, 62533296 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisklabel type: gpt\nDisk identifier: 07104E7E-E7BC-4F60-886A-4F1E6EA39AE9\n\nOld situation:\n\nDevice        Start      End  Sectors  Size Type\n/dev/sdc1      2048    52993    50946 24.9M Microsoft basic data\n/dev/sdc2     53248 21358439 21305192 10.2G Linux filesystem\n/dev/sdc3  21358592 21448703    90112   44M Linux swap\n\n>>> Script header accepted.\n>>> Script header accepted.\n>>> Script header accepted.\n>>> Created a new GPT disklabel (GUID: 07104E7E-E7BC-4F60-886A-4F1E6EA39AE9).\n/dev/sdc1: Created a new partition 1 of type 'Microsoft basic data' and of size 6.6 GiB.\n/dev/sdc2: Created a new partition 2 of type 'Linux filesystem' and of size 16.7 GiB.\n/dev/sdc3: Leaving.\n\n"

ERROR: Can't run '/sbin/sfdisk --no-reread /dev/sdc < /tmp/wic-sfdisk-b8u7ffpl' command: Command '/sbin/sfdisk --no-reread /dev/sdc < /tmp/wic-sfdisk-b8u7ffpl' returned non-zero exit status 1
Comment 1 Anuj Mittal 2018-07-11 10:44:46 UTC
I took a look at this. According to the spec, the partitions should be assumed to be on a 2048 sector boundary (for a 512 byte sector) and the current logic just divides the free sectors available by the number of partitions that need re-sizing ... which may or may not align and might overshoot the limit as is happening in this case. 

Since we are just expanding the partitions that are already aligned, I guess it should be okay if we just divide up the free space in multiples of 2048. I tested it and this works. Will test some more and send patch later.

From the UEFI spec [1] :

To avoid the need to determine the physical 
block size and the optimal transfer length 
granularity, software may align GPT partitions at significantly larger boundaries. For 
example, assuming logical block 0 is aligned, 
it may use LBAs that are multiples of 2,048 
to align to 1,048,576 byte (1 MiB) boundaries, which supports most common physical 
block sizes and RAID stripe sizes

[1] http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf