On Fri, Sep 19, 2014 at 03:39:10PM +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 | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 2ffd26e..f57b2ff 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -50,6 +50,7 @@ type partition = {
p_id : partition_id; (* Partition (MBR/GPT) ID. *)
p_type : partition_content; (* Content type and content size. *)
p_label : string option; (* Label/name. *)
+ p_part_num: int; (* partition number *)
I don't think it's necessary to store p_part_num in the main
partitions struct.
Instead you can get to the partition number using:
p.p_part.G.part_num
For example, mbr_part_type could be written:
let mbr_part_type x =
if x.p_part.G.part_num <= 4 && x.p_type <> ContentExtendedPartition
then "primary"
[etc]
+ let mbr_part_type x =
+ if x.p_part_num <= 4 && x.p_type <> ContentExtendedPartition then
"primary"
+ else if x.p_part_num <= 4 && 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;
The big problem with this is I think it doesn't work properly for GPT.
GPT has no idea what "extended" is -- such a concept does not exist.
So if you passed a GPT guest to virt-resize with >= 5 partitions in
it, then virt-resize will not work.
I think you need to check the partition table type somewhere.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW