3 # Copyright (C) 2009 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 get_partitions resolve_windows_path
24 inspect_all_partitions inspect_partition
25 inspect_operating_systems mount_operating_system);
28 use Locale::TextDomain 'libguestfs';
34 virt-cat - Display a file in a virtual machine
38 virt-cat [--options] domname file
40 virt-cat [--options] disk.img [disk.img ...] file
44 C<virt-cat> is a command line tool to display the contents of C<file>
45 where C<file> exists in the named virtual machine (or disk image).
47 C<virt-cat> can be used to quickly view a single file. To edit a
48 file, use C<virt-edit>. For more complex cases you should look at the
53 Display C</etc/fstab> file from inside the libvirt VM called
56 virt-cat mydomain /etc/fstab
58 List syslog messages from a VM:
60 virt-cat mydomain /var/log/messages | tail
62 Find out what DHCP IP address a VM acquired:
64 virt-cat mydomain /var/log/messages | grep 'dhclient: bound to' | tail
66 Find out what packages were recently installed:
68 virt-cat mydomain /var/log/yum.log | tail
70 Find out who is logged on inside a virtual machine:
72 virt-cat mydomain /var/run/utmp > /tmp/utmp
77 virt-cat mydomain /var/log/wtmp > /tmp/wtmp
98 Display version number and exit.
104 =item B<--connect URI> | B<-c URI>
106 If using libvirt, connect to the given I<URI>. If omitted, then we
107 connect to the default libvirt hypervisor.
109 If you specify guest block devices directly, then libvirt is not used
116 =item B<--format> raw
118 Specify the format of disk images given on the command line. If this
119 is omitted then the format is autodetected from the content of the
122 If disk images are requested from libvirt, then this program asks
123 libvirt for this information. In this case, the value of the format
124 parameter is ignored.
126 If working with untrusted raw-format guest disk images, you should
127 ensure the format is always specified.
133 GetOptions ("help|?" => \$help,
134 "version" => \$version,
135 "connect|c=s" => \$uri,
136 "format=s" => \$format,
138 pod2usage (1) if $help;
140 my $g = Sys::Guestfs->new ();
141 my %h = $g->version ();
142 print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
146 pod2usage (__"virt-cat: no image, VM names or filenames to cat given")
149 my $filename = pop @ARGV;
153 $g = open_guest (\@ARGV, address => $uri, format => $format);
155 $g = open_guest (\@ARGV, format => $format);
160 # List of possible filesystems.
161 my @partitions = get_partitions ($g);
163 # Now query each one to build up a picture of what's in it.
165 inspect_all_partitions ($g, \@partitions,
166 use_windows_registry => 0);
168 my $oses = inspect_operating_systems ($g, \%fses);
170 my @roots = keys %$oses;
171 die __"multiboot operating systems are not supported by virt-cat" if @roots > 1;
172 my $root_dev = $roots[0];
174 my $os = $oses->{$root_dev};
175 mount_operating_system ($g, $os);
177 # Allow this to fail in case eg. the file does not exist.
178 # NB: https://bugzilla.redhat.com/show_bug.cgi?id=501888
179 print $g->download($filename, "/dev/stdout");
183 Libvirt guest names can contain arbitrary characters, some of which
184 have meaning to the shell such as C<#> and space. You may need to
185 quote or escape these characters on the command line. See the shell
186 manual page L<sh(1)> for details.
194 L<Sys::Guestfs::Lib(3)>,
196 L<http://libguestfs.org/>.
200 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
204 Copyright (C) 2009 Red Hat Inc.
206 This program is free software; you can redistribute it and/or modify
207 it under the terms of the GNU General Public License as published by
208 the Free Software Foundation; either version 2 of the License, or
209 (at your option) any later version.
211 This program is distributed in the hope that it will be useful,
212 but WITHOUT ANY WARRANTY; without even the implied warranty of
213 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
214 GNU General Public License for more details.
216 You should have received a copy of the GNU General Public License
217 along with this program; if not, write to the Free Software
218 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.