[oe-commits] Maciej Borzecki : wic: fix extended/logical partition layout

git at git.openembedded.org git at git.openembedded.org
Sun Feb 8 08:00:46 UTC 2015


Module: openembedded-core.git
Branch: master
Commit: a8b85f7878726503dbfa2e9ea86bd6fd961bf03b
URL:    http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=a8b85f7878726503dbfa2e9ea86bd6fd961bf03b

Author: Maciej Borzecki <maciej.borzecki at open-rnd.pl>
Date:   Fri Jan  9 14:24:02 2015 +0100

wic: fix extended/logical partition layout

The patch fixes an issue in laying out extended and logical partitions
by wic. The original code produced disk images in which the size 3rd
partition as described in MBR was incorrect. Depending on the type of
file system used for that partition and size of the partition, it would
be impossible to mount the partition correctly. For instance, kickstart
file in which the 3rd partition had size of 1GB and used ext4 fs, would
result in an image with an umountable partition. The root cause is
reservation of sectors for EBR through stealing of last sector from the
last primary partition.

Signed-off-by: Maciej Borzecki <maciej.borzecki at open-rnd.pl>
Signed-off-by: Maciek Borzecki <maciek.borzecki at gmail.com>
Signed-off-by: Ross Burton <ross.burton at intel.com>

---

 scripts/lib/wic/utils/partitionedfs.py | 40 ++++++++++++++++------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/scripts/lib/wic/utils/partitionedfs.py b/scripts/lib/wic/utils/partitionedfs.py
index fb95cc7..9df93dc 100644
--- a/scripts/lib/wic/utils/partitionedfs.py
+++ b/scripts/lib/wic/utils/partitionedfs.py
@@ -156,6 +156,13 @@ class Image:
                 # Skip one sector required for the partitioning scheme overhead
                 d['offset'] += overhead
 
+            elif d['numpart'] > 3:
+                # Reserve a sector for EBR for every logical partition
+                # before alignment is performed.
+                if ptable_format == "msdos":
+                    d['offset'] += 1
+
+
             if p['align']:
                 # If not first partition and we do have alignment set we need
                 # to align the partition.
@@ -185,14 +192,6 @@ class Image:
             p['num'] = d['numpart']
 
             if d['ptable_format'] == "msdos":
-                if d['numpart'] > 2:
-                    # Every logical partition requires an additional sector for
-                    # the EBR, so steal the last sector from the end of each
-                    # partition starting from the 3rd one for the EBR. This
-                    # will make sure the logical partitions are aligned
-                    # correctly.
-                    p['size'] -= 1
-
                 if d['numpart'] > 3:
                     p['type'] = 'logical'
                     p['num'] = d['numpart'] + 1
@@ -259,13 +258,20 @@ class Image:
         for p in self.partitions:
             d = self.disks[p['disk_name']]
             if d['ptable_format'] == "msdos" and p['num'] == 5:
-                # The last sector of the 3rd partition was reserved for the EBR
-                # of the first _logical_ partition. This is why the extended
-                # partition should start one sector before the first logical
-                # partition.
+                # Create an extended partition (note: extended
+                # partition is described in MBR and contains all
+                # logical partitions). The logical partitions save a
+                # sector for an EBR just before the start of a
+                # partition. The extended partition must start one
+                # sector before the start of the first logical
+                # partition. This way the first EBR is inside of the
+                # extended partition. Since the extended partitions
+                # starts a sector before the first logical partition,
+                # add a sector at the back, so that there is enough
+                # room for all logical partitions.
                 self.__create_partition(d['disk'].device, "extended",
                                         None, p['start'] - 1,
-                                        d['offset'] - p['start'])
+                                        d['offset'] - p['start'] + 1)
 
             if p['fstype'] == "swap":
                 parted_fs_type = "linux-swap"
@@ -338,14 +344,6 @@ class Image:
 
         for p in self.partitions:
             d = self.disks[p['disk_name']]
-            if d['ptable_format'] == "msdos" and p['num'] == 5:
-                # The last sector of the 3rd partition was reserved for the EBR
-                # of the first _logical_ partition. This is why the extended
-                # partition should start one sector before the first logical
-                # partition.
-                self.__write_partition(p['num'], p['source_file'],
-                                       p['start'] - 1,
-                                       d['offset'] - p['start'])
 
             self.__write_partition(p['num'], p['source_file'],
                                    p['start'], p['size'])



More information about the Openembedded-commits mailing list