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 This tool is obsolete. Use L<virt-filesystems(1)> as a more
45 C<virt-list-partitions> is a command line tool to list
46 the partitions that are contained in a virtual machine or
47 disk image. It is mainly useful as a first step to using
50 C<virt-list-partitions> is just a simple wrapper around
51 L<libguestfs(3)> functionality. For more complex cases you should
52 look at the L<guestfish(1)> tool.
72 Display version number and exit.
78 =item B<--connect URI> | B<-c URI>
80 If using libvirt, connect to the given I<URI>. If omitted, then we
81 connect to the default libvirt hypervisor.
83 If you specify guest block devices directly, then libvirt is not used
92 Specify the format of disk images given on the command line. If this
93 is omitted then the format is autodetected from the content of the
96 If disk images are requested from libvirt, then this program asks
97 libvirt for this information. In this case, the value of the format
100 If working with untrusted raw-format guest disk images, you should
101 ensure the format is always specified.
107 =item B<-h> | B<--human-readable>
109 Show sizes in human-readable form (eg. "1G").
115 =item B<-l> | B<--long>
117 With this option, C<virt-list-partitions> displays the type
118 and size of each partition too (where "type" means C<ext3>, C<pv> etc.)
124 =item B<-t> | B<--total>
126 Display the total size of each block device (as a separate row or
133 # Configure bundling, otherwise '-lh' is unrecognized.
134 Getopt::Long::Configure ("bundling");
136 GetOptions ("help|?" => \$help,
137 "version" => \$version,
138 "connect|c=s" => \$uri,
139 "format=s" => \$format,
140 "human-readable|h" => \$human,
142 "total|t" => \$total,
144 pod2usage (1) if $help;
146 my $g = Sys::Guestfs->new ();
147 my %h = $g->version ();
148 print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
152 pod2usage (__"virt-list-partitions: no image or VM name given")
157 $g = open_guest (\@ARGV, address => $uri, format => $format);
159 $g = open_guest (\@ARGV, format => $format);
164 # List of partitions and sizes.
165 my @partitions = $g->list_partitions ();
166 foreach my $name (@partitions) {
167 $name = canonicalize ($name);
174 $type = $g->vfs_type ($name);
177 $type = "pv" if $type eq "LVM2_member";
182 $size = $g->blockdev_getsize64 ($name);
187 print (human_size($size));
196 # List of devices and sizes.
197 my @devices = $g->list_devices ();
198 foreach my $name (@devices) {
199 $name = canonicalize ($name);
208 $size = $g->blockdev_getsize64 ($name);
213 print (human_size($size));
222 # The reverse of device name translation, see
223 # BLOCK DEVICE NAMING in guestfs(3).
228 if (m{^/dev/[hv]d([a-z]+\d*)$}) {
234 # Convert a number of bytes to a human-readable number.
243 } elsif ($_ < 1024 * 1024) {
244 sprintf "%.1fM", ($_ / 1024);
246 sprintf "%.1fG", ($_ / 1024 / 1024);
252 Libvirt guest names can contain arbitrary characters, some of which
253 have meaning to the shell such as C<#> and space. You may need to
254 quote or escape these characters on the command line. See the shell
255 manual page L<sh(1)> for details.
261 L<virt-filesystems(1)>,
262 L<virt-list-filesystems(1)>,
265 L<Sys::Guestfs::Lib(3)>,
267 L<http://libguestfs.org/>.
271 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
275 Copyright (C) 2009-2010 Red Hat Inc.
277 This program is free software; you can redistribute it and/or modify
278 it under the terms of the GNU General Public License as published by
279 the Free Software Foundation; either version 2 of the License, or
280 (at your option) any later version.
282 This program is distributed in the hope that it will be useful,
283 but WITHOUT ANY WARRANTY; without even the implied warranty of
284 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
285 GNU General Public License for more details.
287 You should have received a copy of the GNU General Public License
288 along with this program; if not, write to the Free Software
289 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.