virt-clone
Clone existing virtual machines
TLDR
Clone a virtual machine and automatically generate a new name, storage path, and MAC address
Clone a virtual machine and specify the new name, storage path, and MAC address
SYNOPSIS
virt-clone [OPTIONS] -o ORIGINAL_VM -n NEW_VM -f DISK_LOCATION
PARAMETERS
-o, --original ORIGINAL_VM
Name of the original virtual machine to clone.
-n, --name NEW_VM
Name for the new, cloned virtual machine.
-u, --uuid UUID
Specify the UUID for the new virtual machine. If not provided, a random UUID will be generated.
-f, --file DISK_LOCATION
Location to store the cloned virtual disk image. This option can be repeated to clone multiple disks. Use --auto-clone to allow auto disk naming.
--auto-clone
Automatically clone all disks from the original guest, creating appropriate names for the new disks.
--connect URI
Connect to a non-default hypervisor. If omitted, the default hypervisor connection will be used.
--preserve-data
Preserve the source data on the original VM's disk(s). (Use with caution)
--noreboot
Do not start the cloned VM automatically after cloning.
--replace
Replace an existing VM with the same name.
--mac MAC_ADDRESS
Specify a MAC address for the cloned VM. If omitted, a random MAC address is generated.
-h, --help
Show help message and exit.
-q, --quiet
Suppress non-error output.
--print-xml
Print the XML definition of the cloned VM instead of creating it.
DESCRIPTION
The `virt-clone` command is a command-line tool used to clone existing virtual machines managed by libvirt. It creates a complete copy of the source VM, including its virtual disks and configuration files, allowing you to easily create new, independent virtual machines based on a template. `virt-clone` handles updating the network configuration, disk UUIDs, and other parameters that need to be unique for each VM. It is particularly useful for creating multiple VMs with similar configurations or for testing software in a sandboxed environment without affecting the original VM.
Cloning is generally faster than installing a new VM from scratch. The cloning process requires the source VM to be shut down during the cloning process, or be in a consistent saved state if supporting snapshots and offline cloning. `virt-clone` ensures that each cloned guest can boot independently by modifying the MAC address, UUID, and other parameters.
CAVEATS
The source VM must be shut down for consistent cloning. Cloning performance depends heavily on storage type and the size of the VM's virtual disks. Certain operations might require elevated privileges (root).
STORAGE CONSIDERATIONS
When cloning a VM, be mindful of the storage space required. Ensure that there is enough free space on the storage volume where the cloned disks will be created. Using thin-provisioned disks can help to reduce the initial storage footprint, but the storage will increase over time as needed.
NETWORK CONFIGURATION
`virt-clone` automatically updates the MAC address of the cloned VM to avoid conflicts on the network. However, depending on the guest operating system's network configuration, you may need to manually adjust the network settings within the cloned VM to ensure it obtains a valid IP address.
HISTORY
The `virt-clone` command is part of the `virt-manager` suite of tools, designed to simplify the management of virtual machines using libvirt. It has evolved alongside libvirt, adding features and improving performance over time to support increasingly complex virtualization scenarios. Its purpose is to streamline the process of creating new VMs from existing templates or base images.
SEE ALSO
virsh(1), virt-install(1), qemu-img(1)