virt-sysprep

Prepare VM images for cloning

TLDR

List available operations
$ virt-sysprep --list-operations
Remove sensitive data
$ sudo virt-sysprep -a [path/to/image.qcow2]
Dry run by domain name
$ sudo virt-sysprep -d [vm_name] -n
Run specific operations
$ sudo virt-sysprep -d [vm_name] --operations [operation1,operation2]
Set hostname and machine-id
$ sudo virt-sysprep -d [vm_name] --enable customizations --hostname [host_name] --operation machine-id

SYNOPSIS

virt-sysprep [OPTIONS]

DESCRIPTION

virt-sysprep resets, unconfigures, or customizes a virtual machine image for cloning or deployment. It removes machine-specific data like SSH keys, logs, and persistent device names.This prepares VM images for use as templates by removing identity information that should be unique per machine.

PARAMETERS

-a, --add IMAGE

Add disk image
-d, --domain VM
Specify VM by name
-n, --dry-run
Show what would be done without making changes
--operations OPS
Run only specified operations
--list-operations
List all supported operations
--hostname NAME
Set hostname
--enable FEATURE
Enable specific feature

INSTALL

sudo apt install guestfs-tools
sudo dnf install guestfs-tools
sudo pacman -S guestfs-tools
sudo zypper install guestfs-tools
nix profile install nixpkgs#guestfs-tools

CAVEATS

VM must be shut down. Root privileges typically required. Some operations may break the VM if used incorrectly. Always backup images before processing.

SEE ALSO

virt-clone(1), virt-customize(1)