X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=tools%2Fvirt-resize;h=28f51af1fac3438eecd84302b4f6e7164520e358;hb=eeaab2ba84441a96977281a4472b1bccb9ec80a9;hp=b3185d3e4f0017dc797573045f9f77ee4147829e;hpb=cdc89bb10ff584d3aaf07b70c264d659e5f416e3;p=libguestfs.git diff --git a/tools/virt-resize b/tools/virt-resize index b3185d3..28f51af 100755 --- a/tools/virt-resize +++ b/tools/virt-resize @@ -33,6 +33,8 @@ $Data::Dumper::Sortkeys = 1; die __"virt-resize: sorry this program does not work on a 32 bit host\n" if ~1 == 4294967294; +$| = 1; + =encoding utf8 =head1 NAME @@ -61,7 +63,22 @@ L and L, we recommend you go and read those manual pages first. -=head1 BASIC USAGE +=head1 EXAMPLES + +Copy C to C, extending one of the guest's partitions +to fill the extra 5GB of space. + + truncate -r olddisk newdisk; truncate -s +5G newdisk + virt-list-partitions -lht olddisk + # Note "/dev/sda2" is a partition inside the "olddisk" file. + virt-resize --expand /dev/sda2 olddisk newdisk + +As above, but make the /boot partition 200MB bigger, while giving the +remaining space to /dev/sda2: + + virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 olddisk newdisk + +=head1 DETAILED USAGE =head2 EXPANDING A VIRTUAL MACHINE DISK @@ -568,6 +585,7 @@ sub launch_guestfs $g->set_trace (1) if $debug; $g->add_drive_ro ($infile); $g->add_drive ($outfile); + $g->set_progress_callback (\&progress_callback) unless $quiet; $g->launch (); } @@ -1107,16 +1125,11 @@ sub copy_data } if (!$quiet && !$debug) { - local $| = 1; - print __x("Copying {p} ...", p => $part); + print __x("Copying {p} ...\n", p => $part); } $g->copy_size ($part, $target, $newsize < $oldsize ? $newsize : $oldsize); - - if (!$quiet && !$debug) { - print " ", __"done", "\n"; - } } } } @@ -1315,6 +1328,25 @@ sub canonicalize $_; } +# Not as sophisticated as the guestfish progress bar, because +# I intend to use an external library for this at some point (XXX). +sub progress_callback +{ + my $proc_nr = shift; + my $serial = shift; + my $position = shift; + my $total = shift; + + my $ratio = $position / $total; + if ($ratio < 0) { $ratio = 0 } + elsif ($ratio > 1) { $ratio = 1 } + + my $dots = int ($ratio * 76); + + print "[", "#"x$dots, "-"x(76-$dots), "]\r"; + print "\n" if $ratio == 1; +} + =head1 NOTES =head2 "Partition 1 does not end on cylinder boundary."