V2V outline program.
[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 guests to KVM
37
38 =head1 SYNOPSIS
39
40  virt-v2v xen_name -o kvm_name
41
42  virt-v2v guest.img [guest.img ...]
43
44 =head1 DESCRIPTION
45
46
47
48
49
50
51 =head1 OPTIONS
52
53 =over 4
54
55 =cut
56
57 my $help;
58
59 =item B<--help>
60
61 Display brief help.
62
63 =cut
64
65 my $version;
66
67 =item B<--version>
68
69 Display version number and exit.
70
71 =cut
72
73 my $uri;
74
75 =item B<--connect URI> | B<-c URI>
76
77 If using libvirt, connect to the given I<URI>.  If omitted,
78 then we connect to the default libvirt hypervisor.
79
80 Libvirt is only used if you specify a C<domname> on the
81 command line.  If you specify guest block devices directly,
82 then libvirt is not used at all.
83
84 =cut
85
86 GetOptions ("help|?" => \$help,
87             "version" => \$version,
88             "connect|c=s" => \$uri,
89     ) or pod2usage (2);
90 pod2usage (1) if $help;
91 if ($version) {
92     my $g = Sys::Guestfs->new ();
93     my %h = $g->version ();
94     print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
95     exit
96 }
97 pod2usage ("$0: no image or VM names given") if @ARGV == 0;
98
99 # XXX This should be an option.  Disable for now until we get
100 # downloads working reliably.
101 my $use_windows_registry = 0;
102
103 my @params = (\@ARGV);
104 if ($uri) {
105     push @params, address => $uri;
106 }
107 my ($g, $conn, $dom) = open_guest (@params);
108
109 $g->launch ();
110 $g->wait_ready ();
111
112 # List of possible filesystems.
113 my @partitions = get_partitions ($g);
114
115 # Now query each one to build up a picture of what's in it.
116 my %fses =
117     inspect_all_partitions ($g, \@partitions,
118                             use_windows_registry => $use_windows_registry);
119
120 #print "fses -----------\n";
121 #print Dumper(\%fses);
122
123 my $oses = inspect_operating_systems ($g, \%fses);
124
125 #print "oses -----------\n";
126 #print Dumper($oses);
127
128 # We should probably refuse to do anything with those rare
129 # multiboot VMs at this point ... (XXX)
130
131 # Mount up the disks and check for applications.
132
133 my $root_dev;
134 foreach $root_dev (sort keys %$oses) {
135     my $os = $oses->{$root_dev};
136     mount_operating_system ($g, $os);
137     inspect_in_detail ($g, $os);
138     $g->umount_all ();
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 =head1 SEE ALSO
161
162 L<virt-inspector(1)>,
163 L<guestfs(3)>,
164 L<guestfish(1)>,
165 L<Sys::Guestfs(3)>,
166 L<Sys::Guestfs::Lib(3)>,
167 L<Sys::Virt(3)>,
168 L<http://libguestfs.org/>.
169
170 For Windows registry parsing we require the C<reged> program
171 from L<http://home.eunet.no/~pnordahl/ntpasswd/>.
172
173 =head1 AUTHOR
174
175 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
176
177 =head1 COPYRIGHT
178
179 Copyright (C) 2009 Red Hat Inc.
180
181 This program is free software; you can redistribute it and/or modify
182 it under the terms of the GNU General Public License as published by
183 the Free Software Foundation; either version 2 of the License, or
184 (at your option) any later version.
185
186 This program is distributed in the hope that it will be useful,
187 but WITHOUT ANY WARRANTY; without even the implied warranty of
188 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
189 GNU General Public License for more details.
190
191 You should have received a copy of the GNU General Public License
192 along with this program; if not, write to the Free Software
193 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.