<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>12840</bug_id>
          
          <creation_ts>2018-07-02 16:01:22 +0000</creation_ts>
          <short_desc>wic write --expand auto fails</short_desc>
          <delta_ts>2018-07-18 10:43:15 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>Scripts and Tools</component>
          <version>2.5.1</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.6</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ross Burton">ross.burton</reporter>
          <assigned_to name="Anuj Mittal">anuj.mittal</assigned_to>
          <cc>anuj.mittal</cc>
    
    <cc>ross.burton</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>80996</commentid>
    <comment_count>0</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2018-07-02 16:01:22 +0000</bug_when>
    <thetext>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&quot;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&gt;&gt;&gt; Script header accepted.\n&gt;&gt;&gt; Script header accepted.\n&gt;&gt;&gt; Script header accepted.\n&gt;&gt;&gt; Created a new GPT disklabel (GUID: 07104E7E-E7BC-4F60-886A-4F1E6EA39AE9).\n/dev/sdc1: Created a new partition 1 of type &apos;Microsoft basic data&apos; and of size 6.6 GiB.\n/dev/sdc2: Created a new partition 2 of type &apos;Linux filesystem&apos; and of size 16.7 GiB.\n/dev/sdc3: Leaving.\n\n&quot;

ERROR: Can&apos;t run &apos;/sbin/sfdisk --no-reread /dev/sdc &lt; /tmp/wic-sfdisk-b8u7ffpl&apos; command: Command &apos;/sbin/sfdisk --no-reread /dev/sdc &lt; /tmp/wic-sfdisk-b8u7ffpl&apos; returned non-zero exit status 1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81071</commentid>
    <comment_count>1</comment_count>
    <who name="Anuj Mittal">anuj.mittal</who>
    <bug_when>2018-07-11 10:44:46 +0000</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81133</commentid>
    <comment_count>2</comment_count>
    <who name="Anuj Mittal">anuj.mittal</who>
    <bug_when>2018-07-18 10:43:15 +0000</bug_when>
    <thetext>Merged: https://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=82756dcac05f7494805c339bb7ffe193afe536db</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>