From: Richard W.M. Jones Date: Wed, 26 Oct 2011 12:56:18 +0000 (+0100) Subject: virt-resize: Be much more conservative about moving first partition. X-Git-Tag: 1.13.25~1 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=d64fca7b848df36f2043a8af72aaa670e3c14c53;p=libguestfs.git virt-resize: Be much more conservative about moving first partition. Commit 2910413850c7d9e8df753afad179e415f0638d6d caused Windows 7 resizes to break with the 0xc0000225 boot error. Change the --align-first auto (default) option so that it is more conservative about when it moves the first partition. In particular it doesn't move it if it's already aligned (as it is for Win7), nor if there is more than one partition (also Win7). Tested with: Windows XP, 2003, 7, Ubuntu 10.10 and RHEL 5. --- diff --git a/resize/resize.ml b/resize/resize.ml index 9976ff4..3c7a633 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -866,20 +866,41 @@ let () = (* Are we going to align the first partition and fix the bootloader? *) let align_first_partition_and_fix_bootloader = - (* Bootloaders that we know how to fix. *) - let can_fix_boot_loader = + (* Bootloaders that we know how to fix: + * - first partition is NTFS, and + * - first partition is bootable, and + * - only one partition (ie. not Win Vista and later), and + * - it's not already aligned to some small value (no point + * moving it around unnecessarily) + *) + let rec can_fix_boot_loader () = match partitions with - | { p_type = ContentFS ("ntfs", _); p_bootable = true; - p_operation = OpCopy | OpIgnore | OpResize _ } :: _ -> true + | [ { p_part = { G.part_start = start }; + p_type = ContentFS ("ntfs", _); + p_bootable = true; + p_operation = OpCopy | OpIgnore | OpResize _ } ] + when not_aligned_enough start -> true | _ -> false + and not_aligned_enough start = + let alignment = alignment_of start in + alignment < 12 (* < 4K alignment *) + and alignment_of = function + | 0L -> 64 + | n when n &^ 1L = 1L -> 0 + | n -> 1 + alignment_of (n /^ 2L) in - match align_first, can_fix_boot_loader with + match align_first, can_fix_boot_loader () with | `Never, _ | `Auto, false -> false | `Always, _ | `Auto, true -> true +let () = + if debug then + eprintf "align_first_partition_and_fix_bootloader = %b\n%!" + align_first_partition_and_fix_bootloader + (* Repartition the target disk. *) (* Calculate the location of the partitions on the target disk. This