5 virt-sysprep - Reset or unconfigure a virtual machine so clones can be made
9 virt-sysprep [--options] -d domname
11 virt-sysprep [--options] -a disk.img [-a disk.img ...]
15 Virt-sysprep "resets" or "unconfigures" a virtual machine so that
16 clones can be made from it. Steps in this process include removing
17 SSH host keys, removing persistent network MAC configuration, and
18 removing user accounts. Each step can be enabled or disabled as
21 Virt-sysprep is a simple shell script, allowing easy inspection or
22 customization by the system administrator.
24 Virt-sysprep modifies the guest or disk image I<in place>. The guest
25 must be shut down. If you want to preserve the existing contents of
26 the guest, you I<must copy or clone the disk first>.
27 See L</COPYING AND CLONING> below.
29 "Sysprep" stands for "system preparation" tool. The name comes from
30 the Microsoft program C<sysprep.exe> which is used to unconfigure
31 Windows machines in preparation for cloning them. Having said that,
32 virt-sysprep does I<not> currently work on Microsoft Windows guests.
33 We plan to support Windows sysprepping in a future version, and we
34 already have code to do it.
48 Add I<file> which should be a disk image from a virtual machine.
50 The format of the disk image is auto-detected. To override this and
51 force a particular format use the I<--format=..> option.
55 =item B<--connect> URI
57 If using libvirt, connect to the given I<URI>. If omitted, then we
58 connect to the default libvirt hypervisor.
60 If you specify guest block devices directly (I<-a>), then libvirt is
65 =item B<--domain> guest
67 Add all the disks from the named libvirt guest. Domain UUIDs can be
68 used instead of names.
72 Choose which sysprep operations to perform. Give a comma-separated
73 list of operations, for example:
75 --enable=ssh-hostkeys,udev-persistent-net
77 would enable ONLY C<ssh-hostkeys> and C<udev-persistent-net> operations.
79 If the I<--enable> option is not given, then we default to trying all
80 possible sysprep operations. But some sysprep operations are skipped
83 Use I<--list-operations> to list operations supported by a particular
84 version of virt-sysprep.
86 See L</OPERATIONS> below for a list and an explanation of each
89 =item B<--format=raw|qcow2|..>
93 The default for the I<-a> option is to auto-detect the format of the
94 disk image. Using this forces the disk format for I<-a> options which
95 follow on the command line. Using I<--format> with no argument
96 switches back to auto-detection for subsequent I<-a> options.
100 virt-sysprep --format=raw -a disk.img
102 forces raw format (no auto-detection) for C<disk.img>.
104 virt-sysprep --format=raw -a disk.img --format -a another.img
106 forces raw format (no auto-detection) for C<disk.img> and reverts to
107 auto-detection for C<another.img>.
109 If you have untrusted raw-format guest disk images, you should use
110 this option to specify the disk format. This avoids a possible
111 security problem with malicious guests (CVE-2010-3851).
113 =item B<--hostname> newhostname
115 Change the hostname. See the L</hostname> operation below.
116 If not given, defaults to C<localhost.localdomain>.
118 =item B<--list-operations>
120 List the operations supported by the virt-sysprep program.
126 Enable verbose messages for debugging.
132 Display version number and exit.
136 Enable tracing of libguestfs API calls.
142 If the I<--enable> option is I<not> given, then all sysprep operations
143 in the list below are enabled, although some are skipped depending on
146 Operations can be individually enabled using the I<--enable> option.
147 Use a comma-separated list, for example:
149 virt-sysprep --enable=ssh-hostkeys,udev-persistent-net [etc..]
151 To list the operations supported by the current version of
152 virt-sysprep, use I<--list-operations>.
156 This changes the hostname of the guest to the value given in the
157 I<--hostname> parameter.
159 If the I<--hostname> parameter is not given, then the hostname is
160 changed to C<localhost.localdomain>.
164 Remove HWADDR (hard-coded MAC address) configuration. For Fedora and
165 Red Hat Enterprise Linux, this is removed from C<ifcfg-*> files.
169 This erases the SSH host keys in the guest.
171 The SSH host keys are regenerated (differently) next time the guest is
174 If, after cloning, the guest gets the same IP address, ssh will give
175 you a stark warning about the host key changing:
177 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
178 @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
179 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
180 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
182 =head2 udev-persistent-net
184 This erases udev persistent net rules which map the guest's existing
185 MAC address to a fixed ethernet device (eg. eth0).
187 After a guest is cloned, the MAC address usually changes. Since the
188 old MAC address occupies the old name (eg. eth0), this means the fresh
189 MAC address is assigned to a new name (eg. eth1) and this is usually
190 undesirable. Erasing the udev persistent net rules avoids this.
192 =head1 COPYING AND CLONING
194 Virt-sysprep can be used as part of a process of cloning guests, or to
195 prepare a template from which guests can be cloned. There are many
196 different ways to achieve this using the virt tools, and this section
197 is just an introduction.
199 A virtual machine (when switched off) consists of two parts:
203 =item I<configuration>
205 The configuration or description of the guest. eg. The libvirt
206 XML (see C<virsh dumpxml>), the running configuration of the guest,
207 or another external format like OVF.
209 Some configuration items that might need to be changed:
223 path to block device(s)
227 network card MAC address
231 =item I<block device(s)>
233 One or more hard disk images, themselves containing files,
234 directories, applications, kernels, configuration, etc.
236 Some things inside the block devices that might need to be changed:
242 hostname and other net configuration
254 Windows unique security ID (SID)
264 =head2 COPYING THE BLOCK DEVICE
266 Starting with an original guest, you probably wish to copy the guest
267 block device and its configuration to make a template. Then once you
268 are happy with the template, you will want to make many clones from
274 original guest --------> template ---------->
279 You can, of course, just copy the block device on the host using
280 L<cp(1)> or L<dd(1)>.
283 original guest --------> template ---------->
288 There are some smarter (and faster) ways too:
300 Use the block device as a backing file and create a snapshot on top
301 for each guest. The advantage is that you don't need to copy the
302 block device (very fast) and only changes are stored (less storage
305 Note that writing to the backing file once you have created guests on
306 top of it is not possible: you will corrupt the guests.
308 Tools that can do this include:
309 L<qemu-img(1)> (with the I<create -f qcow2 -o backing_file> option),
310 L<lvcreate(8)> (I<--snapshot> option). Some filesystems (such as
311 btrfs) and most Network Attached Storage devices can also create cheap
312 snapshots from files or LUNs.
316 Get your NAS to snapshot and/or duplicate the LUN.
320 Prepare your template using L<virt-sparsify(1)>. See below.
326 A separate tool, L<virt-clone(1)>, can be used to duplicate the block
327 device and/or modify the external libvirt configuration of a guest.
328 It will reset the name, UUID and MAC address of the guest in the
331 L<virt-clone(1)> does not use libguestfs and cannot look inside the
332 disk image. This was the original motivation to write virt-sysprep.
337 original guest --------> template
339 L<virt-sparsify(1)> can be used to make the cloning template smaller,
340 making it easier to compress and/or faster to copy.
342 Notice that since virt-sparsify also copies the image, you can use it
343 to make the initial copy (instead of C<dd>).
353 If you want to give people cloned guests, but let them pick the size
354 of the guest themselves (eg. depending on how much they are prepared
355 to pay for disk space), then instead of copying the template, you can
356 run L<virt-resize(1)>. Virt-resize performs a copy and resize, and
357 thus is ideal for cloning guests from a template.
361 Libvirt guest names can contain arbitrary characters, some of which
362 have meaning to the shell such as C<#> and space. You may need to
363 quote or escape these characters on the command line. See the shell
364 manual page L<sh(1)> for details.
368 This program returns 0 on success, or 1 if there was an error.
381 L<http://libguestfs.org/>,
382 L<http://libvirt.org/>.
386 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
390 Copyright (C) 2011 Red Hat Inc.
392 This program is free software; you can redistribute it and/or modify
393 it under the terms of the GNU General Public License as published by
394 the Free Software Foundation; either version 2 of the License, or
395 (at your option) any later version.
397 This program is distributed in the hope that it will be useful,
398 but WITHOUT ANY WARRANTY; without even the implied warranty of
399 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
400 GNU General Public License for more details.
402 You should have received a copy of the GNU General Public License
403 along with this program; if not, write to the Free Software
404 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.