raw: fix image size with --align
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 4 Jan 2013 11:41:15 +0000 (13:41 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 10 Jan 2013 12:13:17 +0000 (14:13 +0200)
Finally, with the preparation patches we did, we can fix the --align problem
and fix bug #624.

The issue is: with --align the image size becomes too large and there are
unused blocks at the end.

Now we can use correct image size calculated by partitionedfs.py.

Change-Id: I59e19281934b9557cdb960a7228d81f463f37786
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
mic/imager/raw.py

index b3e9256c439dd47d53112da512cd98a5295878f3..9ce21d5089ed59d590720b254715d8659542c097 100644 (file)
@@ -193,21 +193,8 @@ class RawImageCreator(BaseImageCreator):
     # Actual implemention
     #
     def _mount_instroot(self, base_on = None):
-        self.__imgdir = self._mkdtemp()
-
         parts = self._get_parts()
-
-        #create disk
-        for item in self.get_diskinfo():
-            full_path = self._full_path(self.__imgdir, item['name'], "raw")
-            msger.debug("Adding disk %s as %s with size %s bytes" \
-                        % (item['name'], full_path, item['size']))
-
-            disk = fs_related.SparseLoopbackDisk(full_path, item['size'])
-            self.__disks[item['name']] = disk
-
         self.__instloop = PartitionedMount(self._instroot)
-        self.__instloop.add_disks(self.__disks)
 
         for p in parts:
             self.__instloop.add_partition(int(p.size),
@@ -219,6 +206,21 @@ class RawImageCreator(BaseImageCreator):
                                           boot = p.active,
                                           align = p.align)
 
+        self.__instloop.layout_partitions()
+
+        # Create the disks
+        self.__imgdir = self._mkdtemp()
+        for disk_name, disk in self.__instloop.disks.items():
+            full_path = self._full_path(self.__imgdir, disk_name, "raw")
+            msger.debug("Adding disk %s as %s with size %s bytes" \
+                        % (disk_name, full_path, disk['min_size']))
+
+            disk_obj = fs_related.SparseLoopbackDisk(full_path,
+                                                     disk['min_size'])
+            self.__disks[disk_name] = disk_obj
+
+        self.__instloop.add_disks(self.__disks)
+
         self.__instloop.mount()
         self._create_mkinitrd_config()