New tools: virt-copy-in, virt-copy-out, virt-tar-in, virt-tar-out.
[libguestfs.git] / tools / virt-list-filesystems
1 #!/usr/bin/perl -w
2 # virt-list-filesystems
3 # Copyright (C) 2009-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(open_guest);
24 use Pod::Usage;
25 use Getopt::Long;
26 use Locale::TextDomain 'libguestfs';
27
28 =encoding utf8
29
30 =head1 NAME
31
32 virt-list-filesystems - List filesystems in a virtual machine or disk image
33
34 =head1 SYNOPSIS
35
36  virt-list-filesystems [--options] domname
37
38  virt-list-filesystems [--options] disk.img [disk.img ...]
39
40 =head1 DESCRIPTION
41
42 This tool is obsolete.  Use L<virt-filesystems(1)> as a more
43 flexible replacement.
44
45 C<virt-list-filesystems> is a command line tool to list
46 the filesystems that are contained in a virtual machine or
47 disk image.
48
49 C<virt-list-filesystems> is just a simple wrapper around
50 L<libguestfs(3)> functionality.  For more complex cases you should
51 look at the L<guestfish(1)> tool.
52
53 =head1 OPTIONS
54
55 =over 4
56
57 =cut
58
59 my $help;
60
61 =item B<--help>
62
63 Display brief help.
64
65 =cut
66
67 my $version;
68
69 =item B<--version>
70
71 Display version number and exit.
72
73 =cut
74
75 my $uri;
76
77 =item B<--connect URI> | B<-c URI>
78
79 If using libvirt, connect to the given I<URI>.  If omitted, then we
80 connect to the default libvirt hypervisor.
81
82 If you specify guest block devices directly, then libvirt is not used
83 at all.
84
85 =cut
86
87 my $format;
88
89 =item B<--format> raw
90
91 Specify the format of disk images given on the command line.  If this
92 is omitted then the format is autodetected from the content of the
93 disk image.
94
95 If disk images are requested from libvirt, then this program asks
96 libvirt for this information.  In this case, the value of the format
97 parameter is ignored.
98
99 If working with untrusted raw-format guest disk images, you should
100 ensure the format is always specified.
101
102 =cut
103
104 my $long;
105
106 =item B<-l> | B<--long>
107
108 With this option, C<virt-list-filesystems> displays the type of
109 each filesystem too (where "type" means C<ext3>, C<xfs> etc.)
110
111 =cut
112
113 my $all;
114
115 =item B<-a> | B<--all>
116
117 Normally we only show mountable filesystems.  If this option
118 is given then swap devices are shown too.
119
120 =back
121
122 =cut
123
124 # Configure bundling, otherwise '-al' is treated as '--all'.
125 Getopt::Long::Configure ("bundling");
126
127 GetOptions ("help|?" => \$help,
128             "version" => \$version,
129             "connect|c=s" => \$uri,
130             "format=s" => \$format,
131             "long|l" => \$long,
132             "all|a" => \$all,
133     ) or pod2usage (2);
134 pod2usage (1) if $help;
135 if ($version) {
136     my $g = Sys::Guestfs->new ();
137     my %h = $g->version ();
138     print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
139     exit
140 }
141
142 pod2usage (__"virt-list-filesystems: no image or VM name given")
143     if @ARGV <= 0;
144
145 my $g;
146 if ($uri) {
147     $g = open_guest (\@ARGV, address => $uri, format => $format);
148 } else {
149     $g = open_guest (\@ARGV, format => $format);
150 }
151
152 $g->launch ();
153
154 # List of filesystems.
155 my %fses = $g->list_filesystems ();
156
157 my ($dev, $fstype);
158 foreach $dev (sort keys %fses) {
159     $fstype = $fses{$dev};
160
161     if ($all || ($fstype ne "swap" && $fstype ne "unknown")) {
162         print canonicalize($dev);
163         if ($long) {
164             print " $fstype";
165         }
166         print "\n";
167     }
168 }
169
170 # The reverse of device name translation, see
171 # BLOCK DEVICE NAMING in guestfs(3).
172 sub canonicalize
173 {
174     local $_ = shift;
175
176     if (m{^/dev/[hv]d([a-z]\d)$}) {
177         return "/dev/sd$1";
178     }
179     $_;
180 }
181
182 =head1 SHELL QUOTING
183
184 Libvirt guest names can contain arbitrary characters, some of which
185 have meaning to the shell such as C<#> and space.  You may need to
186 quote or escape these characters on the command line.  See the shell
187 manual page L<sh(1)> for details.
188
189 =head1 SEE ALSO
190
191 L<guestfs(3)>,
192 L<guestfish(1)>,
193 L<virt-cat(1)>,
194 L<virt-tar(1)>,
195 L<virt-filesystems(1)>,
196 L<virt-list-partitions(1)>,
197 L<Sys::Guestfs(3)>,
198 L<Sys::Guestfs::Lib(3)>,
199 L<Sys::Virt(3)>,
200 L<http://libguestfs.org/>.
201
202 =head1 AUTHOR
203
204 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
205
206 =head1 COPYRIGHT
207
208 Copyright (C) 2009 Red Hat Inc.
209
210 This program is free software; you can redistribute it and/or modify
211 it under the terms of the GNU General Public License as published by
212 the Free Software Foundation; either version 2 of the License, or
213 (at your option) any later version.
214
215 This program is distributed in the hope that it will be useful,
216 but WITHOUT ANY WARRANTY; without even the implied warranty of
217 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
218 GNU General Public License for more details.
219
220 You should have received a copy of the GNU General Public License
221 along with this program; if not, write to the Free Software
222 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.