[Libguestfs] [PATCH v2 08/11] resize: parted and copy logical partitions

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed May 20 10:51:34 UTC 2015


Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 resize/resize.ml | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/resize/resize.ml b/resize/resize.ml
index 89bcb30..db7e0b3 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -1210,6 +1210,11 @@ read the man page virt-resize(1).
       g#part_add "/dev/sdb" (mbr_part_type p) p.p_target_start p.p_target_end
   ) partitions;
 
+  List.iter (
+    fun p ->
+      g#part_add "/dev/sdb" "logical" p.p_target_start p.p_target_end
+  ) logical_partitions;
+
   (* Copy over the data. *)
   let copy_partition p =
       match p.p_operation with
@@ -1234,24 +1239,12 @@ read the man page virt-resize(1).
          | ContentUnknown | ContentPV _ | ContentFS _ ->
            g#copy_device_to_device ~size:copysize ~sparse source target
 
-         | ContentExtendedPartition ->
-           (* You can't just copy an extended partition by name, eg.
-            * source = "/dev/sda2", because the device name only covers
-            * the first 1K of the partition.  Instead, copy the
-            * source bytes from the parent disk (/dev/sda).
-            *
-            * You can't write directly to the extended partition,
-            * because the size of it reported by Linux is always 1024
-            * bytes. Instead, write to the offset of the extended
-            * partition in the destination disk (/dev/sdb).
-            *)
-           let srcoffset = p.p_part.G.part_start in
-           let destoffset = p.p_target_start *^ 512L in
-           g#copy_device_to_device ~srcoffset ~destoffset ~size:copysize "/dev/sda" "/dev/sdb"
+         | ContentExtendedPartition -> ()
         )
       | OpIgnore | OpDelete -> ()
   in
   List.iter copy_partition partitions;
+  List.iter copy_partition logical_partitions;
 
   (* Set bootable and MBR IDs.  Do this *after* copying over the data,
    * so that we can magically change the primary partition to an extended
-- 
2.1.0




More information about the Libguestfs mailing list