rescue: Rewrite virt-rescue in C.
[libguestfs.git] / tools / virt-resize
1 #!/usr/bin/perl -w
2 # virt-resize
3 # Copyright (C) 2010 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 use warnings;
20 use strict;
21
22 use Sys::Guestfs;
23 use Sys::Guestfs::Lib qw(feature_available);
24 use Fcntl qw(S_ISREG SEEK_SET);
25 use POSIX qw(floor);
26 use Pod::Usage;
27 use Getopt::Long;
28 use Data::Dumper;
29 use Locale::TextDomain 'libguestfs';
30
31 $Data::Dumper::Sortkeys = 1;
32
33 die __"virt-resize: sorry this program does not work on a 32 bit host\n"
34     if ~1 == 4294967294;
35
36 $| = 1;
37
38 =encoding utf8
39
40 =head1 NAME
41
42 virt-resize - Resize a virtual machine disk
43
44 =head1 SYNOPSIS
45
46  virt-resize [--resize /dev/sdaN=[+/-]<size>[%]]
47    [--expand /dev/sdaN] [--shrink /dev/sdaN]
48    [--ignore /dev/sdaN] [--delete /dev/sdaN] [...] indisk outdisk
49
50 =head1 DESCRIPTION
51
52 Virt-resize is a tool which can resize a virtual machine disk, making
53 it larger or smaller overall, and resizing or deleting any partitions
54 contained within.
55
56 Virt-resize B<cannot> resize disk images in-place.  Virt-resize
57 B<should not> be used on live virtual machines - for consistent
58 results, shut the virtual machine down before resizing it.
59
60 If you are not familiar with the associated tools:
61 L<virt-filesystems(1)> and L<virt-df(1)>, we recommend you go and read
62 those manual pages first.
63
64 =head1 EXAMPLES
65
66 Copy C<olddisk> to C<newdisk>, extending one of the guest's partitions
67 to fill the extra 5GB of space.
68
69  truncate -r olddisk newdisk; truncate -s +5G newdisk
70  virt-filesystems --long --h --all -a olddisk
71  # Note "/dev/sda2" is a partition inside the "olddisk" file.
72  virt-resize --expand /dev/sda2 olddisk newdisk
73
74 As above, but make the /boot partition 200MB bigger, while giving the
75 remaining space to /dev/sda2:
76
77  virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 olddisk newdisk
78
79 As above, but the output format will be uncompressed qcow2:
80
81  qemu-img create -f qcow2 newdisk.qcow2 15G
82  virt-resize --expand /dev/sda2 olddisk newdisk.qcow2
83
84 =head1 DETAILED USAGE
85
86 =head2 EXPANDING A VIRTUAL MACHINE DISK
87
88 =over 4
89
90 =item 1. Shut down the virtual machine
91
92 =item 2. Locate input disk image
93
94 Locate the input disk image (ie. the file or device on the host
95 containing the guest's disk).  If the guest is managed by libvirt, you
96 can use C<virsh dumpxml> like this to find the disk image name:
97
98  # virsh dumpxml guestname | xpath /domain/devices/disk/source
99  Found 1 nodes:
100  -- NODE --
101  <source dev="/dev/vg/lv_guest" />
102
103 =item 3. Look at current sizing
104
105 Use L<virt-filesystems(1)> to display the current partitions and
106 sizes:
107
108  # virt-filesystems --long --parts --blkdevs -h -a /dev/vg/lv_guest
109  Name       Type       Size  Parent
110  /dev/sda1  partition  101M  /dev/sda
111  /dev/sda2  partition  7.9G  /dev/sda
112  /dev/sda   device     8.0G  -
113
114 (This example is a virtual machine with an 8 GB disk which we would
115 like to expand up to 10 GB).
116
117 =item 4. Create output disk
118
119 Virt-resize cannot do in-place disk modifications.  You have to have
120 space to store the resized output disk.
121
122 To store the resized disk image in a file, create a file of a suitable
123 size:
124
125  # rm -f outdisk
126  # truncate -s 10G outdisk
127
128 Or use L<lvcreate(1)> to create a logical volume:
129
130  # lvcreate -L 10G -n lv_name vg_name
131
132 Or use L<virsh(1)> vol-create-as to create a libvirt storage volume:
133
134  # virsh pool-list
135  # virsh vol-create-as poolname newvol 10G
136
137 =item 5. Resize
138
139 virt-resize takes two mandatory parameters, the input disk (eg. device
140 or file) and the output disk.  The output disk is the one created in
141 the previous step.
142
143  # virt-resize indisk outdisk
144
145 This command just copies disk image C<indisk> to disk image C<outdisk>
146 I<without> resizing or changing any existing partitions.  If
147 C<outdisk> is larger, then an extra, empty partition is created at the
148 end of the disk covering the extra space.  If C<outdisk> is smaller,
149 then it will give an error.
150
151 More realistically you'd want to expand existing partitions in the
152 disk image by passing extra options (for the full list see the
153 L</OPTIONS> section below).
154
155 L</--expand> is the most useful option.  It expands the named
156 partition within the disk to fill any extra space:
157
158  # virt-resize --expand /dev/sda2 indisk outdisk
159
160 (In this case, an extra partition is I<not> created at the end of the
161 disk, because there will be no unused space).
162
163 L</--resize> is the other commonly used option.  The following would
164 increase the size of /dev/sda1 by 200M, and expand /dev/sda2
165 to fill the rest of the available space:
166
167  # virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 \
168      indisk outdisk
169
170 If the expanded partition in the image contains a filesystem or LVM
171 PV, then if virt-resize knows how, it will resize the contents, the
172 equivalent of calling a command such as L<pvresize(8)>,
173 L<resize2fs(8)> or L<ntfsresize(8)>.  However virt-resize does not
174 know how to resize some filesystems, so you would have to online
175 resize them after booting the guest.  And virt-resize also does not
176 resize anything inside an LVM PV, it just resizes the PV itself and
177 leaves the user to resize any LVs inside that PV as desired.
178
179 Other options are covered below.
180
181 =item 6. Test
182
183 Thoroughly test the new disk image I<before> discarding the old one.
184
185 If you are using libvirt, edit the XML to point at the new disk:
186
187  # virsh edit guestname
188
189 Change E<lt>source ...E<gt>, see
190 L<http://libvirt.org/formatdomain.html#elementsDisks>
191
192 Then start up the domain with the new, resized disk:
193
194  # virsh start guestname
195
196 and check that it still works.  See also the L</NOTES> section below
197 for additional information.
198
199 =item 7. Resize LVs etc inside the guest
200
201 (This can also be done offline using L<guestfish(1)>)
202
203 Once the guest has booted you should see the new space available, at
204 least for filesystems that virt-resize knows how to resize, and for
205 PVs.  The user may need to resize LVs inside PVs, and also resize
206 filesystem types that virt-resize does not know how to expand.
207
208 =back
209
210 =head2 SHRINKING A VIRTUAL MACHINE DISK
211
212 Shrinking is somewhat more complex than expanding, and only an
213 overview is given here.
214
215 Firstly virt-resize will not attempt to shrink any partition content
216 (PVs, filesystems).  The user has to shrink content before passing the
217 disk image to virt-resize, and virt-resize will check that the content
218 has been shrunk properly.
219
220 (Shrinking can also be done offline using L<guestfish(1)>)
221
222 After shrinking PVs and filesystems, shut down the guest, and proceed
223 with steps 3 and 4 above to allocate a new disk image.
224
225 Then run virt-resize with any of the C<--shrink> and/or C<--resize>
226 options.
227
228 =head2 IGNORING OR DELETING PARTITIONS
229
230 virt-resize also gives a convenient way to ignore or delete partitions
231 when copying from the input disk to the output disk.  Ignoring a
232 partition speeds up the copy where you don't care about the existing
233 contents of a partition.  Deleting a partition removes it completely,
234 but note that it also renumbers any partitions after the one which is
235 deleted, which can leave some guests unbootable.
236
237 =head2 QCOW2 AND NON-SPARSE RAW FORMATS
238
239 If the input disk is in qcow2 format, then you may prefer that the
240 output is in qcow2 format as well.  Alternately, virt-resize can
241 convert the format on the fly.  The output format is simply determined
242 by the format of the empty output container that you provide.  Thus to
243 create qcow2 output, use:
244
245  qemu-img create [-c] -f qcow2 outdisk [size]
246
247 instead of the truncate command (use C<-c> for a compressed disk).
248
249 Similarly, to get non-sparse raw output use:
250
251  fallocate -l size outdisk
252
253 (on older systems that don't have the L<fallocate(1)> command use
254 C<dd if=/dev/zero of=outdisk bs=1M count=..>)
255
256 =head1 OPTIONS
257
258 =over 4
259
260 =cut
261
262 my $help;
263
264 =item B<--help>
265
266 Display help.
267
268 =cut
269
270 my $version;
271
272 =item B<--version>
273
274 Display version number and exit.
275
276 =cut
277
278 my @resize;
279
280 =item B<--resize part=size>
281
282 Resize the named partition (expanding or shrinking it) so that it has
283 the given size.
284
285 C<size> can be expressed as an absolute number followed by
286 b/K/M/G/T/P/E to mean bytes, Kilobytes, Megabytes, Gigabytes,
287 Terabytes, Petabytes or Exabytes; or as a percentage of the current
288 size; or as a relative number or percentage.  For example:
289
290  --resize /dev/sda2=10G
291
292  --resize /dev/sda4=90%
293
294  --resize /dev/sda2=+1G
295
296  --resize /dev/sda2=-200M
297
298  --resize /dev/sda1=+128K
299
300  --resize /dev/sda1=+10%
301
302  --resize /dev/sda1=-10%
303
304 You can increase the size of any partition.  Virt-resize will expand
305 the direct content of the partition if it knows how (see C<--expand>
306 below).
307
308 You can only I<decrease> the size of partitions that contain
309 filesystems or PVs which have already been shrunk.  Virt-resize will
310 check this has been done before proceeding, or else will print an
311 error (see also C<--resize-force>).
312
313 You can give this option multiple times.
314
315 =cut
316
317 my @resize_force;
318
319 =item B<--resize-force part=size>
320
321 This is the same as C<--resize> except that it will let you decrease
322 the size of any partition.  Generally this means you will lose any
323 data which was at the end of the partition you shrink, but you may not
324 care about that (eg. if shrinking an unused partition, or if you can
325 easily recreate it such as a swap partition).
326
327 See also the C<--ignore> option.
328
329 =cut
330
331 my $expand;
332
333 =item B<--expand part>
334
335 Expand the named partition so it uses up all extra space (space left
336 over after any other resize changes that you request have been done).
337
338 If virt-resize knows how, it will expand the direct content of the
339 partition.  For example, if the partition is an LVM PV, it will expand
340 the PV to fit (like calling L<pvresize(8)>).  Virt-resize leaves any
341 other content it doesn't know about alone.
342
343 Currently virt-resize can resize:
344
345 =over 4
346
347 =item *
348
349 ext2, ext3 and ext4 filesystems when they are contained
350 directly inside a partition.
351
352 =item *
353
354 NTFS filesystems contained directly in a partition, if libguestfs was
355 compiled with support for NTFS.
356
357 The filesystem must have been shut down consistently last time it was
358 used.  Additionally, L<ntfsresize(8)> marks the resized filesystem as
359 requiring a consistency check, so at the first boot after resizing
360 Windows will check the disk.
361
362 =item *
363
364 LVM PVs (physical volumes).  However virt-resize does I<not>
365 resize anything inside the PV.  The user will have to resize
366 LVs as desired.
367
368 =back
369
370 Note that you cannot use C<--expand> and C<--shrink> together.
371
372 =cut
373
374 my $shrink;
375
376 =item B<--shrink part>
377
378 Shrink the named partition until the overall disk image fits in the
379 destination.  The named partition B<must> contain a filesystem or PV
380 which has already been shrunk using another tool (eg. L<guestfish(1)>
381 or other online tools).  Virt-resize will check this and give an error
382 if it has not been done.
383
384 The amount by which the overall disk must be shrunk (after carrying
385 out all other operations requested by the user) is called the
386 "deficit".  For example, a straight copy (assume no other operations)
387 from a 5GB disk image to a 4GB disk image results in a 1GB deficit.
388 In this case, virt-resize would give an error unless the user
389 specified a partition to shrink and that partition had more than a
390 gigabyte of free space.
391
392 Note that you cannot use C<--expand> and C<--shrink> together.
393
394 =cut
395
396 my @ignore;
397
398 =item B<--ignore part>
399
400 Ignore the named partition.  Effectively this means the partition is
401 allocated on the destination disk, but the content is not copied
402 across from the source disk.  The content of the partition will be
403 blank (all zero bytes).
404
405 You can give this option multiple times.
406
407 =cut
408
409 my @delete;
410
411 =item B<--delete part>
412
413 Delete the named partition.  It would be more accurate to describe
414 this as "don't copy it over", since virt-resize doesn't do in-place
415 changes and the original disk image is left intact.
416
417 Note that when you delete a partition, then anything contained in the
418 partition is also deleted.  Furthermore, this causes any partitions
419 that come after to be I<renumbered>, which can easily make your guest
420 unbootable.
421
422 You can give this option multiple times.
423
424 =cut
425
426 my @lv_expand;
427
428 =item B<--LV-expand logvol>
429
430 This takes the logical volume and, as a final step, expands it to fill
431 all the space available in its volume group.  A typical usage,
432 assuming a Linux guest with a single PV C</dev/sda2> and a root device
433 called C</dev/vg_guest/lv_root> would be:
434
435  virt-resize indisk outdisk \
436    --expand /dev/sda2 --LV-expand /dev/vg_guest/lv_root
437
438 This would first expand the partition (and PV), and then expand the
439 root device to fill the extra space in the PV.
440
441 The contents of the LV are also resized if virt-resize knows how to do
442 that.  You can stop virt-resize from trying to expand the content by
443 using the option C<--no-expand-content>.
444
445 Use L<virt-filesystems(1)> to list the filesystems in
446 the guest.
447
448 You can give this option multiple times, I<but> it doesn't
449 make sense to do this unless the logical volumes you specify
450 are all in different volume groups.
451
452 =cut
453
454 my $copy_boot_loader = 1;
455
456 =item B<--no-copy-boot-loader>
457
458 By default, virt-resize copies over some sectors at the start of the
459 disk (up to the beginning of the first partition).  Commonly these
460 sectors contain the Master Boot Record (MBR) and the boot loader, and
461 are required in order for the guest to boot correctly.
462
463 If you specify this flag, then this initial copy is not done.  You may
464 need to reinstall the boot loader in this case.
465
466 =cut
467
468 my $extra_partition = 1;
469 my $min_extra_partition = 10 * 1024 * 1024; # see below
470
471 =item B<--no-extra-partition>
472
473 By default, virt-resize creates an extra partition if there is any
474 extra, unused space after all resizing has happened.  Use this option
475 to prevent the extra partition from being created.  If you do this
476 then the extra space will be inaccessible until you run fdisk, parted,
477 or some other partitioning tool in the guest.
478
479 Note that if the surplus space is smaller than 10 MB, no extra
480 partition will be created.
481
482 =cut
483
484 my $expand_content = 1;
485
486 =item B<--no-expand-content>
487
488 By default, virt-resize will try to expand the direct contents
489 of partitions, if it knows how (see C<--expand> option above).
490
491 If you give the C<--no-expand-content> option then virt-resize
492 will not attempt this.
493
494 =cut
495
496 my $debug;
497
498 =item B<-d> | B<--debug>
499
500 Enable debugging messages.
501
502 =cut
503
504 my $dryrun;
505
506 =item B<-n> | B<--dryrun>
507
508 Print a summary of what would be done, but don't do anything.
509
510 =cut
511
512 my $quiet;
513
514 =item B<-q> | B<--quiet>
515
516 Don't print the summary.
517
518 =cut
519
520 my $format;
521
522 =item B<--format> raw
523
524 Specify the format of the input disk image.  If this flag is not
525 given then it is auto-detected from the image itself.
526
527 If working with untrusted raw-format guest disk images, you should
528 ensure the format is always specified.
529
530 Note that this option I<does not> affect the output format.
531 See L</QCOW2 AND NON-SPARSE RAW FORMATS>.
532
533 =cut
534
535 my $output_format;
536
537 =item B<--output-format> raw
538
539 Specify the format of the output disk image.  If this flag is not
540 given then it is auto-detected from the image itself.
541
542 If working with untrusted raw-format guest disk images, you should
543 ensure the format is always specified.
544
545 Note that you still need to create the output disk with the right
546 format.  See L</QCOW2 AND NON-SPARSE RAW FORMATS>.
547
548 =back
549
550 =cut
551
552 GetOptions ("help|?" => \$help,
553             "version" => \$version,
554             "resize=s" => \@resize,
555             "resize-force=s" => \@resize_force,
556             "expand=s" => \$expand,
557             "shrink=s" => \$shrink,
558             "ignore=s" => \@ignore,
559             "delete=s" => \@delete,
560             "lv-expand=s" => \@lv_expand,
561             "copy-boot-loader!" => \$copy_boot_loader,
562             "extra-partition!" => \$extra_partition,
563             "expand-content!" => \$expand_content,
564             "d|debug" => \$debug,
565             "n|dryrun|dry-run" => \$dryrun,
566             "q|quiet" => \$quiet,
567             "format=s" => \$format,
568             "output-format=s" => \$output_format,
569     ) or pod2usage (2);
570 pod2usage (1) if $help;
571 if ($version) {
572     my $g = Sys::Guestfs->new ();
573     my %h = $g->version ();
574     print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
575     exit
576 }
577
578 die "virt-resize [--options] indisk outdisk\n" unless @ARGV == 2;
579
580 # Check in and out images exist.
581 my $infile = $ARGV[0];
582 my $outfile = $ARGV[1];
583 die __x("virt-resize: {file}: does not exist or is not readable\n", file => $infile)
584     unless -r $infile;
585 die __x("virt-resize: {file}: does not exist or is not writable\nYou have to create the destination disk before running this program.\nPlease read the virt-resize(1) manpage for more information.\n", file => $outfile)
586     unless -w $outfile;
587
588 # Add them to the handle and launch the appliance.
589 my $g;
590 launch_guestfs ();
591
592 sub launch_guestfs
593 {
594     $g = Sys::Guestfs->new ();
595     $g->set_trace (1) if $debug;
596     my @args = ($infile);
597     push @args, readonly => 1;
598     push @args, format => $format if defined $format;
599     $g->add_drive_opts (@args);
600     @args = ($outfile);
601     push @args, format => $output_format if defined $output_format;
602     $g->add_drive_opts (@args);
603     $g->set_progress_callback (\&progress_callback) unless $quiet;
604     $g->launch ();
605 }
606
607 my $sectsize = $g->blockdev_getss ("/dev/sdb");
608
609 # Get the size in bytes of each disk.
610 #
611 # Originally we computed this by looking at the same of the host file,
612 # but of course this failed for qcow2 images (RHBZ#633096).  The right
613 # way to do it is with $g->blockdev_getsize64.
614 my $insize = $g->blockdev_getsize64 ("/dev/sda");
615 my $outsize = $g->blockdev_getsize64 ("/dev/sdb");
616
617 if ($debug) {
618     print "$infile size $insize bytes\n";
619     print "$outfile size $outsize bytes\n";
620 }
621
622 # Create a partition table.
623 #
624 # We *must* do this before copying the bootloader across, and copying
625 # the bootloader must be careful not to disturb this partition table
626 # (RHBZ#633766).  There are two reasons for this:
627 #
628 # (1) The 'parted' library is stupid and broken.  In many ways.  In
629 # this particular instance the stupid and broken bit is that it
630 # overwrites the whole boot sector when initializating a partition
631 # table.  (Upstream don't consider this obvious problem to be a bug).
632 #
633 # (2) GPT has a backup partition table located at the end of the disk.
634 # It's non-movable, because the primary GPT contains fixed references
635 # to both the size of the disk and the backup partition table at the
636 # end.  This would be a problem for any resize that didn't either
637 # carefully move the backup GPT (and rewrite those references) or
638 # recreate the whole partition table from scratch.
639
640 my $parttype;
641 create_partition_table ();
642
643 sub create_partition_table
644 {
645     local $_;
646
647     $parttype = $g->part_get_parttype ("/dev/sda");
648     print "partition table type: $parttype\n" if $debug;
649
650     $g->part_init ("/dev/sdb", $parttype);
651 }
652
653 # In reality the number of sectors containing boot loader data will be
654 # less than this (although Windows 7 defaults to putting the first
655 # partition on sector 2048, and has quite a large boot loader).
656 #
657 # However make this large enough to be sure that we have copied over
658 # the boot loader.  We could also do this by looking for the sector
659 # offset of the first partition.
660 #
661 # It doesn't matter if we copy too much.
662 my $max_bootloader = 4096 * 512;
663
664 die __x("virt-resize: {file}: file is too small to be a disk image ({sz} bytes)\n",
665         file => $infile, sz => $insize)
666     if $insize < $max_bootloader;
667 die __x("virt-resize: {file}: file is too small to be a disk image ({sz} bytes)\n",
668         file => $outfile, sz => $outsize)
669     if $outsize < $max_bootloader;
670
671 # Copy the boot loader across.
672 do_copy_boot_loader () if $copy_boot_loader;
673
674 sub do_copy_boot_loader
675 {
676     print "copying boot loader ...\n" if $debug;
677
678     # Don't disturb the partition table that we just wrote.
679     # https://secure.wikimedia.org/wikipedia/en/wiki/Master_Boot_Record
680     # https://secure.wikimedia.org/wikipedia/en/wiki/GUID_Partition_Table
681
682     my $bootsect = $g->pread_device ("/dev/sda", 446, 0);
683     die __"virt-resize: short read" if length ($bootsect) < 446;
684
685     $g->pwrite_device ("/dev/sdb", $bootsect, 0);
686
687     my $start = 512;
688     if ($parttype eq "gpt") {
689         # XXX With 4K sectors does GPT just fit more entries in a
690         # sector, or does it always use 34 sectors?
691         $start = 17408;
692     }
693
694     my $loader = $g->pread_device ("/dev/sda", $max_bootloader, $start);
695     die __"virt-resize: short read" if length ($loader) < $max_bootloader;
696
697     $g->pwrite_device ("/dev/sdb", $loader, $start);
698 }
699
700 my $to_be_expanded = 0;
701
702 # Get the partitions on the source disk.
703 my @partitions;
704 my %partitions;
705 check_source_disk ();
706
707 sub check_source_disk
708 {
709     local $_;
710
711     # Partitions and PVs.
712     my @p = $g->part_list ("/dev/sda");
713     foreach (@p) {
714         my $name = "/dev/sda" . $_->{part_num};
715         push @partitions, $name;
716
717         my %h = %$_;
718         $h{name} = $name;
719         $h{bootable} = $g->part_get_bootable ("/dev/sda", $h{part_num});
720         eval { $h{mbr_id} = $g->part_get_mbr_id ("/dev/sda", $h{part_num}); };
721         $partitions{$name} = \%h;
722     }
723 }
724
725 # Examine each partition.
726 my @pvs_full = $g->pvs_full ();
727 examine_partition ($_) foreach @partitions;
728
729 sub examine_partition
730 {
731     local $_;
732     my $part = shift;
733
734     # What is it?
735     my $type = "unknown";
736     eval {
737         $type = $g->vfs_type ($part);
738     };
739     $partitions{$part}->{type} = $type;
740
741     # Can we get the actual size of this object (ie. to find out if it
742     # is smaller than the container for shrinking)?
743     my $fssize;
744     if ($type eq "LVM2_member") { # LVM PV
745         foreach (@pvs_full) {
746             $fssize = $_->{pv_size}
747               if canonicalize ($_->{pv_name}) eq $part;
748         }
749     } else {                    # Something mountable?
750         eval {
751             $g->mount_ro ($part, "/");
752
753             my %stat = $g->statvfs ("/");
754             $fssize = $stat{bsize} * $stat{blocks};
755         };
756
757         eval {
758             $g->umount_all ();
759         };
760     }
761
762     # This might be undef if we didn't successfully find the size.  In
763     # that case user won't be allowed to shrink this partition except
764     # by forcing it.
765     $partitions{$part}->{fssize} = $fssize;
766
767     # Is it partition content that we know how to expand?
768     $partitions{$part}->{can_expand_content} = 0;
769     if ($expand_content) {
770         if ($type eq "LVM2_member") {
771             $partitions{$part}->{can_expand_content} = 1;
772             $partitions{$part}->{expand_content_method} = "pvresize";
773         } elsif ($type =~ /^ext[234]$/) {
774             $partitions{$part}->{can_expand_content} = 1;
775             $partitions{$part}->{expand_content_method} = "resize2fs";
776         } elsif ($type eq "ntfs" && feature_available ($g, "ntfsprogs")) {
777             $partitions{$part}->{can_expand_content} = 1;
778             $partitions{$part}->{expand_content_method} = "ntfsresize";
779         }
780     }
781 }
782
783 if ($debug) {
784     print "partitions found: ", join (", ", @partitions), "\n";
785     foreach my $part (@partitions) {
786         print "$part:\n";
787         foreach (sort keys %{$partitions{$part}}) {
788             print("\t", $_, " = ",
789                   defined ($partitions{$part}->{$_})
790                   ? $partitions{$part}->{$_} : "undef",
791                   "\n");
792         }
793     }
794 }
795
796 # Examine the LVs (for --lv-expand option).
797 my @lvs = $g->lvs ();
798 my %lvs;
799 examine_lv ($_) foreach @lvs;
800 mark_lvs_to_expand ();
801
802 sub examine_lv
803 {
804     local $_ = shift;
805
806     $lvs{$_}->{name} = $_;
807
808     my $type = "unknown";
809     eval {
810         $type = $g->vfs_type ($_);
811     };
812     $lvs{$_}->{type} = $type;
813
814     if ($expand_content) {
815         if ($type =~ /^ext[234]$/) {
816             $lvs{$_}->{can_expand_content} = 1;
817             $lvs{$_}->{expand_content_method} = "resize2fs";
818         } elsif ($type eq "ntfs" && feature_available ($g, "ntfsprogs")) {
819             $lvs{$_}->{can_expand_content} = 1;
820             $lvs{$_}->{expand_content_method} = "ntfsresize";
821         }
822     }
823 }
824
825 sub mark_lvs_to_expand {
826     local $_;
827
828     foreach (@lv_expand) {
829         die __x("virt-resize: no logical volume called {n}\n",
830                 n => $_)
831             unless exists $lvs{$_};
832
833         if ($lvs{$_}->{can_expand_content}) {
834             $lvs{$_}->{will_expand_content} = 1;
835             $to_be_expanded++;
836         }
837     }
838 }
839
840 sub find_partition
841 {
842     local $_ = shift;
843     my $option = shift;
844
845     $_ = "/dev/$_" unless $_ =~ m{^/dev};
846     $_ = canonicalize ($_);
847
848     unless (exists $partitions{$_}) {
849         die __x("{p}: partition not found in the source disk image, when using the '{opt}' command line option\n",
850                 p => $_,
851                 opt => $option)
852     }
853
854     if ($partitions{$_}->{ignore}) {
855         die __x("{p}: partition ignored, you cannot use it in another command line argument\n",
856                 p => $_)
857     }
858     if ($partitions{$_}->{delete}) {
859         die __x("{p}: partition deleted, you cannot use it in another command line argument\n",
860                 p => $_)
861     }
862
863     return $_;
864 }
865
866 # Handle --ignore.
867 do_ignore ($_) foreach @ignore;
868
869 sub do_ignore
870 {
871     local $_ = shift;
872     $_ = find_partition ($_, "--ignore");
873     $partitions{$_}->{ignore} = 1;
874 }
875
876 # Handle --delete.
877 do_delete ($_) foreach @delete;
878
879 sub do_delete
880 {
881     local $_ = shift;
882     $_ = find_partition ($_, "--delete");
883     $partitions{$_}->{delete} = 1;
884 }
885
886 # Handle --resize and --resize-force.
887 do_resize ($_, 0, "--resize") foreach @resize;
888 do_resize ($_, 1, "--resize-force") foreach @resize_force;
889
890 sub do_resize
891 {
892     local $_ = shift;
893     my $force = shift;
894     my $option = shift;
895
896     # Argument is "part=size" ...
897     my ($part, $sizefield) = split /=/, $_, 2;
898     $part = find_partition ($part, $option);
899
900     if (exists $partitions{$part}->{newsize}) {
901         die __x("{p}: this partition has already been marked for resizing\n",
902                 p => $part);
903     }
904
905     # Parse the size field.
906     my $oldsize = $partitions{$part}->{part_size};
907     my $newsize;
908     if (!defined ($sizefield) || $sizefield eq "") {
909         die __x("{p}: missing size field in {o} option\n",
910                 p => $part, o => $option);
911     } elsif ($sizefield =~ /^([.\d]+)([bKMGTPE])$/) {
912         $newsize = sizebytes ($1, $2);
913     } elsif ($sizefield =~ /^\+([.\d]+)([bKMGTPE])$/) {
914         my $incr = sizebytes ($1, $2);
915         $newsize = $oldsize + $incr;
916     } elsif ($sizefield =~ /^-([.\d]+)([bKMGTPE])$/) {
917         my $decr = sizebytes ($1, $2);
918         $newsize = $oldsize - $decr;
919     } elsif ($sizefield =~ /^([.\d]+)%$/) {
920         $newsize = $oldsize * $1 / 100;
921     } elsif ($sizefield =~ /^\+([.\d]+)%$/) {
922         $newsize = $oldsize + $oldsize * $1 / 100;
923     } elsif ($sizefield =~ /^-([.\d]+)%$/) {
924         $newsize = $oldsize - $oldsize * $1 / 100;
925     } else {
926         die __x("{p}: {f}: cannot parse size field\n",
927                 p => $part, f => $sizefield)
928     }
929
930     $newsize > 0 or
931         die __x("{p}: new size is zero or negative\n", p => $part);
932
933     mark_partition_for_resize ($part, $oldsize, $newsize, $force, $option);
934 }
935
936 sub mark_partition_for_resize
937 {
938     local $_;
939     my $part = shift;
940     my $oldsize = shift;
941     my $newsize = shift;
942     my $force = shift;
943     my $option = shift;
944
945     # Do nothing if the size is the same.
946     return if $oldsize == $newsize;
947
948     my $bigger = $newsize > $oldsize;
949
950     # Check there is space to shrink this.
951     unless ($bigger || $force) {
952         if (! $partitions{$part}->{fssize} ||
953             $partitions{$part}->{fssize} > $newsize) {
954             die __x("{p}: cannot make this partition smaller because it contains a\nfilesystem, physical volume or other content that is larger than the new size.\nYou have to resize the content first, see virt-resize(1).\n",
955                     p => $part);
956         }
957     }
958
959     $partitions{$part}->{newsize} = $newsize;
960
961     if ($partitions{$part}->{can_expand_content} && $bigger) {
962         $partitions{$part}->{will_expand_content} = 1;
963         $to_be_expanded++;
964     }
965 }
966
967 # Handle --expand and --shrink.
968 my $surplus;
969 if (defined $expand && defined $shrink) {
970     die __"virt-resize: you cannot use options --expand and --shrink together\n"
971 }
972 if (defined $expand || defined $shrink) {
973     calculate_surplus ();
974
975     if ($debug) {
976         print "surplus before --expand or --shrink: $surplus (",
977           human_size ($surplus), ")\n";
978     }
979
980     do_expand () if $expand;
981     do_shrink () if $shrink;
982 }
983
984 # (Re-)calculate surplus after doing expand or shrink.
985 calculate_surplus ();
986
987 # Add up the total space required on the target so far, compared
988 # to the size of the target.  We end up with a surplus or deficit.
989 sub calculate_surplus
990 {
991     local $_;
992
993     # We need some overhead for partitioning.  Worst case would be for
994     # EFI partitioning + massive per-partition alignment.
995     my $overhead = $sectsize * (
996         2 * 64 +                   # GPT start and end
997         (64 * (@partitions + 1))   # Maximum alignment
998         ) +
999         ($max_bootloader - 64 * 512); # boot loader
1000
1001     my $required = 0;
1002     foreach (@partitions) {
1003         if ($partitions{$_}->{newsize}) {
1004             $required += $partitions{$_}->{newsize}
1005         } else {
1006             $required += $partitions{$_}->{part_size}
1007         }
1008     }
1009
1010     # Compare that to the actual target disk.
1011     $surplus = $outsize - ($required + $overhead);
1012 }
1013
1014 sub do_expand
1015 {
1016     local $_;
1017
1018     unless ($surplus > 0) {
1019         die __x("virt-resize: error: cannot use --expand when there is no surplus space to\nexpand into.  You need to make the target disk larger by at least {h}.\n",
1020                 h => human_size (-$surplus));
1021     }
1022
1023     my $part = find_partition ($expand, "--expand");
1024     my $oldsize = $partitions{$part}->{part_size};
1025     mark_partition_for_resize ($part, $oldsize, $oldsize + $surplus,
1026                                0, "--expand");
1027 }
1028
1029 sub do_shrink
1030 {
1031     local $_;
1032
1033     unless ($surplus < 0) {
1034         die __"virt-resize: error: cannot use --shrink because there is no deficit\n(see 'deficit' in the virt-resize(1) man page)\n"
1035     }
1036
1037     my $part = find_partition ($shrink, "--shrink");
1038     my $oldsize = $partitions{$part}->{part_size};
1039     mark_partition_for_resize ($part, $oldsize, $oldsize + $surplus,
1040                                0, "--shrink");
1041 }
1042
1043 # Print summary.
1044 print_summary () unless $quiet;
1045
1046 sub print_summary
1047 {
1048     local $_;
1049     print __"Summary of changes:\n";
1050
1051     foreach my $part (@partitions) {
1052         if ($partitions{$part}->{ignore}) {
1053             print __x("{p}: partition will be ignored\n", p => $part);
1054         } elsif ($partitions{$part}->{delete}) {
1055             print __x("{p}: partition will be deleted\n", p => $part);
1056         } elsif ($partitions{$part}->{newsize}) {
1057             print __x("{p}: partition will be resized from {oldsize} to {newsize}\n",
1058                       p => $part,
1059                       oldsize => human_size ($partitions{$part}->{part_size}),
1060                       newsize => human_size ($partitions{$part}->{newsize}));
1061             if ($partitions{$part}->{will_expand_content}) {
1062                 print __x("{p}: content will be expanded using the '{meth}' method\n",
1063                           p => $part,
1064                           meth => $partitions{$part}->{expand_content_method});
1065             }
1066         } else {
1067             print __x("{p}: partition will be left alone\n", p => $part);
1068         }
1069     }
1070
1071     foreach my $lv (@lv_expand) {
1072         print __x("{n}: LV will be expanded to maximum size\n",
1073                   n => $lv);
1074     }
1075
1076     foreach my $lv (@lvs) {
1077         if ($lvs{$lv}->{will_expand_content}) {
1078             print __x("{n}: content will be expanded using the '{meth}' method\n",
1079                       n => $lv,
1080                       meth => $lvs{$lv}->{expand_content_method});
1081         }
1082     }
1083
1084     if ($surplus > 0) {
1085         print __x("There is a surplus of {spl} bytes ({h}).\n",
1086                   spl => $surplus,
1087                   h => human_size ($surplus));
1088         if ($extra_partition) {
1089             if ($surplus >= $min_extra_partition) {
1090                 print __"An extra partition will be created for the surplus.\n";
1091             } else {
1092                 print __"The surplus space is not large enough for an extra partition to be created\nand so it will just be ignored.\n";
1093             }
1094         } else {
1095             print __"The surplus space will be ignored.  Run a partitioning program in the guest\nto partition this extra space if you want.\n";
1096         }
1097     } elsif ($surplus < 0) {
1098         die __x("virt-resize: error: there is a deficit of {def} bytes ({h}).\nYou need to make the target disk larger by at least this amount,\nor adjust your resizing requests.\n",
1099                 def => -$surplus,
1100                 h => human_size (-$surplus));
1101     }
1102 }
1103
1104 exit 0 if $dryrun;
1105
1106 # Repartition the target disk.
1107 my $nextpart = 1;
1108 repartition ();
1109
1110 sub repartition
1111 {
1112     local $_;
1113
1114     # Work out where to start the first partition.
1115     die __"virt-resize: source disk does not have a first partition\n"
1116         unless exists ($partitions{"/dev/sda1"});
1117     my $start = $partitions{"/dev/sda1"}->{part_start} / $sectsize;
1118
1119     # Align to 64.
1120     $start = ($start + 63) & ~63;
1121
1122     print "starting to partition from $start\n" if $debug;
1123
1124     # Create the new partitions.
1125     foreach my $part (@partitions) {
1126         unless ($partitions{$part}->{delete}) {
1127             # Size in sectors.
1128             my $size;
1129             if ($partitions{$part}->{newsize}) {
1130                 $size = ($partitions{$part}->{newsize} + $sectsize - 1)
1131                     / $sectsize;
1132             } else {
1133                 $size = ($partitions{$part}->{part_size} + $sectsize - 1)
1134                     / $sectsize;
1135             }
1136
1137             # Create it.
1138             my ($target, $end, $part_num) = add_partition ($start, $size);
1139             $partitions{$part}->{target} = $target;
1140
1141             if ($partitions{$part}->{bootable}) {
1142                 $g->part_set_bootable ("/dev/sdb", $part_num, 1);
1143             }
1144
1145             if ($partitions{$part}->{mbr_id}) {
1146                 $g->part_set_mbr_id ("/dev/sdb", $part_num,
1147                                      $partitions{$part}->{mbr_id});
1148             }
1149
1150             # Start of next partition + alignment.
1151             $start = $end + 1;
1152             $start = ($start + 63) & ~63;
1153         }
1154     }
1155
1156     # Create surplus partition.
1157     if ($extra_partition && $surplus >= $min_extra_partition) {
1158         add_partition ($start, $outsize / $sectsize - 64 - $start);
1159     }
1160 }
1161
1162 # Add a partition.
1163 sub add_partition
1164 {
1165     local $_;
1166     my $start = shift;
1167     my $size = shift;
1168
1169     my ($target, $end, $part_num);
1170
1171     if ($nextpart <= 3 || $parttype ne "msdos") {
1172         $target = "/dev/sdb$nextpart";
1173         $end = $start + $size - 1;
1174         $g->part_add ("/dev/sdb", "primary", $start, $end);
1175         $part_num = $nextpart++;
1176     } else {
1177         if ($nextpart == 4) {
1178             $g->part_add ("/dev/sdb", "extended", $start, -1);
1179             $part_num = $nextpart++;
1180             $start += 64;
1181         }
1182         $target = "/dev/sdb$nextpart";
1183         $end = $start + $size - 1;
1184         $g->part_add ("/dev/sdb", "logical", $start, $end);
1185         $part_num = $nextpart++;
1186     }
1187
1188     return ($target, $end, $part_num);
1189 }
1190
1191 # Copy over the data.
1192 copy_data ();
1193
1194 sub copy_data
1195 {
1196     foreach my $part (@partitions)
1197     {
1198         unless ($partitions{$part}->{ignore}) {
1199             my $target = $partitions{$part}->{target};
1200             if ($target) {
1201                 my $oldsize = $partitions{$part}->{part_size};
1202                 my $newsize;
1203                 if ($partitions{$part}->{newsize}) {
1204                     $newsize = $partitions{$part}->{newsize};
1205                 } else {
1206                     $newsize = $partitions{$part}->{part_size};
1207                 }
1208
1209                 if (!$quiet && !$debug) {
1210                     print __x("Copying {p} ...\n", p => $part);
1211                 }
1212
1213                 $g->copy_size ($part, $target,
1214                                $newsize < $oldsize ? $newsize : $oldsize);
1215             }
1216         }
1217     }
1218 }
1219
1220 # After copying the data over we must shut down and restart the
1221 # appliance in order to expand the content.  The reason for this may
1222 # not be obvious, but it's because otherwise we'll have duplicate VGs
1223 # (the old VG(s) and the new VG(s)) which breaks LVM.
1224 #
1225 # The restart is only required if we're going to expand something.
1226
1227 if ($to_be_expanded > 0) {
1228     restart_appliance ();
1229     expand_partitions ();
1230     expand_lvs ();
1231     expand_lvs_content ();
1232 }
1233
1234 sub restart_appliance
1235 {
1236     # Sync disk and exit.
1237     $g->umount_all ();
1238     $g->sync ();
1239     undef $g;
1240
1241     $g = Sys::Guestfs->new ();
1242     $g->set_trace (1) if $debug;
1243     my @args = ($outfile);
1244     push @args, format => $output_format if defined $output_format;
1245     $g->add_drive_opts (@args);
1246     $g->launch ();
1247
1248     # Target partitions have changed from /dev/sdb to /dev/sda,
1249     # so change them.
1250     foreach my $part (@partitions)
1251     {
1252         my $target = $partitions{$part}->{target};
1253         if ($target) {
1254             if ($target =~ m{/dev/(.)db(.*)}) {
1255                 $partitions{$part}->{target} = "/dev/$1da$2";
1256             } else {
1257                 die "internal error: unexpected partition target: $target";
1258             }
1259         }
1260     }
1261 }
1262
1263 sub expand_partitions
1264 {
1265     foreach my $part (@partitions)
1266     {
1267         unless ($partitions{$part}->{ignore}) {
1268             my $target = $partitions{$part}->{target};
1269             if ($target) {
1270                 # Expand if requested.
1271                 if ($partitions{$part}->{will_expand_content}) {
1272                     if (!$quiet && !$debug) {
1273                         print __x("Expanding {p} using the '{meth}' method\n",
1274                                   p => $part,
1275                                   meth => $partitions{$part}->{expand_content_method});
1276                     }
1277                     expand_target_partition ($part)
1278                 }
1279             }
1280         }
1281     }
1282 }
1283
1284 sub expand_target_partition
1285 {
1286     local $_;
1287     my $part = shift;
1288
1289     # Assertions.
1290     die unless $part;
1291     die unless $partitions{$part}->{can_expand_content};
1292     die unless $partitions{$part}->{will_expand_content};
1293     die unless $partitions{$part}->{expand_content_method};
1294     die unless $partitions{$part}->{target};
1295     die unless $expand_content;
1296
1297     my $target = $partitions{$part}->{target};
1298     my $method = $partitions{$part}->{expand_content_method};
1299     if ($method eq "pvresize") {
1300         $g->pvresize ($target);
1301     }
1302     elsif ($method eq "resize2fs") {
1303         $g->e2fsck_f ($target);
1304         $g->resize2fs ($target);
1305     }
1306     elsif ($method eq "ntfsresize") {
1307         $g->ntfsresize ($target);
1308     }
1309     else {
1310         die "internal error: unknown method: $method";
1311     }
1312 }
1313
1314 sub expand_lvs
1315 {
1316     local $_;
1317
1318     foreach (@lv_expand) {
1319         $g->lvresize_free ($_, 100);
1320     }
1321 }
1322
1323 sub expand_lvs_content
1324 {
1325     local $_;
1326
1327     foreach (@lvs) {
1328         if ($lvs{$_}->{will_expand_content}) {
1329             my $method = $lvs{$_}->{expand_content_method};
1330             if (!$quiet && !$debug) {
1331                 print __x("Expanding {p} using the '{meth}' method\n",
1332                           p => $_, meth => $method);
1333                     }
1334             if ($method eq "resize2fs") {
1335                 $g->e2fsck_f ($_);
1336                 $g->resize2fs ($_);
1337             } elsif ($method eq "ntfsresize") {
1338                 $g->ntfsresize ($_);
1339             } else {
1340                 die "internal error: unknown method: $method";
1341             }
1342         }
1343     }
1344 }
1345
1346 # Sync disk and exit.
1347 $g->umount_all ();
1348 $g->sync ();
1349 undef $g;
1350
1351 exit 0;
1352
1353 sub sizebytes
1354 {
1355     local $_ = shift;
1356     my $unit = shift;
1357
1358     $_ *= 1024 if $unit =~ /[KMGTPE]/;
1359     $_ *= 1024 if $unit =~ /[MGTPE]/;
1360     $_ *= 1024 if $unit =~ /[GTPE]/;
1361     $_ *= 1024 if $unit =~ /[TPE]/;
1362     $_ *= 1024 if $unit =~ /[PE]/;
1363     $_ *= 1024 if $unit =~ /[E]/;
1364
1365     return floor($_);
1366 }
1367
1368 # Convert a number of bytes to a human-readable number.
1369 sub human_size
1370 {
1371     local $_ = shift;
1372
1373     my $sgn = "";
1374     if ($_ < 0) {
1375         $sgn = "-";
1376         $_ = -$_;
1377     }
1378
1379     $_ /= 1024;
1380
1381     if ($_ < 1024) {
1382         sprintf "%s%dK", $sgn, $_;
1383     } elsif ($_ < 1024 * 1024) {
1384         sprintf "%s%.1fM", $sgn, ($_ / 1024);
1385     } else {
1386         sprintf "%s%.1fG", $sgn, ($_ / 1024 / 1024);
1387     }
1388 }
1389
1390 # The reverse of device name translation, see
1391 # BLOCK DEVICE NAMING in guestfs(3).
1392 sub canonicalize
1393 {
1394     local $_ = shift;
1395
1396     if (m{^/dev/[hv]d([a-z]\d*)$}) {
1397         return "/dev/sd$1";
1398     }
1399     $_;
1400 }
1401
1402 # Not as sophisticated as the guestfish progress bar, because
1403 # I intend to use an external library for this at some point (XXX).
1404 sub progress_callback
1405 {
1406     my $proc_nr = shift;
1407     my $serial = shift;
1408     my $position = shift;
1409     my $total = shift;
1410
1411     my $ratio = $position / $total;
1412     if ($ratio < 0) { $ratio = 0 }
1413     elsif ($ratio > 1) { $ratio = 1 }
1414
1415     my $dots = int ($ratio * 76);
1416
1417     print "[", "#"x$dots, "-"x(76-$dots), "]\r";
1418     print "\n" if $ratio == 1;
1419 }
1420
1421 =head1 NOTES
1422
1423 =head2 "Partition 1 does not end on cylinder boundary."
1424
1425 Virt-resize aligns partitions to multiples of 64 sectors.  Usually
1426 this means the partitions will not be aligned to the ancient CHS
1427 geometry.  However CHS geometry is meaningless for disks manufactured
1428 since the early 1990s, and doubly so for virtual hard drives.
1429 Alignment of partitions to cylinders is not required by any modern
1430 operating system.
1431
1432 =head2 RESIZING WINDOWS VIRTUAL MACHINES
1433
1434 In Windows Vista and later versions, Microsoft switched to using a
1435 separate boot partition.  In these VMs, typically C</dev/sda1> is the
1436 boot partition and C</dev/sda2> is the main (C:) drive.  We have not
1437 had any luck resizing the boot partition.  Doing so seems to break the
1438 guest completely.  However expanding the second partition (ie. C:
1439 drive) should work.
1440
1441 Windows may initiate a lengthy "chkdsk" on first boot after a resize,
1442 if NTFS partitions have been expanded.  This is just a safety check
1443 and (unless it find errors) is nothing to worry about.
1444
1445 =head2 GUEST BOOT STUCK AT "GRUB"
1446
1447 If a Linux guest does not boot after resizing, and the boot is stuck
1448 after printing C<GRUB> on the console, try reinstalling grub.  This
1449 sometimes happens on older (RHEL 5-era) guests, for reasons we don't
1450 fully understand, although we think is to do with partition alignment.
1451
1452  guestfish -i -a newdisk
1453  ><fs> cat /boot/grub/device.map
1454  # check the contents of this file are sensible or
1455  # edit the file if necessary
1456  ><fs> grub-install / /dev/vda
1457  ><fs> exit
1458
1459 For more flexible guest reconfiguration, including if you need to
1460 specify other parameters to grub-install, use L<virt-rescue(1)>.
1461
1462 =head1 ALTERNATIVE TOOLS
1463
1464 There are several proprietary tools for resizing partitions.  We
1465 won't mention any here.
1466
1467 L<parted(8)> and its graphical shell gparted can do some types of
1468 resizing operations on disk images.  They can resize and move
1469 partitions, but I don't think they can do anything with the contents,
1470 and they certainly don't understand LVM.
1471
1472 L<guestfish(1)> can do everything that virt-resize can do and a lot
1473 more, but at a much lower level.  You will probably end up
1474 hand-calculating sector offsets, which is something that virt-resize
1475 was designed to avoid.  If you want to see the guestfish-equivalent
1476 commands that virt-resize runs, use the C<--debug> flag.
1477
1478 =head1 SHELL QUOTING
1479
1480 Libvirt guest names can contain arbitrary characters, some of which
1481 have meaning to the shell such as C<#> and space.  You may need to
1482 quote or escape these characters on the command line.  See the shell
1483 manual page L<sh(1)> for details.
1484
1485 =head1 SEE ALSO
1486
1487 L<virt-filesystems(1)>,
1488 L<virt-df(1)>,
1489 L<guestfs(3)>,
1490 L<guestfish(1)>,
1491 L<lvm(8)>,
1492 L<pvresize(8)>,
1493 L<lvresize(8)>,
1494 L<resize2fs(8)>,
1495 L<ntfsresize(8)>,
1496 L<virsh(1)>,
1497 L<parted(8)>,
1498 L<truncate(1)>,
1499 L<fallocate(1)>,
1500 L<grub(8)>,
1501 L<grub-install(8)>,
1502 L<virt-rescue(1)>,
1503 L<Sys::Guestfs(3)>,
1504 L<http://libguestfs.org/>.
1505
1506 =head1 AUTHOR
1507
1508 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
1509
1510 =head1 COPYRIGHT
1511
1512 Copyright (C) 2010 Red Hat Inc.
1513
1514 This program is free software; you can redistribute it and/or modify
1515 it under the terms of the GNU General Public License as published by
1516 the Free Software Foundation; either version 2 of the License, or
1517 (at your option) any later version.
1518
1519 This program is distributed in the hope that it will be useful,
1520 but WITHOUT ANY WARRANTY; without even the implied warranty of
1521 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1522 GNU General Public License for more details.
1523
1524 You should have received a copy of the GNU General Public License
1525 along with this program; if not, write to the Free Software
1526 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.