X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=tools%2Fvirt-make-fs;h=d4e231be06b282ac35bbfb91f8176f2ae6ddcf8d;hp=3825f70197db3b30b4671ffaf5d418662fb0ccef;hb=04ea1375c55aa67df4e7fc61dbb534111767f3b6;hpb=29b3ffdad5d6774f988fd0e25f9c8242e5dd577a diff --git a/tools/virt-make-fs b/tools/virt-make-fs index 3825f70..d4e231b 100755 --- a/tools/virt-make-fs +++ b/tools/virt-make-fs @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # virt-make-fs -# Copyright (C) 2010 Red Hat Inc. +# Copyright (C) 2010-2011 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use warnings; use strict; @@ -56,39 +56,13 @@ data to a VM). Basic usage is: - virt-make-fs input output + virt-make-fs input output.img where C is either a directory containing files that you want to add, or a tar archive (either uncompressed tar or gzip-compressed -tar); and C is a disk image. The input type is detected -automatically. The output disk image defaults to a raw ext2 image -unless you specify extra flags (see L below). - -=head2 EXTRA SPACE - -Unlike formats such as tar and squashfs, a filesystem does not "just -fit" the files that it contains, but might have extra space. -Depending on how you are going to use the output, you might think this -extra space is wasted and want to minimize it, or you might want to -leave space so that more files can be added later. Virt-make-fs -defaults to minimizing the extra space, but you can use the C<--size> -flag to leave space in the filesystem if you want it. - -An alternative way to leave extra space but not make the output image -any bigger is to use an alternative disk image format (instead of the -default "raw" format). Using C<--format=qcow2> will use the native -QEmu/KVM qcow2 image format (check your hypervisor supports this -before using it). This allows you to choose a large C<--size> but the -extra space won't actually be allocated in the image until you try to -store something in it. - -Don't forget that you can also use local commands including -L and L to resize existing filesystems, -or rerun virt-make-fs to build another image from scratch. - -=head3 EXAMPLE - - virt-make-fs --format=qcow2 --size=+200M input output.img +tar); and C is a disk image. The input type is detected +automatically. The output disk image defaults to a raw ext2 sparse +image unless you specify extra flags (see L below). =head2 FILESYSTEM TYPE @@ -150,6 +124,32 @@ better to use an EFI/GPT-compatible partition table: virt-make-fs --partition=gpt --size=+4T --format=qcow2 input disk.img +=head2 EXTRA SPACE + +Unlike formats such as tar and squashfs, a filesystem does not "just +fit" the files that it contains, but might have extra space. +Depending on how you are going to use the output, you might think this +extra space is wasted and want to minimize it, or you might want to +leave space so that more files can be added later. Virt-make-fs +defaults to minimizing the extra space, but you can use the I<--size> +flag to leave space in the filesystem if you want it. + +An alternative way to leave extra space but not make the output image +any bigger is to use an alternative disk image format (instead of the +default "raw" format). Using I<--format=qcow2> will use the native +QEmu/KVM qcow2 image format (check your hypervisor supports this +before using it). This allows you to choose a large I<--size> but the +extra space won't actually be allocated in the image until you try to +store something in it. + +Don't forget that you can also use local commands including +L and L to resize existing filesystems, +or rerun virt-make-fs to build another image from scratch. + +=head3 EXAMPLE + + virt-make-fs --format=qcow2 --size=+200M input output.img + =head1 OPTIONS =over 4 @@ -190,7 +190,7 @@ my $size; =item B<-s +ENE> -Use the C<--size> (or C<-s>) option to choose the size of the output +Use the I<--size> (or I<-s>) option to choose the size of the output image. If this option is I given, then the output image will be just @@ -203,7 +203,7 @@ enough to contain all the input files, else you will get an error. To leave extra space, specify C<+> (plus sign) and a number followed by b/K/M/G/T/P/E to mean bytes, Kilobytes, Megabytes, Gigabytes, -Terabytes, Petabytes or Exabytes. For example: C<--size=+200M> means +Terabytes, Petabytes or Exabytes. For example: I<--size=+200M> means enough space for the input files, and (approximately) an extra 200 MB free space. @@ -222,7 +222,7 @@ my $format = "raw"; Choose the output disk image format. -The default is C (raw disk image). +The default is C (raw sparse disk image). For other choices, see the L manpage. The only other choice that would really make sense here is C. @@ -253,20 +253,22 @@ my $partition; If specified, this flag adds an MBR partition table to the output disk image. -You can change the partition table type, eg. C<--partition=gpt> for +You can change the partition table type, eg. I<--partition=gpt> for large disks. -Note that if you just use a lonesome C<--partition>, the Perl option +Note that if you just use a lonesome I<--partition>, the Perl option parser might consider the next parameter to be the partition type. For example: - virt-make-fs --partition input.tar ... + virt-make-fs --partition input.tar output.img would cause virt-make-fs to think you wanted to use a partition type -of C which is completely wrong. To avoid this, use C<--> -(a double dash) between options and the input file argument: +of C which is completely wrong. To avoid this, use I<--> +(a double dash) between options and the input and output arguments: + + virt-make-fs --partition -- input.tar output.img - virt-make-fs --partition -- input.tar ... +For MBR, virt-make-fs sets the partition type byte automatically. =back @@ -393,6 +395,8 @@ if (!defined $size) { } } +$size = int ($size); + # Create the output disk. # Take the unusual step of invoking qemu-img here. @@ -421,6 +425,22 @@ eval { $partition = "mbr" if $partition eq ""; $g->part_disk ($dev, $partition); $dev = "/dev/sda1"; + + # Set the partition type byte if it's MBR and the filesystem + # type is one that we know about. + my $mbr_id; + if ($partition eq "mbr") { + if ($type =~ /^v?fat$/) { + $mbr_id = 0xb; + } elsif ($type eq "ntfs") { + $mbr_id = 0x7; + } elsif ($type =~ /^ext\d$/) { + $mbr_id = 0x83; + } elsif ($type eq "minix") { + $mbr_id = 0x81; + } + } + $g->part_set_mbr_id ("/dev/sda", 1, $mbr_id) if defined $mbr_id; } print STDERR "creating $type filesystem on $dev ...\n" if $debug; @@ -565,7 +585,7 @@ Richard W.M. Jones L =head1 COPYRIGHT -Copyright (C) 2010 Red Hat Inc. +Copyright (C) 2010-2011 Red Hat Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -579,4 +599,4 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.