From c631f3e4ecfa1640cd761774ade02cca57a906fc Mon Sep 17 00:00:00 2001
From: Nikos Skalkotos <skalkoto@grnet.gr>
Date: Tue, 29 Jan 2013 16:33:05 +0000
Subject: [PATCH] In bundle_volume keep partition starting points

When shrinking partitions, make sure that the shrinked partitions
always starts from the sector the initial partition started. Changing
this may destroy the boot loader.
---
 image_creator/bundle_volume.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/image_creator/bundle_volume.py b/image_creator/bundle_volume.py
index ff6ed3e..189e107 100644
--- a/image_creator/bundle_volume.py
+++ b/image_creator/bundle_volume.py
@@ -222,9 +222,13 @@ class BundleVolume(object):
             # Align to 2048
             part_end = ((part_end + 2047) // 2048) * 2048
 
+            # Make sure the partition starts where the old partition started.
+            constraint = parted.Constraint(device=image_disk.device)
+            constraint.startRange = parted.Geometry(device=image_disk.device,
+                                                    start=last.start, length=1)
+
             image_disk.setPartitionGeometry(
-                image_disk.getPartitionBySector(last.start),
-                parted.Constraint(device=image_disk.device),
+                image_disk.getPartitionBySector(last.start), constraint,
                 start=last.start, end=part_end)
             image_disk.commitToDevice()
 
-- 
GitLab