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