3 # Copyright (C) 2010 Red Hat Inc.
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.
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.
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.
23 use Sys::Guestfs::Lib qw(open_guest);
26 use Locale::TextDomain 'libguestfs';
32 virt-list-partitions - List partitions in a virtual machine or disk image
36 virt-list-partitions [--options] domname
38 virt-list-partitions [--options] disk.img [disk.img ...]
42 C<virt-list-partitions> is a command line tool to list
43 the partitions that are contained in a virtual machine or
44 disk image. It is mainly useful as a first step to using
47 C<virt-list-partitions> is just a simple wrapper around
48 L<libguestfs(3)> functionality. For more complex cases you should
49 look at the L<guestfish(1)> tool.
69 Display version number and exit.
75 =item B<--connect URI> | B<-c URI>
77 If using libvirt, connect to the given I<URI>. If omitted, then we
78 connect to the default libvirt hypervisor.
80 If you specify guest block devices directly, then libvirt is not used
87 =item B<-l> | B<--long>
89 With this option, C<virt-list-partitions> displays the type
90 and size of each partition too (where "type" means C<ext3>, C<pv> etc.)
96 =item B<-h> | B<--human-readable>
98 Show sizes in human-readable form (eg. "1G").
104 # Configure bundling, otherwise '-lh' is unrecognized.
105 Getopt::Long::Configure ("bundling");
107 GetOptions ("help|?" => \$help,
108 "version" => \$version,
109 "connect|c=s" => \$uri,
111 "human-readable|h" => \$human,
113 pod2usage (1) if $help;
115 my $g = Sys::Guestfs->new ();
116 my %h = $g->version ();
117 print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
121 pod2usage (__"virt-list-partitions: no image or VM name given")
126 $g = open_guest (\@ARGV, address => $uri);
128 $g = open_guest (\@ARGV);
133 # List of partitions and sizes.
135 my @devices = $g->list_devices ();
136 foreach my $dev (@devices) {
137 my @p = $g->part_list ($dev);
139 $_->{name} = canonicalize ("$dev" . $_->{part_num});
140 push @partitions, $_;
145 foreach my $part (@partitions) {
151 $type = $g->vfs_type ($part->{name});
154 $type = "pv" if $type eq "LVM2_member";
157 print (human_size($part->{part_size}));
159 print $part->{part_size};
165 # The reverse of device name translation, see
166 # BLOCK DEVICE NAMING in guestfs(3).
171 if (m{^/dev/[hv]d([a-z]\d)$}) {
177 # Convert a number of bytes to a human-readable number.
186 } elsif ($_ < 1024 * 1024) {
187 sprintf "%.1fM", ($_ / 1024);
189 sprintf "%.1fG", ($_ / 1024 / 1024);
197 L<virt-list-filesystems(1)>,
200 L<Sys::Guestfs::Lib(3)>,
202 L<http://libguestfs.org/>.
206 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
210 Copyright (C) 2009 Red Hat Inc.
212 This program is free software; you can redistribute it and/or modify
213 it under the terms of the GNU General Public License as published by
214 the Free Software Foundation; either version 2 of the License, or
215 (at your option) any later version.
217 This program is distributed in the hope that it will be useful,
218 but WITHOUT ANY WARRANTY; without even the implied warranty of
219 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
220 GNU General Public License for more details.
222 You should have received a copy of the GNU General Public License
223 along with this program; if not, write to the Free Software
224 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.