Docs: Add "API Overview" section to guestfs(3) manpage.
[libguestfs.git] / v2v / virt-v2v.pl
1 #!/usr/bin/perl -w
2 # virt-v2v
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 get_partitions resolve_windows_path
24   inspect_all_partitions inspect_partition
25   inspect_operating_systems mount_operating_system inspect_in_detail);
26 use Pod::Usage;
27 use Getopt::Long;
28 use Data::Dumper;
29 use File::Temp qw/tempdir/;
30 use XML::Writer;
31 use Locale::TextDomain 'libguestfs';
32
33 =encoding utf8
34
35 =head1 NAME
36
37 virt-v2v - Convert Xen or VMWare guests to KVM
38
39 =head1 SYNOPSIS
40
41  virt-v2v xen_name -o kvm_name
42
43  virt-v2v guest.ovf.zip -o kvm_name
44
45  virt-v2v guest.img [guest.img ...]
46
47 =head1 DESCRIPTION
48
49 Virt-v2v converts guests from one virtualization hypervisor to
50 another.  Currently it is limited in what it can convert.  See the
51 table below.
52
53  -------------------------------+----------------------------
54  SOURCE                         | TARGET
55  -------------------------------+----------------------------
56  Xen domain managed by          |
57  libvirt                        |
58                                 |
59  Xen compatibility:             |
60    - PV or FV kernel            |  KVM guest managed by
61    - with or without PV drivers |  libvirt
62    - RHEL 3.9+, 4.8+, 5.3+      |    - with virtio drivers
63    - Windows XP, 2003           |
64                                 |
65  -------------------------------+
66                                 |
67  VMWare VMDK image with         |
68  OVF metadata, exported from    |
69  vSphere                        |
70                                 |
71  VMWare compatibility:          |
72    - RHEL 3.9+, 4.8+, 5.3+      |
73    - VMWare tools               |
74                                 |
75  -------------------------------+----------------------------
76
77 =head2 CONVERTING XEN DOMAINS
78
79 For Xen domains managed by libvirt, perform the initial conversion
80 using:
81
82  virt-v2v xen_name -o kvm_name
83
84 where C<xen_name> is the libvirt Xen domain name, and C<kvm_name> is
85 the (new) name for the converted KVM guest.
86
87 Then test boot the new guest in KVM:
88
89  virsh start kvm_name
90  virt-viewer kvm_name
91
92 When you have verified that this works, shut down the new KVM domain
93 and I<commit> the changes by doing:
94
95  virt-v2v --commit kvm_name
96
97 I<This command will destroy the original Xen domain>.
98
99 Or you can I<rollback> to the original Xen domain by doing:
100
101  virt-v2v --rollback kvm_name
102
103 B<Very important note:> Do I<not> try to run both the original Xen
104 domain and the KVM domain at the same time!  This will cause guest
105 corruption.
106
107 =head2 CONVERTING VMWARE GUESTS
108
109 I<This section to be written>
110
111
112
113
114
115 =head1 OPTIONS
116
117 =over 4
118
119 =cut
120
121 my $help;
122
123 =item B<--help>
124
125 Display brief help.
126
127 =cut
128
129 my $version;
130
131 =item B<--version>
132
133 Display version number and exit.
134
135 =cut
136
137 my $uri;
138
139 =item B<--connect URI> | B<-c URI>
140
141 If using libvirt, connect to the given I<URI>.  If omitted,
142 then we connect to the default libvirt hypervisor.
143
144 Libvirt is only used if you specify a C<domname> on the
145 command line.  If you specify guest block devices directly,
146 then libvirt is not used at all.
147
148 =cut
149
150 my $output;
151
152 =item B<--output name> | B<-o name>
153
154 Set the output guest name.
155
156 =cut
157
158 =back
159
160 =cut
161
162 GetOptions ("help|?" => \$help,
163             "version" => \$version,
164             "connect|c=s" => \$uri,
165             "output|o=s" => \$output,
166     ) or pod2usage (2);
167 pod2usage (1) if $help;
168 if ($version) {
169     my $g = Sys::Guestfs->new ();
170     my %h = $g->version ();
171     print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
172     exit
173 }
174 pod2usage (__"virt-v2v: no image or VM names given") if @ARGV == 0;
175
176 # XXX This should be an option.  Disable for now until we get
177 # downloads working reliably.
178 my $use_windows_registry = 0;
179
180 my @params = (\@ARGV);
181 if ($uri) {
182     push @params, address => $uri;
183 }
184 my ($g, $conn, $dom) = open_guest (@params);
185
186 $g->launch ();
187 $g->wait_ready ();
188
189 # List of possible filesystems.
190 my @partitions = get_partitions ($g);
191
192 # Now query each one to build up a picture of what's in it.
193 my %fses =
194     inspect_all_partitions ($g, \@partitions,
195                             use_windows_registry => $use_windows_registry);
196
197 #print "fses -----------\n";
198 #print Dumper(\%fses);
199
200 my $oses = inspect_operating_systems ($g, \%fses);
201
202 #print "oses -----------\n";
203 #print Dumper($oses);
204
205 # Only work on single-root operating systems.
206 my $root_dev;
207 my @roots = keys %$oses;
208 die __"no root device found in this operating system image" if @roots == 0;
209 die __"multiboot operating systems are not supported by v2v" if @roots > 1;
210 $root_dev = $roots[0];
211
212 # Mount up the disks and check for applications.
213
214 my $os = $oses->{$root_dev};
215 mount_operating_system ($g, $os);
216 inspect_in_detail ($g, $os);
217 $g->umount_all ();
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241 =head1 SEE ALSO
242
243 L<virt-inspector(1)>,
244 L<guestfs(3)>,
245 L<guestfish(1)>,
246 L<Sys::Guestfs(3)>,
247 L<Sys::Guestfs::Lib(3)>,
248 L<Sys::Virt(3)>,
249 L<http://libguestfs.org/>.
250
251 For Windows registry parsing we require the C<reged> program
252 from L<http://home.eunet.no/~pnordahl/ntpasswd/>.
253
254 =head1 AUTHOR
255
256 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
257
258 Matthew Booth L<mbooth@redhat.com>
259
260 =head1 COPYRIGHT
261
262 Copyright (C) 2009 Red Hat Inc.
263
264 This program is free software; you can redistribute it and/or modify
265 it under the terms of the GNU General Public License as published by
266 the Free Software Foundation; either version 2 of the License, or
267 (at your option) any later version.
268
269 This program is distributed in the hope that it will be useful,
270 but WITHOUT ANY WARRANTY; without even the implied warranty of
271 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
272 GNU General Public License for more details.
273
274 You should have received a copy of the GNU General Public License
275 along with this program; if not, write to the Free Software
276 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.