On Mon, Sep 22, 2014 at 03:47:38PM +0800, Hu Tao wrote:
Function mbr_part_type returns one of "primary",
"extended" and
"logical". The type is used by parted when adding partitions.
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
resize/resize.ml | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 8b43306..c56a91a 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -1091,10 +1091,17 @@ read the man page virt-resize(1).
calculate_target_partitions 1 start ~create_surplus:true partitions in
+ (* For GPT, the part type simply becomes partition name, so we don't
+ * handle the case specifically. *)
+ let mbr_part_type x =
+ if x.p_part.G.part_num <= 4l && x.p_type <>
ContentExtendedPartition then "primary"
+ else if x.p_part.G.part_num <= 4l && x.p_type = ContentExtendedPartition
then "extended"
+ else "logical" in
+
(* Now partition the target disk. *)
List.iter (
fun p ->
- g#part_add "/dev/sdb" "primary" p.p_target_start
p.p_target_end
+ g#part_add "/dev/sdb" (mbr_part_type p) p.p_target_start p.p_target_end
) partitions;
(* Copy over the data. *)
I don't think the comment is true:
$ guestfish -N disk -- \
part-init /dev/sda gpt : part-add /dev/sda "foo" 100 -100
libguestfs: error: part_add: unknown partition type: foo: this should be
"primary", "logical" or "extended"
The mbr_part_type function just has to be changed so it always returns
"primary" is the part_type = GPT.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages.
http://libguestfs.org