How to use the command qm clone (with examples)

How to use the command qm clone (with examples)

The qm clone command is used to create a copy of a virtual machine in QEMU/KVM Virtual Machine Manager. This command allows users to duplicate an existing virtual machine, with the option to customize the name, description, file storage format, and pool association of the new copy.

Use case 1: Copy a virtual machine

Code:

qm clone vm_id new_vm_id

Motivation: The motivation for using this example is to create a new copy of an existing virtual machine, which can be useful for testing purposes or for creating similar instances with different configurations.

Explanation:

  • qm clone: the command to clone a virtual machine.
  • vm_id: the ID of the virtual machine to be cloned.
  • new_vm_id: the ID of the new virtual machine that will be created.

Example output:

Cloning virtual machine 100...
New virtual machine 200 created successfully.

Use case 2: Copy a virtual machine using a specific name

Code:

qm clone vm_id new_vm_id --name name

Motivation: The motivation for using this example is to customize the name of the new virtual machine, making it easier to identify and manage different instances.

Explanation:

  • –name name: specifies the name of the new virtual machine.
  • name: the desired name for the new virtual machine.

Example output:

Cloning virtual machine 100 with the name "My VM"...
New virtual machine 200 with the name "My VM" created successfully.

Use case 3: Copy a virtual machine using a specific description

Code:

qm clone vm_id new_vm_id --description description

Motivation: The motivation for using this example is to provide a description for the new virtual machine, helping users to understand its purpose or configuration details.

Explanation:

  • –description description: specifies the description of the new virtual machine.
  • description: the desired description for the new virtual machine.

Example output:

Cloning virtual machine 100 with the description "Test VM"...
New virtual machine 200 with the description "Test VM" created successfully.

Use case 4: Copy a virtual machine creating a full copy of all disks

Code:

qm clone vm_id new_vm_id --full

Motivation: The motivation for using this example is to create a complete copy of the virtual machine, including all attached disks, ensuring that the new instance is an exact replica of the original one.

Explanation:

  • –full: specifies that a full copy of all disks should be created.

Example output:

Cloning virtual machine 100 with all disks...
New virtual machine 200 with all disks created successfully.

Use case 5: Copy a virtual machine using a specific format for file storage (requires –full)

Code:

qm clone vm_id new_vm_id --full --format qcow2|raw|vmdk

Motivation: The motivation for using this example is to choose a different file storage format for the new virtual machine, which can affect performance or compatibility with other hypervisors.

Explanation:

  • –full: specifies that a full copy of all disks should be created.
  • –format qcow2|raw|vmdk: specifies the format for file storage.
  • qcow2|raw|vmdk: the desired file storage format for the new virtual machine.

Example output:

Cloning virtual machine 100 with all disks and using the qcow2 format...
New virtual machine 200 with all disks created successfully using the qcow2 format.

Use case 6: Copy a virtual machine then add it to a specific pool

Code:

qm clone vm_id new_vm_id --pool pool_name

Motivation: The motivation for using this example is to immediately associate the new virtual machine with a specific pool, allowing for easier organization and management of multiple instances.

Explanation:

  • –pool pool_name: specifies the pool to which the new virtual machine should be added.
  • pool_name: the name of the pool to associate the new virtual machine with.

Example output:

Cloning virtual machine 100 and adding it to the pool "My Pool"...
New virtual machine 200 added successfully to the pool "My Pool".

Conclusion:

The qm clone command in QEMU/KVM Virtual Machine Manager provides a versatile way to create copies of virtual machines, offering options to customize the name, description, file storage format, and pool association of the new instances. These examples demonstrate the various use cases of the command, showcasing its flexibility and usefulness in managing virtual machines.

Related Posts

How to use the command 'az storage' (with examples)

How to use the command 'az storage' (with examples)

Azure Cloud Storage is a feature offered by Microsoft Azure that allows users to store and manage large amounts of unstructured data like documents, images, videos, etc.

Read More
How to use the command 'xrdb' (with examples)

How to use the command 'xrdb' (with examples)

The ‘xrdb’ command is a resource database utility for Unix-like systems that is used to manage resources in the X Window System.

Read More
How to use the command 'nomad' (with examples)

How to use the command 'nomad' (with examples)

The ’nomad’ command is a distributed, highly available, datacenter-aware scheduler that allows users to manage jobs and nodes in a cluster.

Read More