16.12. virt-sysprep: Resetting Virtual Machine Settings
virt-sysprepcommand line tool can be used to reset or unconfigure a guest virtual machine so that clones can be made from it. This process involves removing SSH host keys, persistent network MAC configuration, and user accounts.
virt-sysprepcan also customize a virtual machine, for instance by adding SSH keys, users or logos. Each step can be enabled or disabled as required.
virt-syspreptool is part of the libguestfs-tools-c package, which is installed with the following command:
yum install libguestfs-tools-c
virt-syspreptool can be installed with the following command:
yum install /usr/bin/virt-sysprep
virt-sysprepmodifies the guest or disk image in place. To use
virt-sysprep, the guest virtual machine must be offline, so you must shut it down before running the commands. To preserve the existing contents of the guest virtual machine, you must snapshot, copy or clone the disk first. Refer to libguestfs.org for more information on copying and cloning disks.
|--help||Displays a brief help entry about a particular command or about the whole package. For additional help, see the virt-sysprep man page.|| $ |
|-a [file] or --add [file]|| Adds the specified file, which should be a disk image from a guest virtual machine. The format of the disk image is auto-detected. To override this and force a particular format, use the || $ |
|-c [URI] or --connect [URI]|| Connects to the given URI, if using libvirt. If omitted, it will connect via the KVM hypervisor. If you specify guest block devices directly (|| $ |
|-d [guest] or --domain [guest]||Adds all the disks from the specified guest virtual machine. Domain UUIDs can be used instead of domain names.|| $ |
|-n or --dry-run or --dryrun||Performs a read-only "dry run" sysprep operation on the guest virtual machine. This runs the sysprep operation, but throws away any changes to the disk at the end.|| $ |
|--enable [operations]||Enables the specified operations. To list the possible operations, use the --list command.|| $ |
| --format [||The default for the -a option is to auto-detect the format of the disk image. Using this forces the disk format for -a options which follow on the command line. Using --format auto switches back to auto-detection for subsequent -a options (see the -a command above).|| $ |
|--list-operations|| Lists the operations supported by the virt-sysprep program. These are listed one per line, with one or more single-space-separated fields. The first field in the output is the operation name, which can be supplied to the || $ |
|--mount-options||Sets the mount options for each mount point in the guest virtual machine. Use a semicolon-separated list of mountpoint:options pairs. You may need to place quotes around this list to protect it from the shell.|| $ |
|--selinux-relabel and --no-selinux-relabel|| virt-sysprep does not always schedule a SELinux relabelling at the first boot of the guest. In some cases, a relabel is performed (for example, when virt-sysprep has modified files). However, when all operations only remove files (for example, when using || $ |
|-q or --quiet||Prevents the printing of log messages.|| $ |
|-v or --verbose||Enables verbose messages for debugging purposes.|| $ |
|-V or --version||Displays the virt-sysprep version number and exits.|| $ |
|--root-password||Sets the root password. Can either be used to specify the new password explicitly, or to use the string from the first line of a selected file, which is more secure.|| |