- # Delete any existing partitions on the destination disk.
- $g->part_init ("/dev/sdb", $parttype);
+ # Delete any existing partitions on the destination disk,
+ # but leave the bootloader that we copied over intact.
+ if ($copy_boot_loader) {
+ # Delete in reverse as an easy way to deal with extended
+ # partitions.
+ foreach (sort { $b cmp $a } $g->list_partitions ()) {
+ if (m{^/dev/.db(\d+)$}) {
+ $g->part_del ("/dev/sdb", $1);
+ }
+ }
+ } else {
+ # Didn't copy over the initial boot loader, so we need
+ # to make a new partition table here.
+ $g->part_init ("/dev/sdb", $parttype);
+ }
+
+ # Work out where to start the first partition.
+ die __"virt-resize: source disk does not have a first partition\n"
+ unless exists ($partitions{"/dev/sda1"});
+ my $start = $partitions{"/dev/sda1"}->{part_start} / $sectsize;