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 inspect_in_detail);
29 use File::Temp qw/tempdir/;
31 use Locale::TextDomain 'libguestfs';
37 virt-v2v - Convert Xen or VMWare guests to KVM
41 virt-v2v xen_name -o kvm_name
43 virt-v2v guest.ovf.zip -o kvm_name
45 virt-v2v guest.img [guest.img ...]
49 Virt-v2v converts guests from one virtualization hypervisor to
50 another. Currently it is limited in what it can convert. See the
53 -------------------------------+----------------------------
55 -------------------------------+----------------------------
56 Xen domain managed by |
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
65 -------------------------------+
67 VMWare VMDK image with |
68 OVF metadata, exported from |
71 VMWare compatibility: |
72 - RHEL 3.9+, 4.8+, 5.3+ |
75 -------------------------------+----------------------------
77 =head2 CONVERTING XEN DOMAINS
79 For Xen domains managed by libvirt, perform the initial conversion
82 virt-v2v xen_name -o kvm_name
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.
87 Then test boot the new guest in KVM:
92 When you have verified that this works, shut down the new KVM domain
93 and I<commit> the changes by doing:
95 virt-v2v --commit kvm_name
97 I<This command will destroy the original Xen domain>.
99 Or you can I<rollback> to the original Xen domain by doing:
101 virt-v2v --rollback kvm_name
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
107 =head2 CONVERTING VMWARE GUESTS
109 I<This section to be written>
133 Display version number and exit.
139 =item B<--connect URI> | B<-c URI>
141 If using libvirt, connect to the given I<URI>. If omitted,
142 then we connect to the default libvirt hypervisor.
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.
152 =item B<--output name> | B<-o name>
154 Set the output guest name.
162 GetOptions ("help|?" => \$help,
163 "version" => \$version,
164 "connect|c=s" => \$uri,
165 "output|o=s" => \$output,
167 pod2usage (1) if $help;
169 my $g = Sys::Guestfs->new ();
170 my %h = $g->version ();
171 print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
174 pod2usage (__"virt-v2v: no image or VM names given") if @ARGV == 0;
176 # XXX This should be an option. Disable for now until we get
177 # downloads working reliably.
178 my $use_windows_registry = 0;
180 my @params = (\@ARGV);
182 push @params, address => $uri;
184 my ($g, $conn, $dom) = open_guest (@params);
189 # List of possible filesystems.
190 my @partitions = get_partitions ($g);
192 # Now query each one to build up a picture of what's in it.
194 inspect_all_partitions ($g, \@partitions,
195 use_windows_registry => $use_windows_registry);
197 #print "fses -----------\n";
198 #print Dumper(\%fses);
200 my $oses = inspect_operating_systems ($g, \%fses);
202 #print "oses -----------\n";
203 #print Dumper($oses);
205 # Only work on single-root operating systems.
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];
212 # Mount up the disks and check for applications.
214 my $os = $oses->{$root_dev};
215 mount_operating_system ($g, $os);
216 inspect_in_detail ($g, $os);
243 L<virt-inspector(1)>,
247 L<Sys::Guestfs::Lib(3)>,
249 L<http://libguestfs.org/>.
251 For Windows registry parsing we require the C<reged> program
252 from L<http://home.eunet.no/~pnordahl/ntpasswd/>.
256 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
258 Matthew Booth L<mbooth@redhat.com>
262 Copyright (C) 2009 Red Hat Inc.
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.
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.
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.