tools: Make warnings about running on live guests more prominent.
[libguestfs.git] / tools / virt-rescue
1 #!/usr/bin/perl -w
2 # virt-rescue
3 # Copyright (C) 2009 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-rescue - Run a rescue shell on a virtual machine
33
34 =head1 SYNOPSIS
35
36  virt-rescue [--options] domname
37
38  virt-rescue [--options] disk.img [disk.img ...]
39
40 =head1 WARNING
41
42 You must I<not> use C<virt-rescue> on live virtual machines.  Doing so
43 will probably result in disk corruption in the VM.  C<virt-rescue>
44 tries to stop you from doing this, but doesn't catch all cases.
45
46 However if you use the I<--ro> (read only) option, then you can attach
47 a shell to a live virtual machine, but the results might be strange or
48 inconsistent at times (but you won't get disk corruption).
49
50 =head1 DESCRIPTION
51
52 virt-rescue gives you a rescue shell and some simple recovery tools
53 which you can use on a virtual machine disk image.
54
55 After running virt-rescue, what you see under C</> is the recovery
56 appliance.  You must mount the virtual machine's filesystems by hand,
57 eg:
58
59  # lvs
60  LV      VG        Attr   LSize   Origin Snap%  Move Log Copy%  Convert
61  lv_root vg_f11x64 -wi-a-   8.83G
62  lv_swap vg_f11x64 -wi-a- 992.00M
63  # mount /dev/vg_f11x64/lv_root /sysroot
64  # ls /sysroot
65
66 This tool is just designed for quick interactive hacking on a virtual
67 machine.  For more structured access to a virtual machine disk image,
68 you should use L<guestfs(3)>.  To get a structured shell, use
69 L<guestfish(1)>.
70
71 =head1 OPTIONS
72
73 =over 4
74
75 =cut
76
77 my $help;
78
79 =item B<--help>
80
81 Display brief help.
82
83 =cut
84
85 my $version;
86
87 =item B<--version>
88
89 Display version number and exit.
90
91 =cut
92
93 my $uri;
94
95 =item B<--connect URI> | B<-c URI>
96
97 If using libvirt, connect to the given I<URI>.  If omitted, then we
98 connect to the default libvirt hypervisor.
99
100 If you specify guest block devices directly, then libvirt is not used
101 at all.
102
103 =cut
104
105 my $readonly;
106
107 =item B<--ro> | B<-r>
108
109 Open the image read-only.
110
111 =back
112
113 =cut
114
115 GetOptions ("help|?" => \$help,
116             "version" => \$version,
117             "connect|c=s" => \$uri,
118             "ro|r" => \$readonly,
119     ) or pod2usage (2);
120 pod2usage (1) if $help;
121 if ($version) {
122     my $g = Sys::Guestfs->new ();
123     my %h = $g->version ();
124     print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
125     exit
126 }
127
128 pod2usage (__"virt-rescue: no image or VM names rescue given")
129     if @ARGV == 0;
130
131 my @args = (\@ARGV);
132 push @args, address => $uri if $uri;
133 push @args, rw => 1 unless $readonly;
134 my $g = open_guest (@args);
135
136 $g->set_direct (1);
137 $g->set_append ("guestfs_rescue=1");
138
139 $g->launch ();
140
141 exit 0;
142
143 =head1 SEE ALSO
144
145 L<guestfs(3)>,
146 L<guestfish(1)>,
147 L<virt-cat(1)>,
148 L<Sys::Guestfs(3)>,
149 L<Sys::Guestfs::Lib(3)>,
150 L<Sys::Virt(3)>,
151 L<http://libguestfs.org/>.
152
153 =head1 AUTHOR
154
155 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
156
157 =head1 COPYRIGHT
158
159 Copyright (C) 2009 Red Hat Inc.
160
161 This program is free software; you can redistribute it and/or modify
162 it under the terms of the GNU General Public License as published by
163 the Free Software Foundation; either version 2 of the License, or
164 (at your option) any later version.
165
166 This program is distributed in the hope that it will be useful,
167 but WITHOUT ANY WARRANTY; without even the implied warranty of
168 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169 GNU General Public License for more details.
170
171 You should have received a copy of the GNU General Public License
172 along with this program; if not, write to the Free Software
173 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.