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.
80 =item B<--connect URI>
82 If using libvirt, connect to the given I<URI>. If omitted, then we
83 connect to the default libvirt hypervisor.
85 If you specify guest block devices directly, then libvirt is not used
94 Specify the format of disk images given on the command line. If this
95 is omitted then the format is autodetected from the content of the
98 If disk images are requested from libvirt, then this program asks
99 libvirt for this information. In this case, the value of the format
100 parameter is ignored.
102 If working with untrusted raw-format guest disk images, you should
103 ensure the format is always specified.
111 =item B<--human-readable>
113 Show sizes in human-readable form (eg. "1G").
123 With this option, C<virt-list-partitions> displays the type
124 and size of each partition too (where "type" means C<ext3>, C<pv> etc.)
134 Display the total size of each block device (as a separate row or
141 # Configure bundling, otherwise '-lh' is unrecognized.
142 Getopt::Long::Configure ("bundling");
144 GetOptions ("help|?" => \$help,
145 "version" => \$version,
146 "connect|c=s" => \$uri,
147 "format=s" => \$format,
148 "human-readable|h" => \$human,
150 "total|t" => \$total,
152 pod2usage (1) if $help;
154 my $g = Sys::Guestfs->new ();
155 my %h = $g->version ();
156 print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
160 pod2usage (__"virt-list-partitions: no image or VM name given")
165 $g = open_guest (\@ARGV, address => $uri, format => $format);
167 $g = open_guest (\@ARGV, format => $format);
172 # List of partitions and sizes.
173 my @partitions = $g->list_partitions ();
174 foreach my $name (@partitions) {
175 $name = canonicalize ($name);
182 $type = $g->vfs_type ($name);
185 $type = "pv" if $type eq "LVM2_member";
190 $size = $g->blockdev_getsize64 ($name);
195 print (human_size($size));
204 # List of devices and sizes.
205 my @devices = $g->list_devices ();
206 foreach my $name (@devices) {
207 $name = canonicalize ($name);
216 $size = $g->blockdev_getsize64 ($name);
221 print (human_size($size));
230 # The reverse of device name translation, see
231 # BLOCK DEVICE NAMING in guestfs(3).
236 if (m{^/dev/[hv]d([a-z]+\d*)$}) {
242 # Convert a number of bytes to a human-readable number.
251 } elsif ($_ < 1024 * 1024) {
252 sprintf "%.1fM", ($_ / 1024);
254 sprintf "%.1fG", ($_ / 1024 / 1024);
260 Libvirt guest names can contain arbitrary characters, some of which
261 have meaning to the shell such as C<#> and space. You may need to
262 quote or escape these characters on the command line. See the shell
263 manual page L<sh(1)> for details.
269 L<virt-filesystems(1)>,
270 L<virt-list-filesystems(1)>,
273 L<Sys::Guestfs::Lib(3)>,
275 L<http://libguestfs.org/>.
279 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
283 Copyright (C) 2009-2010 Red Hat Inc.
285 This program is free software; you can redistribute it and/or modify
286 it under the terms of the GNU General Public License as published by
287 the Free Software Foundation; either version 2 of the License, or
288 (at your option) any later version.
290 This program is distributed in the hope that it will be useful,
291 but WITHOUT ANY WARRANTY; without even the implied warranty of
292 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
293 GNU General Public License for more details.
295 You should have received a copy of the GNU General Public License
296 along with this program; if not, write to the Free Software
297 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.