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โ Addfilewhich 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 withguestfish. See โADDING REMOTE STORAGEโ inguestfish(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-sysprepnormally 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-aoption is to auto-detect the format of the disk image. Using this forces the disk format for-aoptions which follow on the command line. Using--format autoswitches back to auto-detection for subsequent-aoptions.
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โNAMEis the libguestfs device name (eg./dev/sda1).UUIDis the device UUID.allmeans 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 fromFILENAME.--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โ inguestfs(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:errorcan 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 thevirt-sysprepprogram.
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 ontoFILE. 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 theLINEstring, 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 ofFILEtoPERMISSIONS.
โ ๏ธ Okay bestie, listen:PERMISSIONSis decimal by default unless you prefix it with0to get octal โ so use0700, NOT700. 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 directoryREMOTEDIR(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) โ editsFILEusing the Perl expressionEXPR.
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) โ installsSCRIPTinside 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 toHOSTNAME. You can use a dottedhostname.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 atLINKand pointing atTARGET. 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) โ scrubsbuilder.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 forUSER. (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 tomd5,sha256orsha512.
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--editoption 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) calledSCRIPTon 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 namedSCRIPT(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 thescriptoperation is enabled and one or more scripts are specified using--scriptparameter(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 givenUSERwill 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 calledTARFILEinto the disk image, placing them in the directoryREMOTEDIR(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 toTIMEZONE. (see โcustomizeโ below)
Use a location string like Europe/London ๐ฐ๏ธ
--touch FILEโ this command performs atouch(1)-like operation onFILE. (see โcustomizeโ below)--truncate FILEโ this command truncatesFILEto 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 underPATHto 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 ofyum 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 fileFILEto destinationDESTin 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โ writesCONTENTtoFILE. (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--firstbootscripts (which run in the context of the guest when it is booting first time).--scriptscripts 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--firstbootor--firstboot-commandoptions 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--firstbootor--firstboot-commandoptions 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 ๐
guestfs(3)โ the big libguestfs API page, the mothership ๐ธguestfish(1)โ the interactive shell situationvirt-builder(1)โ for building images from scratch, iconicvirt-clone(1)โ the cloning onevirt-customize(1)โ literallyvirt-sysprep's sibling, related energyvirt-rescue(1)โ rescue mode, main character energyvirt-resize(1)โ resizing, obviouslyvirt-sparsify(1)โ the sparsifying onevirsh(1)โ libvirt's CLI, you know herlvcreate(8)โ LVM, section 8, don't askqemu-img(1)โ image tooling ๐ซถscrub(1)โ yes, thatscrubhttp://libguestfs.org/โ the website, go look ๐http://libvirt.org/โ and the other website, also go look โจ
๐ซถ AUTHORS
These two literally built the thing, show some respect ๐
- Richard W.M. Jones โ
http://people.redhat.com/~rjones/ - Wanlong Gao, Fujitsu Ltd.
ยฉ๏ธ COPYRIGHT
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:
- To get a list of bugs against libguestfs, use this link:
https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools - To report a new bug against libguestfs, use this link:
https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
When reporting a bug, please supply all of this โ a half-filled bug report is giving nothing, bestie ๐
- The version of libguestfs.
- Where you got libguestfs (eg. which Linux distro, compiled from source, etc)
- Describe the bug accurately and give a way to reproduce it.
- 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
- centos-stream 10: guestfs-tools 1.57.3-1.el10 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms