How to Use the Command qm (with examples)

How to Use the Command qm (with examples)

QEMU/KVM Virtual Machine Manager is a command-line tool used for managing QEMU-based virtual machines on Proxmox Virtual Environment (PVE). The qm command provides various functionalities for creating, configuring, and managing virtual machines. This article will illustrate different use cases of the qm command.

Use case 1: List all virtual machines

Code:

qm list

Motivation: This use case is useful when you want to get a list of all virtual machines running on the Proxmox server. It provides an overview of the existing virtual machines, along with their IDs and status.

Example Output:

VMID  Name            Status     Mem(MiB)    Disk(GiB)  PID
100   myvm1           running    1024        10.00      1234
101   myvm2           stopped    512         20.00      -
102   myvm3           running    2048        30.00      5678

Use case 2: Create a virtual machine using an ISO file

Code:

qm create 100 -ide0 local-lvm:4 -net0 e1000 -cdrom local:iso/proxmox-mailgateway_2.1.iso

Motivation: This use case allows you to create a new virtual machine with specific configurations. In this example, we create a virtual machine with an ID of 100, a 4 GB IDE disk on the local-lvm storage, and an e1000 network interface. Additionally, we specify an ISO file located in the iso/proxmox-mailgateway_2.1.iso path as the CD-ROM for the virtual machine.

Explanation:

  • qm create: Command to create a new virtual machine.
  • 100: ID of the virtual machine to be created.
  • -ide0 local-lvm:4: Specifies the IDE disk of size 4 GB and the storage location local-lvm.
  • -net0 e1000: Specifies the network interface as e1000.
  • -cdrom local:iso/proxmox-mailgateway_2.1.iso: Specifies the ISO file to be mounted as the CD-ROM.

Example Output: No specific output will be displayed upon successful execution. The virtual machine will be created with the provided configurations.

Use case 3: Show the configuration of a virtual machine

Code:

qm config 100

Motivation: This use case is helpful when you want to view the current configuration of a specific virtual machine. It provides detailed information about the virtual machine’s configurations, such as networks, disks, and other parameters.

Explanation:

  • qm config: Command to display the configuration of a virtual machine.
  • 100: ID of the virtual machine whose configuration needs to be shown.

Example Output:

balloon: 1048576
bios: ovmf
boot: c
bootdisk: virtio0
cores: 2
cpulimit: 0
cpuunits: 1000
efidisk0: local-lvm:64
ide2: none,media=cdrom
memory: 4096
name: myvm1
net0: virtio=02:A3:BD:61:F9:49,bridge=vmbr0
net1: e1000=02:4D:51:80:D5:8F,bridge=vmbr1
numa: 0
ostype: l26
smbios1: uuid=f2212345-d925-4f9c-baff-012345678901
sockets: 1
virtio0: local-lvm:10
vmgenid: 01234567-abcd-ef01-2345-6789abcdef01

Use case 4: Start a specific virtual machine

Code:

qm start 100

Motivation: This use case allows the user to start a specific virtual machine. It is useful when you want to power on a virtual machine that is currently stopped.

Explanation:

  • qm start: Command to start a virtual machine.
  • 100: ID of the virtual machine to be started.

Example Output: No specific output will be displayed upon successful execution. The virtual machine will be started and its status will change to “running”.

Use case 5: Send a shutdown request and wait until the virtual machine is stopped

Code:

qm shutdown 100 && qm wait 100

Motivation: This use case is helpful when you want to gracefully shut down a virtual machine and wait until it is completely stopped before performing further actions.

Explanation:

  • qm shutdown: Command to send a shutdown request to a virtual machine.
  • 100: ID of the virtual machine to be shut down.
  • qm wait: Command to wait until a virtual machine is stopped.
  • 100: ID of the virtual machine to wait for.

Example Output: No specific output will be displayed upon successful execution. The virtual machine will be shut down, and the command will wait until the virtual machine is fully stopped before returning.

Code:

qm destroy 100 --purge

Motivation: This use case is useful when you want to permanently remove a virtual machine and all its related resources, including disks, snapshots, and backups.

Explanation:

  • qm destroy: Command to destroy a virtual machine.
  • 100: ID of the virtual machine to be destroyed.
  • --purge: Optional argument to remove all related resources.

Example Output: No specific output will be displayed upon successful execution. The virtual machine will be destroyed, and all its related resources will be removed.

Conclusion:

The qm command provides a comprehensive set of functionalities for managing QEMU-based virtual machines on Proxmox Virtual Environment. By exploring the various use cases illustrated in this article, users can effectively create, configure, and manage virtual machines according to their specific requirements.

Tags :

Related Posts

How to use the command `calc` (with examples)

How to use the command `calc` (with examples)

calc is an interactive arbitrary-precision calculator that can be used in the terminal.

Read More
Compiling C++ Source Files with Clang++ (with examples)

Compiling C++ Source Files with Clang++ (with examples)

1: Compiling a Source Code File into an Executable Binary clang++ path/to/source.

Read More
How to use the command spectacle (with examples)

How to use the command spectacle (with examples)

Spectacle is KDE’s screenshot utility that allows users to capture screenshots of their desktop, active window, or a specific region.

Read More