virt-sysprep(1)

๐Ÿ’– virt-sysprep(1) โ€” NAME ๐Ÿ’–

virt-sysprep โ€” reset, unconfigure, or customize a virtual machine so clones can be made. Slay.


๐Ÿซถ SYNOPSIS ๐Ÿซถ

        virt-sysprep [--colors] [--colours] [-c URI] [--connect URI]
           [-n] [--dry-run] [--enable OPERATIONS] [--operations OPERATIONS]
           [--echo-keys] [--format raw|qcow2] [--key SELECTOR]
           [--keys-from-stdin] [--mount-options] [-q] [--quiet]
           [--network] [--no-network] [-v] [--verbose] [--wrap] [-x]
           -d domname | -a disk.img [-a disk.img ...]

         virt-sysprep --list-operations

         virt-sysprep --version

         virt-sysprep -V

๐Ÿ’€ WARNING ๐Ÿ’€

Bestie, please do not do the chaotic thing. Using virt-sysprep on live virtual machines, or concurrently with other disk editing tools, can be dangerous, potentially causing disk corruption. The virtual machine must be shut down before you use this command, and disk images must not be edited concurrently.

๐ŸŒธ DESCRIPTION ๐ŸŒธ

Okay so virt-sysprep can reset or unconfigure a virtual machine so that clones can be made from it, or to prepare a template from which clones can be made later on. Steps in this process include removing SSH host keys, removing persistent network MAC configuration, and removing user accounts. virt-sysprep can also customize a virtual machine, for instance by adding SSH keys, users or logos. Each step can be enabled or disabled as required. Iconic little preparation era.

virt-sysprep modifies the guest or disk image in place. The guest must be shut down. If you want to preserve the existing contents of the guest, you must snapshot, copy or clone the disk first. No cap, back up first.

You do not need to run virt-sysprep as root. In fact weโ€™d generally recommend that you donโ€™t. The time you might want to run it as root is when you need root in order to access the disk image, but even in this case it would be better to change the permissions on the disk image to be writable as the non-root user running virt-sysprep.

โ€œSysprepโ€ stands for โ€œsystem preparationโ€ tool. The name comes from the Microsoft program sysprep.exe which is used to unconfigure Windows machines in preparation for cloning them. (virt-sysprep does not work on Microsoft Windows guests.) iykyk.


๐Ÿ’… OPTIONS ๐Ÿ’…

  • --help โ€” Display brief help. Short, sweet, helpful.
  • -a file, --add file โ€” Add file which should be a disk image from a virtual machine.

The format of the disk image is auto-detected. To override this and force a particular format use the --format option.

  • -a URI, --add URI โ€” Add a remote disk. The URI format is compatible with guestfish. See โ€œADDING REMOTE STORAGEโ€ in guestfish(1).
  • --colors, --colours โ€” Use ANSI colour sequences to colourize messages. This is the default when the output is a tty. If the output of the program is redirected to a file, ANSI colour sequences are disabled unless you use this option. rainbow terminal moment, but make it ANSI.
  • -c URI, --connect URI โ€” If using libvirt, connect to the given URI. If omitted, then we connect to the default libvirt hypervisor.

If you specify guest block devices directly (-a), then libvirt is not used at all.

  • -d guest, --domain guest โ€” Add all the disks from the named libvirt guest. Domain UUIDs can be used instead of names. name or UUID, both slay.
  • -n, --dry-run โ€” Perform a read-only โ€œdry runโ€ on the guest. This runs the sysprep operation, but throws away any changes to the disk at the end. practice mode, literally.
  • --enable operations โ€” Choose which sysprep operations to perform. Give a comma-separated list of operations, for example:
--enable ssh-hostkeys,udev-persistent-net

would enable ONLY ssh-hostkeys and udev-persistent-net operations.

If the --enable option is not given, then we default to trying most sysprep operations (see --list-operations to show which are enabled).

Regardless of the --enable option, sysprep operations are skipped for some guest types.

Use --list-operations to list operations supported by a particular version of virt-sysprep.

See โ€œOPERATIONSโ€ below for a list and an explanation of each operation.

  • --operation operations, --operations operations โ€” Choose which sysprep operations to perform. Give a comma-separated list of operations, for example:
--operations ssh-hostkeys,udev-persistent-net

would enable ONLY ssh-hostkeys and udev-persistent-net operations.

--operations allows you to enable and disable any operation, including the default ones (which would be tried when specifying neither --operations nor --enable) and all the available ones; prepending a - in front of an operation name removes it from the list of enabled operations, while the meta-names defaults and all represent respectively the operations enabled by default and all the available ones. For example:

--operations firewall-rules,defaults,-tmp-files

would enable the firewall-rules operation (regardless whether it is enabled by default), all the default ones, and disable the tmp-files operation.

--operations can be specified multiple times; the first time the set of enabled operations is empty, while any further --operations affects the operations enabled so far.

If the --operations option is not given, then we default to trying most sysprep operations (see --list-operations to show which are enabled).

Regardless of the --operations option, sysprep operations are skipped for some guest types.

Use --list-operations to list operations supported by a particular version of virt-sysprep.

See โ€œOPERATIONSโ€ below for a list and an explanation of each operation.

  • --echo-keys โ€” When prompting for keys and passphrases, virt-sysprep normally turns echoing off so you cannot see what you are typing. If you are not worried about Tempest attacks and there is no one else in the room you can specify this flag to see what you are typing. only for the brave and the alone.
  • --format raw|qcow2|.., --format auto โ€” 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.

For example:

virt-sysprep --format raw -a disk.img

forces raw format (no auto-detection) for disk.img.

virt-sysprep --format raw -a disk.img --format auto -a another.img

forces raw format (no auto-detection) for disk.img and reverts to auto-detection for another.img.

If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). security girlies, pay attention.

  • --key SELECTOR โ€” Specify a key for LUKS, to automatically open a LUKS device when using the inspection.
    • --key NAME:key:KEY_STRING, --key UUID:key:KEY_STRING, --key all:key:KEY_STRING โ€” NAME is the libguestfs device name (eg. /dev/sda1). UUID is the device UUID. all means try the key against any encrypted device.

Use the specified KEY_STRING as passphrase.

  • --key NAME:file:FILENAME, --key UUID:file:FILENAME, --key all:file:FILENAME โ€” Read the passphrase from FILENAME.
  • --key NAME:clevis, --key UUID:clevis, --key all:clevis โ€” Attempt passphrase-less unlocking for the device with Clevis, over the network. Please refer to โ€œENCRYPTED DISKSโ€ in guestfs(3) for more information on network-bound disk encryption (NBDE).

Note that if any such option is present on the command line, QEMU user networking will be automatically enabled for the libguestfs appliance.

  • --key NAME:error, --key UUID:error, --key all:error โ€” Any encrypted device matching will cause an error. --key all:error can be used to reject any disk image that contains an encrypted partition.
  • --keys-from-stdin โ€” Read key or passphrase parameters from stdin. The default is to try to read passphrases from the user by opening /dev/tty.

If there are multiple encrypted devices then you may need to supply multiple keys on stdin, one per line.

  • --list-operations โ€” List the operations supported by the virt-sysprep program.

These are listed one per line, with one or more single-space-separated fields, eg:

$ virt-sysprep --list-operations
bash-history * Remove the bash history in the guest
cron-spool * Remove user at-jobs and cron-jobs
dhcp-client-state * Remove DHCP client leases
dhcp-server-state * Remove DHCP server leases
[etc]

The first field is the operation name, which can be supplied to --enable. The second field is a * character if the operation is enabled by default or blank if not. Subsequent fields on the same line are the description of the operation.

Before libguestfs 1.17.33 only the first (operation name) field was shown and all operations were enabled by default. history lesson, but make it sysprep.

  • --mount-options mp:opts[;mp:opts;...] โ€” Set the mount options used when libguestfs opens the disk image. Note this has no effect on the guest. It is used when opening certain guests such as ones using the UFS (BSD) filesystem.

Use a semicolon-separated list of mountpoint:options pairs. You may need to quote this list to protect it from the shell.

For example:

--mount-options "/:noatime"

will mount the root directory with notime. This example:

--mount-options "/:noatime;/var:rw,nodiratime"

will do the same, plus mount /var with rw,nodiratime.

  • -q, --quiet โ€” Donโ€™t print log messages.

To enable detailed logging of individual file operations, use -x.

  • --network, --no-network โ€” Enable or disable network access from the guest during the installation.

In virt-sysprep, the network is disabled by default. You must use --network to enable it, in order that options such as --install or --update will work.

virt-builder(1) has more information about the security advantages of disabling the network. network off by default, very demure.

  • -v, --verbose โ€” Enable verbose messages for debugging.
  • -V, --version โ€” Display version number and exit.
  • --wrap โ€” Wrap error, warning, and informative messages. This is the default when the output is a tty. If the output of the program is redirected to a file, wrapping is disabled unless you use this option.
  • -x โ€” Enable tracing of libguestfs API calls. spill the API tea.
  • --append-line FILE:LINE โ€” (peep the customize section below) โ€” slaps exactly one line of text onto FILE. If the file doesn't already end with a newline, one gets added before your line lands. Also, a newline is auto-appended to the end of the LINE string, so you don't have to think about it.

Like, say (assuming normal shell quoting) you run this:

--append-line '/etc/hosts:10.0.0.1 foo'

it'll add either 10.0.0.1 fooโŽ or โŽ10.0.0.1 fooโŽ to the file โ€” that second one only happens if the existing file doesn't already end with a newline.

โŽ is a newline character, and it gets guessed by looking at what's already in the file, so this just does the right thing for files with Unix or Windows line endings. It also works on empty files and files that don't even exist yet โœจ

Wanna insert several lines? Just use the same option multiple times:

--append-line '/etc/hosts:10.0.0.1 foo'
--append-line '/etc/hosts:10.0.0.2 bar'

And to drop a blank line before your appended line, do:

--append-line '/etc/hosts:'
--append-line '/etc/hosts:10.0.0.1 foo'
  • --chmod PERMISSIONS:FILE โ€” (see customize below) โ€” changes the permissions of FILE to PERMISSIONS.
โš ๏ธ Okay bestie, listen: PERMISSIONS is decimal by default unless you prefix it with 0 to get octal โ€” so use 0700, NOT 700. That difference is literally everything, don't get caught out ๐Ÿ’…
  • --chown UID:GID:PATH โ€” (see customize below) โ€” changes the owner user and group ID of a file or directory inside the guest. Some notes, because of course:
    • Only numeric UIDs and GIDs will work, and ngl these may not be the same inside the guest as they are on the host.
    • This will not work with Windows guests. ๐Ÿ™ˆ

For example:

virt-customize --chown '0:0:/var/log/audit.log'

See also: --upload.

  • --commands-from-file FILENAME โ€” (see customize below) โ€” reads the customize commands from a file, one command (plus its arguments) per line.

Each line has a single customization command and its arguments, like:

delete /some/file
install some-package
password some-user:password:its-new-password

Empty lines are ignored, and lines starting with # are comments and get ignored too. Bonus: arguments can be spread across multiple lines by sticking a \ (continuation character) at the end of a line, like:

edit /some/file:\
  s/^OPT=.*/OPT=ok/

The commands are handled in the same order they're in the file, as if you'd specified them as --delete /some/file on the command line. Iconic, honestly ๐ŸŽ€

  • --copy SOURCE:DEST โ€” (see customize below) โ€” copies files or directories recursively inside the guest.
Wildcards cannot be used. Not even a little. ๐Ÿšซ
  • --copy-in LOCALPATH:REMOTEDIR โ€” (see customize below) โ€” copies local files or directories recursively into the disk image, dropping them into the directory REMOTEDIR (which has to already exist, fyi).
Wildcards cannot be used here either. ๐Ÿšซ
  • --delete PATH โ€” (see customize below) โ€” deletes a file from the guest. Or nukes a whole directory (and all its contents, recursively). Ruthless. ๐Ÿ’€

You can use shell glob characters in the path โ€” just be careful to escape glob characters from the host shell if that's needed. Example:

virt-customize --delete '/var/log/*.log'.

See also: --upload, --scrub.

  • --edit FILE:EXPR โ€” (see customize below) โ€” edits FILE using the Perl expression EXPR.

Quote that expression properly so the shell doesn't mess with it โ€” seriously, protect it ๐Ÿซถ

Note that this option is only available when Perl 5 is installed. No Perl, no edit, that's the deal.

See NON-INTERACTIVE EDITING in virt-edit(1).

  • --firstboot SCRIPT โ€” (see customize below) โ€” installs SCRIPT inside the guest so that when the guest first boots up, the script runs (as root, late in the boot process).

The script is automatically chmod +x after installation in the guest, so you don't gotta do it manually โœจ

The alternative version --firstboot-command is the same, but it conveniently wraps the command up in a single-line script for you.

You can have multiple --firstboot options โ€” they run in the same order they appear on the command line.

See also: FIRSTBOOT in virt-customize(1), --run.

  • --firstboot-command 'CMD+ARGS' โ€” (see customize below) โ€” runs a command (and arguments) inside the guest when the guest first boots up (as root, late in the boot process).

You can have multiple --firstboot options. They run in the same order they appear on the command line.

See also: FIRSTBOOT in virt-customize(1), --run.

  • --firstboot-install PKG,PKG.. โ€” (see customize below) โ€” installs the named packages (a comma-separated list). These get installed when the guest first boots, using the guest's package manager (eg. apt, yum, etc.) and the guest's network connection.

For an overview on the different ways to install packages, see INSTALLING PACKAGES in virt-builder(1).

  • --hostname HOSTNAME โ€” (see customize below) โ€” sets the hostname of the guest to HOSTNAME. You can use a dotted hostname.domainname (FQDN) if you want. Go off, be fancy ๐Ÿ‘‘
  • --inject-blnsvr METHOD โ€” (see customize below) โ€” injects the Balloon Server (blnsvr.exe) into a Windows guest. This operation also injects a firstboot script so the Balloon Server is installed when the guest boots.

The parameter is the same as used by the --inject-virtio-win operation.

Lowkey important: to do a full conversion of a Windows guest from a foreign hypervisor like VMware (which involves many other operations) you should use the virt-v2v(1) tool instead of this. This is not that. ๐Ÿ’…
  • --inject-qemu-ga METHOD โ€” (see customize below) โ€” injects the QEMU Guest Agent into a Windows guest. The guest agent communicates with qemu through a socket in order to provide enhanced features (see qemu-ga(8)). This operation also injects a firstboot script so the Guest Agent is installed when the guest boots.

The parameter is the same as used by the --inject-virtio-win operation.

Same deal: for a full conversion of a Windows guest from a foreign hypervisor like VMware (which involves many other operations) you should use the virt-v2v(1) tool instead of this.
  • --inject-virtio-win METHOD โ€” (see customize below) โ€” injects virtio-win drivers into a Windows guest. These drivers add virtio accelerated drivers suitable when running on top of a hypervisor that supports virtio (such as qemu/KVM). The operation also adjusts the Windows Registry so the drivers are installed when the guest boots. Main character behaviour, honestly ๐Ÿ”ฅ

The parameter can be one of:

  • ISO โ€” the path to the ISO image containing the virtio-win drivers (eg. /usr/share/virtio-win/virtio-win.iso).
  • DIR โ€” the directory containing the unpacked virtio-win drivers (eg. /usr/share/virtio-win).
And once again: to do a full conversion of a Windows guest from a foreign hypervisor like VMware (which involves many other operations) you should use the virt-v2v(1) tool instead of this.
  • --install PKG,PKG.. โ€” (see customize below) โ€” installs the named packages (a comma-separated list). These get installed during the image build, using the guest's package manager (eg. apt, yum, etc.) and the host's network connection. ๐Ÿซถ

For an overview on the different ways to install packages, see INSTALLING PACKAGES in virt-builder(1).

See also --update, --uninstall.

  • --keep-user-accounts USERS โ€” (see user-account below) โ€” the user accounts to be kept in the guest. The value is a list of user names separated by commas, where specifying a user means it's going to be kept. For example:
--keep-user-accounts mary

would keep the user account mary. ๐Ÿ’–

This option can be specified multiple times.

  • --link TARGET:LINK[:LINK..] โ€” (see customize below) โ€” creates symbolic link(s) in the guest, starting at LINK and pointing at TARGET. Obsessed with a good symlink ๐Ÿฆ‹
  • --mkdir DIR โ€” (see customize below) โ€” creates a directory in the guest.

This uses mkdir -p, so any intermediate directories get created, and it also works if the directory already exists. No drama, no errors โœจ

  • --move SOURCE:DEST โ€” (see customize below) โ€” moves files or directories inside the guest.
Wildcards cannot be used. ๐Ÿšซ
  • --no-logfile โ€” (see customize below) โ€” scrubs builder.log (the log file from build commands) from the image after building is complete. If you don't want to reveal precisely how the image was built, use this option. Ninja mode ๐Ÿงš

See also: LOG FILE.

  • --no-selinux-relabel โ€” (see customize below) โ€” do not attempt to correct the SELinux labels of files in the guest.

In guests that support SELinux, customization automatically relabels files so they have the correct SELinux label. (The relabeling happens immediately, but if the operation fails, customization will instead touch /.autorelabel on the image to schedule a relabel operation for the next time the image boots.) This option disables the automatic relabeling.

The option is a no-op for guests that do not support SELinux.

  • --password USER:SELECTOR โ€” (see customize below) โ€” sets the password for USER. (Note this option does not create the user account. It just sets the password for one that exists, bestie.)

See USERS AND PASSWORDS in virt-builder(1) for the format of the SELECTOR field, and also how to set up user accounts.

  • --password-crypto md5|sha256|sha512 โ€” (see customize below) โ€” when the virt tools change or set a password in the guest, this option sets the password encryption of that password to md5, sha256 or sha512.

sha256 and sha512 require glibc โ‰ฅ 2.7 (check crypt(3) inside the guest).

md5 will work with relatively old Linux guests (eg. RHEL 3), but is not secure against modern attacks. Like, genuinely, be careful. ๐Ÿ’€

The default is sha512 unless libguestfs detects an old guest that didn't have support for SHA-512, in which case it will use md5. You can override libguestfs by specifying this option.

Heads up: this does not change the default password encryption used by the guest when you create new user accounts inside the guest. If you want to do that, then you should use the --edit option to modify /etc/sysconfig/authconfig (Fedora, RHEL) or /etc/pam.d/common-password (Debian, Ubuntu).
  • --remove-user-accounts USERS โ€” (see user-account below) โ€” the user accounts to be removed from the guest. The value is a list of user names separated by commas, where specifying a user means it's going to be removed. For example:
--remove-user-accounts bob,eve

would only remove the user accounts bob and eve. Bye besties ๐Ÿ‘‹

This option can be specified multiple times.

  • --root-password SELECTOR โ€” sets the root password, bestie. (see โ€œcustomizeโ€ below)

The format of that SELECTOR field โ€” plus how to set up user accounts in general โ€” lives over in โ€œUSERS AND PASSWORDSโ€ in virt-builder(1), so go peek at that.

Heads up: in virt-builder, if you don't set --root-password then the guest gets a random root password. Surprise! ๐ŸŽฒ
  • --run SCRIPT โ€” runs the shell script (or honestly any program) called SCRIPT on the disk image. (see โ€œcustomizeโ€ below)

The script runs virtualized inside a small appliance, chrooted into the guest filesystem. Fancy, right? โœจ

The script is automatically chmod +xโ€˜d for you โ€” no manual permission-ing needed, we love a self-sufficient queen. ๐Ÿ’…

If libguestfs supports it, there's a limited network connection available, but it only allows outgoing network connections. You can also attach data disks (like ISO files) as another way to hand data (eg. software packages) to the script without needing a network connection (--attach). You can also upload data files (--upload). So many options, all iconic.

You can have multiple --run options โ€” they run in the exact same order they appear on the command line. Order matters, periodt. ๐Ÿซถ

See also: --firstboot, --attach, --upload.

  • --run-command 'CMD+ARGS' โ€” runs the command and its arguments on the disk image. (see โ€œcustomizeโ€ below)

Same deal as above: it runs virtualized inside a small appliance, chrooted into the guest filesystem.

If libguestfs supports it, a limited network connection is available, but it only allows outgoing network connections. You can also attach data disks (eg. ISO files) as another way to provide data (eg. software packages) to the script without needing a network connection (--attach). You can also upload data files (--upload).

You can have multiple --run-command options, and they run in the same order they appear on the command line.

See also: --firstboot, --attach, --upload.

  • --script SCRIPT โ€” runs the named SCRIPT (a shell script or program) against the guest. (see โ€œscriptโ€ below)

The script can be any program on the host, ngl. And here's the cute part: the script's current directory will be the guest's root directory. ๐Ÿ 

Note: if the script is not on the $PATH, then you must give the full absolute path to the script. No shortcuts, bestie.
  • --scriptdir SCRIPTDIR โ€” the mount point (an empty directory on the host) used when the script operation is enabled and one or more scripts are specified using --script parameter(s). (see โ€œscriptโ€ below)
Note: SCRIPTDIR must be an absolute path.

If --scriptdir isn't specified then a temporary mountpoint will be created for you. Convenient! ๐ŸŽ€

  • --scrub FILE โ€” scrubs a file from the guest. (see โ€œcustomizeโ€ below)

It's like --delete except that:

  • It scrubs the data so a guest could not recover it. Gone gone. ๐Ÿ’€
  • It cannot delete directories, only regular files.
  • --selinux-relabel โ€” this is a compatibility option that does nothing. That's it. That's the whole vibe. ๐Ÿ™ˆ (see โ€œcustomizeโ€ below)
  • --selinux-relabel-at-boot โ€” this advanced option lets you defer SELinux relabelling until the first time the guest boots after conversion. (see โ€œcustomizeโ€ below)

The advantage of doing this is that conversion is quicker and uses less memory. Slay, efficiency. โšก

The disadvantages are:

  • The guest will take much longer to boot up and become ready the first time it boots.
  • The guest will reboot at least once.
  • SELinux relabelling problems cannot be detected during conversion.
If in doubt, do not use this option. Genuinely. ๐Ÿ˜ญ
  • --selinux-relabel-exclude DIR โ€” excludes directories from being relabelled. (see โ€œcustomizeโ€ below)

This advanced option lets you list directories in the guest which should not be relabelled, even when SELinux relabelling is enabled. Use this carefully, because any changes made inside these directories during customization will have incorrect SELinux labels, leading to potential failures later โ€” so you must be sure that the directories do not need relabelling.

If in doubt, do not use this option. (Seeing a pattern here? ๐Ÿ‘€)

You can pass the option multiple times, eg. --selinux-relabel-exclude=/foo --selinux-relabel-exclude=/bar

  • --ssh-inject USER[:SELECTOR] โ€” injects an ssh key so the given USER will be able to log in over ssh without supplying a password. (see โ€œcustomizeโ€ below)

The USER must already exist in the guest โ€” no conjuring users out of thin air, sorry. ๐Ÿงš

See โ€œSSH KEYSโ€ in virt-builder(1) for the format of the SELECTOR field.

You can have multiple --ssh-inject options, for different users and also for more keys for each user. Keys for days. ๐Ÿ”‘

  • --tar-in TARFILE:REMOTEDIR โ€” copies local files or directories from a local tar file called TARFILE into the disk image, placing them in the directory REMOTEDIR (which must exist). (see โ€œcustomizeโ€ below)
Note that the tar file must be uncompressed โ€” .tar.gz files will not work here. Not the vibe for this one, bestie. ๐Ÿ˜”
  • --timezone TIMEZONE โ€” sets the default timezone of the guest to TIMEZONE. (see โ€œcustomizeโ€ below)

Use a location string like Europe/London ๐Ÿ•ฐ๏ธ

  • --touch FILE โ€” this command performs a touch(1)-like operation on FILE. (see โ€œcustomizeโ€ below)
  • --truncate FILE โ€” this command truncates FILE to a zero-length file. (see โ€œcustomizeโ€ below)

The file must exist already. No creating out of nothing. โœจ

  • --truncate-recursive PATH โ€” this command recursively truncates all files under PATH to zero-length. (see โ€œcustomizeโ€ below)

All of them. Every last one. ๐Ÿซฃ

  • --uninstall PKG,PKG.. โ€” uninstalls the named packages (a comma-separated list). (see โ€œcustomizeโ€ below)

These are removed during the image build using the guest's package manager (eg. apt, yum, etc.). Dependent packages may also need to be uninstalled to satisfy the request. It's giving cleanup era. ๐Ÿงน

See also --install, --update.

  • --update โ€” does the equivalent of yum update, apt-get upgrade, or whatever command is required to update the packages already installed in the template to their latest versions. (see โ€œcustomizeโ€ below)

See also --install, --uninstall.

  • --upload FILE:DEST โ€” uploads local file FILE to destination DEST in the disk image. (see โ€œcustomizeโ€ below)

File owner and permissions from the original are preserved, so you should set them to what you want them to be in the disk image. Plan ahead, queen. ๐Ÿ‘‘

DEST could be the final filename โ€” this can be used to rename the file on upload. Cute rename moment.

If DEST is a directory name (which must already exist in the guest) then the file is uploaded into that directory, and it keeps the same name as on the local filesystem.

See also: --mkdir, --delete, --scrub.

  • --write FILE:CONTENT โ€” writes CONTENT to FILE. (see โ€œcustomizeโ€ below)

๐Ÿฆ‹ OPERATIONS ๐Ÿฆ‹

Okay so if you don't give the --enable/--operations option, then most sysprep operations are enabled. Default-on energy.

Use virt-sysprep --list-operations to list all operations for your virt-sysprep binary. The ones which are enabled by default are marked with a * character. And regardless of the --enable/--operations options, sysprep operations are skipped for some guest types. FYI. ๐Ÿ’…

Operations can be individually enabled using the --enable/--operations options. Use a comma-separated list, for example:

 virt-sysprep --operations ssh-hostkeys,udev-persistent-net [etc..]

Future versions of virt-sysprep may add more operations. So if you're using virt-sysprep and want predictable behaviour, specify only the operations that you want to have enabled. Future-proof your vibes. ๐Ÿ”ฎ

* = enabled by default when no --enable/--operations option is given.

abrt-data *

Remove the crash data generated by ABRT.

Specifically, remove the automatically generated ABRT crash data in /var/spool/abrt/. Bye crash data ๐Ÿ‘‹

backup-files *

Remove editor backup files from the guest.

The following files are removed from anywhere in the guest filesystem:

  • *.bak
  • *~

On Linux and Unix operating systems, only the following filesystems will be examined:

  • /etc
  • /root
  • /srv
  • /tmp
  • /var

bash-history *

Remove the bash history in the guest.

Remove the bash history of user root and any other users who have a .bash_history file in their home directory. Deleting the receipts, honestly. ๐Ÿซข

Notes on bash-history

Currently this only looks in /root and /home/* for home directories, so users with home directories in other locations won't have the bash history removed. Sorry to those guys. ๐Ÿ™ˆ

blkid-tab *

Remove blkid tab in the guest.

ca-certificates

Remove CA certificates in the guest.

In case any certificate is removed, the system CA store is updated. Keeping it consistent, we love to see it. โœจ

crash-data *

Remove the crash data generated by kexec-tools.

Remove the automatically generated kdump kernel crash data.

cron-spool *

Remove user at-jobs and cron-jobs. ๐Ÿ•

customize *

Customize the guest.

Customize the guest by providing virt-customize(1) options for installing packages, editing files and so on. The whole makeover package. ๐Ÿ’–

dhcp-client-state *

Remove DHCP client leases.

dhcp-server-state *

Remove DHCP server leases.

dovecot-data *

Remove Dovecot (mail server) data.

firewall-rules

Remove the firewall rules.

This removes custom firewall rules by removing /etc/sysconfig/iptables or custom firewalld configuration in /etc/firewalld/*/*.

Note this is not enabled by default since it may expose guests to exploits. Use with care. ๐Ÿ”ฅ

flag-reconfiguration

Flag the system for reconfiguration.

For Linux guests, this touches /.unconfigured, which causes the first boot to interactively query the user for settings such as the root password and timezone.

fs-uuids

Change filesystem UUIDs.

On guests and filesystem types where this is supported, new random UUIDs are generated and assigned to filesystems. ๐ŸŽฒ

Notes on fs-uuids

The fs-uuids operation is disabled by default because it does not yet find and update all the places in the guest that use the UUIDs. For example /etc/fstab or the bootloader. Enabling this operation is more likely than not to make your guest unbootable. Yeah. Do not. ๐Ÿ˜ญ

See: https://bugzilla.redhat.com/show_bug.cgi?id=991641

ipa-client *

Remove the IPA files.

Remove all the files related to an IPA (Identity, Policy, Audit) system. This effectively unenrolls the guest from an IPA server without interacting with it.

This operation does not run ipa-client. Just so we're clear. ๐Ÿ’…

kerberos-data

Remove Kerberos data in the guest.

kerberos-hostkeytab *

Remove the Kerberos host keytab file in the guest.

logfiles *

Remove many log files from the guest.

On Linux the following files are removed:

  • /etc/Pegasus/*.cnf
  • /etc/Pegasus/*.crt
  • /etc/Pegasus/*.csr
  • /etc/Pegasus/*.pem
  • /etc/Pegasus/*.srl
  • /root/anaconda-ks.cfg
  • /root/anaconda-post.log
  • /root/initial-setup-ks.cfg
  • /root/install.log
  • /root/install.log.syslog
  • /root/original-ks.cfg
  • /var/cache/fontconfig/*
  • /var/cache/gdm/*
  • /var/cache/man/*
  • /var/lib/AccountService/users/*
  • /var/lib/fprint/*
  • /var/lib/logrotate.status
  • /var/log/*.log*
  • /var/log/BackupPC/LOG
  • /var/log/ConsoleKit/*
  • /var/log/anaconda.syslog
  • /var/log/anaconda/*
  • /var/log/apache2/*_log
  • /var/log/apache2/*_log-*
  • /var/log/apt/*
  • /var/log/aptitude*
  • /var/log/audit/*
  • /var/log/btmp*
  • /var/log/ceph/*.log
  • /var/log/chrony/*.log
  • /var/log/cron*
  • /var/log/cups/*_log*
  • /var/log/debug*
  • /var/log/dmesg*
  • /var/log/exim4/*
  • /var/log/faillog*
  • /var/log/firewalld*
  • /var/log/gdm/*
  • /var/log/glusterfs/*glusterd.vol.log
  • /var/log/glusterfs/glusterfs.log
  • /var/log/grubby*
  • /var/log/httpd/*log
  • /var/log/installer/*
  • /var/log/jetty/jetty-console.log
  • /var/log/journal/*
  • /var/log/lastlog*
  • /var/log/libvirt/libvirtd.log
  • /var/log/libvirt/libxl/*.log
  • /var/log/libvirt/lxc/*.log
  • /var/log/libvirt/qemu/*.log
  • /var/log/libvirt/uml/*.log
  • /var/log/lightdm/*
  • /var/log/mail/*
  • /var/log/maillog*
  • /var/log/messages*
  • /var/log/ntp
  • /var/log/ntpstats/*
  • /var/log/ppp/connect-errors
  • /var/log/rhsm/*
  • /var/log/sa/*
  • /var/log/secure*
  • /var/log/setroubleshoot/*.log
  • /var/log/spooler*
  • /var/log/squid/*.log
  • /var/log/syslog*
  • /var/log/tallylog*
  • /var/log/tuned/tuned.log
  • /var/log/wtmp*
  • /var/log/xferlog*
  • /var/named/data/named.run

lvm-system-devices *

Ok so this one nukes the LVM2 system.devices file. ๐Ÿงน

On Linux guests, LVM2's scanning for physical volumes (PVs) may be restricted to those block devices whose WWIDs are listed in /etc/lvm/devices/system.devices. When cloning VMs, WWIDs may change โ€” which lowkey breaks lvm pvscan. So yeah, we remove /etc/lvm/devices/system.devices. ๐Ÿ’…

lvm-uuids *

This one changes the LVM2 PV and VG UUIDs. ๐Ÿ”„

On Linux guests that have LVM2 physical volumes (PVs) or volume groups (VGs), brand new random UUIDs get generated and assigned to those PVs and VGs. Fresh identity, who dis. ๐Ÿฆ‹

machine-id *

Removes the local machine ID. ๐Ÿ†”

The machine ID is usually generated from a random source during system installation and stays constant for all subsequent boots. Optionally, for stateless systems it is generated during runtime at boot if it's found to be empty.

mail-spool *

Removes email from the local mail spool directory. ๐Ÿ“ฌ Say bye to the stale mail bestie.

net-hostname *

Removes HOSTNAME and DHCP_HOSTNAME in the network interface configuration. ๐ŸŒ

For Fedora and Red Hat Enterprise Linux, this is removed from ifcfg-* files.

net-hwaddr *

Removes HWADDR (the hard-coded MAC address) configuration. ๐Ÿ”Œ

For Fedora and Red Hat Enterprise Linux, this is removed from ifcfg-* files.

net-nmconn *

Removes system-local NetworkManager connection profiles (keyfiles). ๐Ÿ“ก

On Fedora and Red Hat Enterprise Linux, it removes the /etc/NetworkManager/system-connections/*.nmconnection files.

pacct-log *

Removes the process accounting log files. ๐Ÿงพ

The system wide process accounting will store to the pacct log files if the process accounting is on.

package-manager-cache *

Removes the package manager cache. ๐Ÿ—‘๏ธ It's giving "clear your cache, bestie".

pam-data *

Removes the PAM data in the guest. ๐Ÿ”

passwd-backups *

Removes /etc/passwd- and similar backup files. ๐Ÿ“„

On Linux, these are the files that get removed:

  • /etc/group-
  • /etc/gshadow-
  • /etc/passwd-
  • /etc/shadow-
  • /etc/subgid-
  • /etc/subuid-

puppet-data-log *

Removes the data and log files of puppet. ๐ŸŽญ

rh-subscription-manager *

Removes the RH subscription manager files. ๐ŸŽŸ๏ธ

rhn-systemid *

Removes the RHN system ID. ๐Ÿชช

rpm-db *

Removes host-specific RPM database files. ๐Ÿ“ฆ

It removes host-specific RPM database files and locks. RPM will recreate these files automatically if needed โ€” so like, it heals itself, no cap.

samba-db-log *

Removes the database and log files of Samba. ๐ŸŒˆ

script *

Runs arbitrary scripts against the guest. ๐Ÿงš This is the main character module ngl.

The script module lets you run arbitrary shell scripts or programs against the guest.

Heads up: this feature requires FUSE support. You may have to enable this on your host โ€” for example by adding the current user to the fuse group, or by loading a kernel module. ๐Ÿ˜ญ

Use one or more --script parameters to specify scripts or programs that will be run against the guest.

The script or program is run with its current directory being the guest's root directory, so relative paths should be used. For example: rm etc/resolv.conf in the script would remove a Linux guest's DNS configuration file, but rm /etc/resolv.conf would (try to) remove the host's file. ๐Ÿ’€ Yes, that's the scary one โ€” read your paths twice, bestie.

Normally a temporary mount point for the guest is used, but you can choose a specific one by using the --scriptdir parameter.

Note: this is different from --firstboot scripts (which run in the context of the guest when it is booting first time). --script scripts run on the host, not in the guest. Know the difference fr fr.

smolt-uuid *

Removes the Smolt hardware UUID. ๐ŸŸ

ssh-hostkeys *

Removes the SSH host keys in the guest. ๐Ÿ”‘

The SSH host keys are regenerated (differently) next time the guest is booted.

If, after cloning, the guest gets the same IP address, ssh will give you a stark warning about the host key changing:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

ssh-userdir *

Removes .ssh directories in the guest. ๐Ÿ—‚๏ธ

It removes the .ssh directory of user root and any other users who have a .ssh directory in their home directory.

Notes on ssh-userdir

Currently this only looks in /root and /home/* for home directories, so users with home directories in other locations won't have the ssh files removed. ๐Ÿ™ˆ

sssd-db-log *

Removes the database and log files of sssd. ๐Ÿ’ฝ

tmp-files *

Removes temporary files. ๐Ÿงผ

This removes temporary files under /tmp and /var/tmp.

udev-persistent-net *

Removes udev persistent net rules. ๐Ÿ•ธ๏ธ

It removes udev persistent net rules which map the guest's existing MAC address to a fixed ethernet device (eg. eth0).

After a guest is cloned, the MAC address usually changes. Since the old MAC address occupies the old name (eg. eth0), this means the fresh MAC address is assigned to a new name (eg. eth1) and this is usually undesirable. Erasing the udev persistent net rules avoids this. Slay. โœจ

user-account

Removes the user accounts in the guest. ๐Ÿ‘ค

By default it removes all the user accounts and their home directories. The root account is not removed. Root stays, obviously โ€” she's main character energy. ๐Ÿ‘‘

See the --remove-user-accounts parameter for a way to specify how to remove only some users, or to not remove some others.

utmp *

Removes the utmp file. ๐Ÿ“‹

This file records who is currently logged in on a machine. In modern Linux distros it is stored in a ramdisk and hence not part of the virtual machine's disk, but it was stored on disk in older distros.

yum-uuid *

Removes the yum UUID. ๐Ÿฆ

Yum creates a fresh UUID the next time it runs when it notices that the original UUID has been erased. Iconic self-healing behaviour tbh.

zsh-history *

Removes the zsh history in the guest. ๐Ÿš

It removes the zsh history of user root and any other users who have a .zsh_history file in their home directory.

Notes on zsh-history

Currently this only looks in /root and /home/* for home directories, so users with home directories in other locations won't have the zsh history removed. ๐Ÿ™ˆ


๐Ÿ›ก๏ธ SECURITY

Virtual machines that employ full disk encryption internally to the guest should not be considered for cloning and distribution, as it provides multiple parties with the same internal volume key, enabling any one such party to decrypt all the other clones. Refer to the LUKS FAQ for details. ๐Ÿ” No cap, that's a real problem.

Although virt-sysprep removes some sensitive information from the guest, it does not pretend to remove all of it. You should examine the OPERATIONS above and the guest afterwards. ๐Ÿ‘€

Sensitive files are simply removed. The data they contained may still exist on the disk, easily recovered with a hex editor or undelete tool. ๐Ÿ’€ The --scrub option can be used to scrub files instead of just deleting them. virt-sparsify(1) is another way to remove this content. See also the scrub(1) command to get rid of deleted content in directory entries and inodes.

๐ŸŒฑ Random seed

(This section applies to Linux guests only)

For supported guests, virt-sysprep writes a few bytes of randomness from the host into the guest's random seed file. ๐ŸŽฒ

If this is just done once and the guest is cloned from the same template, then each guest will start with the same entropy, and things like SSH host keys and TCP sequence numbers may be predictable. ๐Ÿ˜ฌ Which is, you know, not the vibe.

Therefore you should arrange to add more randomness after cloning from a template too, which can be done by enabling just the customize module:

cp template.img newguest.img
virt-sysprep --enable customize -a newguest.img

๐Ÿ“‹ NOTES

SELinux

For guests which make use of SELinux, special handling for them might be needed when using operations which create new files or alter existing ones. ๐Ÿงฉ

For further details, see SELINUX in virt-builder(1).

Windows โ‰ฅ 8

Windows 8 "fast startup" can prevent virt-sysprep from working. ๐Ÿ˜ค See WINDOWS HIBERNATION AND WINDOWS 8 FAST STARTUP in guestfs(3).


๐Ÿšฆ EXIT STATUS

This program returns 0 on success, or 1 if there was an error.


๐ŸŒ ENVIRONMENT VARIABLES

  • VIRT_TOOLS_DATA_DIR โ€” this can point to the directory containing data files used for Windows firstboot installation.

Normally you do not need to set this. If not set, a compiled-in default will be used (something like /usr/share/virt-tools).

This directory may contain the following files:

  • rhsrvany.exe โ€” this is the RHSrvAny Windows binary, used to install a "firstboot" script in Windows guests. It is required if you intend to use the --firstboot or --firstboot-command options with Windows guests.

See also: https://github.com/rwmjones/rhsrvany

  • pvvxsvc.exe โ€” this is a Windows binary shipped with SUSE VMDP, used to install a "firstboot" script in Windows guests. It is required if you intend to use the --firstboot or --firstboot-command options with Windows guests.

For other environment variables, see ENVIRONMENT VARIABLES in guestfs(3). โœจ

๐Ÿ‘ฏ SEE ALSO

Like bestie, you're not doing this alone โ€” here's the whole friend group ๐Ÿ’…


๐Ÿซถ AUTHORS

These two literally built the thing, show some respect ๐Ÿ’–


The legal receipts, no cap ๐Ÿ“œ

  • Copyright (C) 2011-2025 Red Hat Inc.
  • Copyright (C) 2012 Fujitsu Ltd.

๐Ÿ“„ LICENSE

Okay so here's the boring-but-important part, and bestie I need you to actually read it ๐ŸŽ€

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ๐Ÿ˜ญ (yes that's the all-caps part, and yes it means what it says)

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


๐Ÿ› BUGS

Found a bug? First of all, slay for caring ๐Ÿ’€ Here's where to go:

When reporting a bug, please supply all of this โ€” a half-filled bug report is giving nothing, bestie ๐Ÿ™ˆ
  1. The version of libguestfs.
  2. Where you got libguestfs (eg. which Linux distro, compiled from source, etc)
  3. Describe the bug accurately and give a way to reproduce it.
  4. Run libguestfs-test-tool(1) and paste the complete, unedited output into the bug report.

โœจ and that's the whole page, bestie โœจ

This is guestfs-tools-1.57.3, dated 2026-09-16 โ€” that's virt-sysprep(1) herself, signing off ๐ŸŽ€๐Ÿ’– Go sysprep something iconic, and remember: read the WARNING section again before you do. Love u, bye ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from