2.5. Cloning Virtual Machines and Containers¶
You can create a copy (clone) of a particular virtual machine or container that will have identical data and resource parameters. Cloning may save time as clones require little reconfiguration compared to setting up new virtual machines or containers.
You can clone stopped virtual machines and stopped and running containers. For example:
# prlctl clone MyCT --name MyCT_clone
# prlctl clone MyVM --name MyVM_clone
The --name
option specifies a name for the clone.
When cloning Windows virtual machines, consider changing their security identifiers (SIDs) with the --changesid
option.
Note
For Windows 2019 VMs, use Microsoft’s Sysprep tool instead of the --changesid
option.
Successfully cloned virtual machines and containers will be shown in the list of virtual environments on the host. For example:
# prlctl list -a
UUID STATUS IP_ADDR T NAME
{62951c2a-...} stopped 10.30.10.101 CT MyCT
{49b66605-...} stopped 10.30.10.101 CT MyCT_clone
{7f4904ad-...} stopped 10.30.128.115 VM MyVM
{2afb2aa2-...} stopped 10.30.128.134 VM MyVM_clone
The example above shows that the cloned container has the same IP address as the original container. Before starting to use the clones, make sure their IP addresses are unique (for instructions on how to assign IP addresses to VMs and containers, see Configuring Network Settings).
Note the following:
When cloning a virtual machine, the MAC address of a network adapter in the clone changes. Thus, it may require additional reconfiguration for guest OSs that do not automatically obtain the MAC addresses of network adapters.
A cloned SUSE Linux Enterprise Server 15 SP6 virtual machine gets a NIC name with an index increased by one. For example, if an original NIC name is
eth0
, it will acquire +1 to its existing name. Thus, the name will change toeth1
. The subsequent clone operation from the cloned VM will cause the same changes to the NIC name of a newly cloned VM, i.e.,eth2
,eth3
, etc.To avoid situations when cloned SUSE Linux Enterprise Server 15 SP6 virtual machines obtain duplicate IP addresses via DHCP, regenerate
machine-id
according to the instructions from Resolving Duplicate Machine IDs in Cloned Salt Clients.
2.5.1. Creating Linked Clones¶
Starting from Virtuozzo Hybrid Server 7.0.7 (Update 7), you can create linked clones of virtual machines. A linked clone is a copy of a virtual machine that shares virtual disks with the original virtual machine. Linked clones take less time and disk space to deploy as they store only changes to the original disks rather than copy them whole. A linked clone cannot run without access to its parent, so make sure the original virtual machine is available and its disks are not corrupted.
To create a linked clone, add the --linked
option to the prlctl clone
command. For example:
# prlctl clone MyVM --name MyVM_linked_clone --linked
On the host, linked clones are shown as usual virtual machines. For example:
# prlctl list -a
UUID STATUS IP_ADDR T NAME
{7f4904ad-...} stopped 10.30.128.115 VM MyVM
{2e9862f6-...} stopped 10.30.128.135 VM MyVM_linked_clone
Note
Migration, backup, restore, and unlink operations are not supported for linked clones.
2.5.2. Configuring Default Directories¶
When cloning a virtual machine or container, you can also override the following default directories:
default directory
/vz/vmprivate/<dest_UUID>
storing the files of a cloned virtual machine (where<dest_UUID>
denotes the UUID of the resulting virtual machine). To store the files of theMyVM_clone
virtual machine in a custom directory, you can run the following command:# prlctl clone MyVM --name MyVM_clone --dst vz/vmprivate/customVMs
In this case all virtual machine files will be placed to the
/customVMs
directory. Note that the specified directory must exist on the server; otherwise, the command will fail.default directory
/vz/private/<dest_UUID>
defining the container private area (where<dest_UUID>
denotes the UUID of the resulting container). To define a custom private area path for the containerMyCT_clone
, you can execute the following command:# prlctl clone MyCT1 --name MyCT_clone --dst /vz/private/customCTs
Note
The default /vz/vmprivate
and /vz/private
are valid for servers that do not participate in Virtuozzo Hybrid Server storage clusters.