<?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>13658</bug_id>
          
          <creation_ts>2019-11-26 07:43:09 +0000</creation_ts>
          <short_desc>Unable to resize extended partition in image created with wic</short_desc>
          <delta_ts>2020-04-02 06:16:33 +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>unspecified</version>
          <rep_platform>All</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>critical</bug_severity>
          <target_milestone>3.1 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Preeti Sachan">preetischn</reporter>
          <assigned_to name="Chee Yang">chee.yang.lee</assigned_to>
          <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>ross.burton</cc>
    
    <cc>tim.orling</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>85635</commentid>
    <comment_count>0</comment_count>
    <who name="Preeti Sachan">preetischn</who>
    <bug_when>2019-11-26 07:43:09 +0000</bug_when>
    <thetext>I have created wic image having extended partitions with below *.wks file content.

wks file:

part /mnt/boot --ondisk mmcblk0 --label edgeos-boot --active --fixed-size=100M --fstype=vfat --align 4096 --source bootimg-partition
part /mnt/krn1 --ondisk mmcblk0 --label edgeos-krn1 --fstype=vfat --align 4096 --fixed-size=64M --source rawcopy --sourceparams=&quot;file=kernel.vfat&quot;
part /mnt/krn2 --ondisk mmcblk0 --label edgeos-krn2 --fstype=vfat --align 4096 --fixed-size=64M
part /mnt/rootfs-container --ondisk mmcblk0 --label edgeos-cntnr --fstype=ext3 --align 4096 --fixed-size=512M --source rootfs --rootfs-dir=rootfs-image-dir
part /mnt/conf --ondisk mmcblk0 --label edgeos-conf --fstype=ext3 --align 4096 --fixed-size=16M
part /mnt/data --ondisk mmcblk0 --label edgeos-data --fstype=ext3 --align 4096 --fixed-size=512M

fdisk output:

# fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14.9 GiB, 15987638272 bytes, 31225856 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6f201fb9

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *       8192   212991   204800  100M  c W95 FAT32 (LBA)
/dev/mmcblk0p2       212992   344063   131072   64M  c W95 FAT32 (LBA)
/dev/mmcblk0p3       344064   475135   131072   64M  c W95 FAT32 (LBA)
/dev/mmcblk0p4       483327  2629631  2146305    1G  f W95 Ext&apos;d (LBA)
/dev/mmcblk0p5       483328  1531903  1048576  512M 83 Linux
/dev/mmcblk0p6      1540096  1572863    32768   16M 83 Linux
/dev/mmcblk0p7      1581056  2629631  1048576  512M 83 Linux


When performing resizing of extended partition using &apos;parted&apos; tool after booting wic image (or at boot time via systemd service file), it is giving error &quot;Unable to satisfy all constraints on the partition.&quot;

command:  &quot;parted /dev/mmcblk0 resizepart 4 -1s&quot;


This error &quot;Unable to satisfy all constraints on the partition.&quot; is coming due to invalid created msdos partition table via wic. There are the basic partition rules for msdos partition table and need to be followed while creating wic image for extended partition. Refer link https://gparted.org/h2-fix-msdos-pt.php.

According to rule, atleast 2 unallocated sectors are required in front of a logical partition. This space is required for the Extended Boot Record (EBR).

But the generated wic image having only one sector gap between extended partition (start: 483327) and 1st logical partition (start: 483328).

There is bug in imager file direct.py. (https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/imager/direct.py?h=master) at line 406, 449 and 514.

line 403-406:
                # Reserve a sector for EBR for every logical partition
                # before alignment is performed.
                if part.type == &apos;logical&apos;:
                    self.offset += 1

line 449:
                  self.extended_size_sec += part.size_sec + 1

line 514-516:

self._create_partition(self.path, &quot;extended&quot;,
                                       None, part.start - 1,
                                       self.extended_size_sec)

In above mentioned line, it is keeping 1 sector gap between extended partition and 1st logical partition instead of keeping minimum 2 sector gap. Please look into this issue.


Thanks and Regards
Preeti Sachan</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85728</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2019-12-05 15:48:52 +0000</bug_when>
    <thetext>Is this simply a case of changing the += 1 to +=2 ? Could someone send a patch please if so?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85754</commentid>
    <comment_count>2</comment_count>
      <attachid>4594</attachid>
    <who name="Preeti Sachan">preetischn</who>
    <bug_when>2019-12-06 08:42:41 +0000</bug_when>
    <thetext>Created attachment 4594
patch file applicable to poky, sumo and thud branch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85755</commentid>
    <comment_count>3</comment_count>
    <who name="Preeti Sachan">preetischn</who>
    <bug_when>2019-12-06 08:46:09 +0000</bug_when>
    <thetext>I have tested on poky sumo and thud branch and having patch for same.
This patch file is applicable to poky sumo and thud branch.

$ cat fix-parted-unable-to-satisfy-all-constraints.patch
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 1fa6b91..57f6f4a 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -416,7 +416,7 @@ class PartitionedImage():
                 # Reserve a sector for EBR for every logical partition
                 # before alignment is performed.
                 if self.ptable_format == &quot;msdos&quot;:
-                    self.offset += 1
+                    self.offset += 2

             if part.align:
                 # If not first partition and we do have alignment set we need
@@ -517,8 +517,8 @@ class PartitionedImage():
                 # add a sector at the back, so that there is enough
                 # room for all logical partitions.
                 self._create_partition(self.path, &quot;extended&quot;,
-                                       None, part.start - 1,
-                                       self.offset - part.start + 1)
+                                       None, part.start - 2,
+                                       self.offset - part.start + 2)

             if part.fstype == &quot;swap&quot;:
                 parted_fs_type = &quot;linux-swap&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86809</commentid>
    <comment_count>4</comment_count>
    <who name="Chee Yang">chee.yang.lee</who>
    <bug_when>2020-03-25 05:00:21 +0000</bug_when>
    <thetext>this should work for master branch
https://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=590555e3b8ccbd94b628aa6778adea7f4538d966</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>4594</attachid>
            <date>2019-12-06 08:42:41 +0000</date>
            <delta_ts>2019-12-06 08:42:41 +0000</delta_ts>
            <desc>patch file applicable to poky, sumo and thud branch</desc>
            <filename>fix-parted-unable-to-satisfy-all-constraints.patch</filename>
            <type>text/plain</type>
            <size>1207</size>
            <attacher name="Preeti Sachan">preetischn</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL3NjcmlwdHMvbGliL3dpYy9wbHVnaW5zL2ltYWdlci9kaXJlY3QucHkgYi9z
Y3JpcHRzL2xpYi93aWMvcGx1Z2lucy9pbWFnZXIvZGlyZWN0LnB5CmluZGV4IDFmYTZiOTEuLjU3
ZjZmNGEgMTAwNjQ0Ci0tLSBhL3NjcmlwdHMvbGliL3dpYy9wbHVnaW5zL2ltYWdlci9kaXJlY3Qu
cHkKKysrIGIvc2NyaXB0cy9saWIvd2ljL3BsdWdpbnMvaW1hZ2VyL2RpcmVjdC5weQpAQCAtNDE2
LDcgKzQxNiw3IEBAIGNsYXNzIFBhcnRpdGlvbmVkSW1hZ2UoKToKICAgICAgICAgICAgICAgICAj
IFJlc2VydmUgYSBzZWN0b3IgZm9yIEVCUiBmb3IgZXZlcnkgbG9naWNhbCBwYXJ0aXRpb24KICAg
ICAgICAgICAgICAgICAjIGJlZm9yZSBhbGlnbm1lbnQgaXMgcGVyZm9ybWVkLgogICAgICAgICAg
ICAgICAgIGlmIHNlbGYucHRhYmxlX2Zvcm1hdCA9PSAibXNkb3MiOgotICAgICAgICAgICAgICAg
ICAgICBzZWxmLm9mZnNldCArPSAxCisgICAgICAgICAgICAgICAgICAgIHNlbGYub2Zmc2V0ICs9
IDIKIAogICAgICAgICAgICAgaWYgcGFydC5hbGlnbjoKICAgICAgICAgICAgICAgICAjIElmIG5v
dCBmaXJzdCBwYXJ0aXRpb24gYW5kIHdlIGRvIGhhdmUgYWxpZ25tZW50IHNldCB3ZSBuZWVkCkBA
IC01MTcsOCArNTE3LDggQEAgY2xhc3MgUGFydGl0aW9uZWRJbWFnZSgpOgogICAgICAgICAgICAg
ICAgICMgYWRkIGEgc2VjdG9yIGF0IHRoZSBiYWNrLCBzbyB0aGF0IHRoZXJlIGlzIGVub3VnaAog
ICAgICAgICAgICAgICAgICMgcm9vbSBmb3IgYWxsIGxvZ2ljYWwgcGFydGl0aW9ucy4KICAgICAg
ICAgICAgICAgICBzZWxmLl9jcmVhdGVfcGFydGl0aW9uKHNlbGYucGF0aCwgImV4dGVuZGVkIiwK
LSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIE5vbmUsIHBhcnQuc3RhcnQg
LSAxLAotICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5vZmZzZXQg
LSBwYXJ0LnN0YXJ0ICsgMSkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
IE5vbmUsIHBhcnQuc3RhcnQgLSAyLAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgc2VsZi5vZmZzZXQgLSBwYXJ0LnN0YXJ0ICsgMikKIAogICAgICAgICAgICAgaWYgcGFy
dC5mc3R5cGUgPT0gInN3YXAiOgogICAgICAgICAgICAgICAgIHBhcnRlZF9mc190eXBlID0gImxp
bnV4LXN3YXAiCg==
</data>

          </attachment>
      

    </bug>

</bugzilla>