qm destroy (with examples)

qm destroy (with examples)

QEMU/KVM Virtual Machine Manager is a powerful tool for managing virtual machines in Proxmox VE. One of the commands provided by QEMU/KVM is the qm destroy command, which allows users to destroy virtual machines in a controlled manner. In this article, we will explore eight different use cases of the qm destroy command and provide code examples for each use case.

Use Case 1: Destroy a specific virtual machine

qm destroy vm_id

Motivation:

Destroying a specific virtual machine is a common task when managing virtual machines. This use case allows you to easily remove a virtual machine without affecting other running instances.

Arguments:

  • vm_id: The ID of the virtual machine to destroy.

Example Output:

Virtual machine with ID 100 destroyed successfully.

Use Case 2: Destroy all disks that are not explicitly referenced in a specific virtual machine’s configuration

qm destroy vm_id --destroy-unreferenced-disks

Motivation:

When a virtual machine is deleted, the disks associated with it may not be explicitly removed. This use case allows you to automatically destroy any unreferenced disks, saving storage space and ensuring that no unused data remains.

Arguments:

  • vm_id: The ID of the virtual machine to destroy.
  • --destroy-unreferenced-disks: Specifies that all disks not explicitly referenced in the virtual machine’s configuration should be destroyed.

Example Output:

Destroying unreferenced disk /var/lib/vz/images/100/vm-100-disk-0.qcow2
Disk /var/lib/vz/images/100/vm-100-disk-0.qcow2 destroyed successfully.

Use Case 3: Destroy a virtual machine and remove from all locations

qm destroy vm_id --purge

Motivation:

When a virtual machine is destroyed, it is often desirable to remove it from all locations, including the inventory, backup jobs, and high availability managers. This use case provides a convenient way to remove a virtual machine completely.

Arguments:

  • vm_id: The ID of the virtual machine to destroy.
  • --purge: Specifies that the virtual machine should be removed from all locations.

Example Output:

Virtual machine with ID 100 removed from the inventory.
Virtual machine with ID 100 removed from backup jobs.
Virtual machine with ID 100 removed from high availability managers.

Use Case 4: Destroy a specific virtual machine ignoring locks and forcing destroy

sudo qm destroy vm_id --skiplock

Motivation:

Sometimes, a virtual machine may be locked due to ongoing operations. This use case allows you to force the destruction of a virtual machine, even if it is currently locked. It can be useful when dealing with stuck or unresponsive virtual machines.

Arguments:

  • vm_id: The ID of the virtual machine to destroy.
  • --skiplock: Specifies that locks should be ignored and the destroy operation forced.

Example Output:

Virtual machine with ID 100 destroyed successfully, even though it was locked.

These are just a few examples of how the qm destroy command can be used to manage virtual machines in QEMU/KVM Virtual Machine Manager. By leveraging the power and flexibility of this command, you can easily destroy virtual machines and associated resources according to your specific requirements.

Related Posts

How to use the command "resize2fs" (with examples)

How to use the command "resize2fs" (with examples)

Resize automatically the filesystem resize2fs /dev/sdXN Motivation The motivation for automatically resizing a filesystem is when you want to adjust the size of the filesystem to match the size of the underlying partition.

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

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

The ‘az devops’ command is part of the Azure Command-Line Interface (CLI) and it allows you to manage Azure DevOps organizations.

Read More
Exploring npm-why (with examples)

Exploring npm-why (with examples)

1: Show why an npm package is installed Code: npm-why package Motivation: Understanding why a specific npm package is installed can be crucial for managing dependencies and troubleshooting issues.

Read More