How to use the command `qm` (with examples)
- Linux
- December 17, 2024
The qm
command acts as a Virtual Machine manager for QEMU/KVM on Proxmox. It’s primarily utilized for effectively managing virtual machines hosted on Proxmox VE servers. This command contains several subcommands, each designed to perform specific tasks related to virtual machine management, such as listing, creating, configuring, starting, stopping, and destroying virtual machines. The command is a powerful tool within Proxmox for system administrators to automate and efficiently handle the lifecycle of their virtual machines.
Use case 1: List all virtual machines
Code:
qm list
Motivation:
Listing all virtual machines is one of the primary tasks for an administrator managing a virtualized environment. This provides an overview of all virtual machines present in the infrastructure, including their ID, name, status, memory, and other essential attributes. It’s particularly useful to quickly assess the current state of the environment and to keep track of available virtual resources.
Explanation:
qm
: This is the command-line interface for managing QEMU/KVM virtual machines in Proxmox.list
: This subcommand lists all the virtual machines under the Proxmox server, providing a summarized view of each VM’s information.
Example Output:
VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID
100 ExampleVM1 running 2048 32 1234
101 ExampleVM2 stopped 4096 64 0
Use case 2: Using an ISO file uploaded on the local storage, create a virtual machine with a 4 GB IDE disk on the local-lvm
storage and an ID of 100
Code:
qm create 100 -ide0 local-lvm:4 -net0 e1000 -cdrom local:iso/proxmox-mailgateway_2.1.iso
Motivation:
Creating a new virtual machine is a fundamental operation in provisioning new environments for development, testing, or production. This command utilizes an ISO file for the installation media, allowing the administrator to set up a new VM based on predefined storage and network settings. It offers flexibility in configuring the storage type and network interfaces that align with infrastructure policies.
Explanation:
qm create
: Initiates the creation of a new virtual machine.100
: Assigns a unique ID of 100 to the virtual machine being created.-ide0 local-lvm:4
: Specifies that an IDE disk of 4 GB should be created on thelocal-lvm
storage.-net0 e1000
: Sets up the network interface of the VM, using the E1000 adapter model.-cdrom local:iso/proxmox-mailgateway_2.1.iso
: Utilizes the specified ISO file as the boot media, located on the local storage under theiso
directory.
Example Output:
Virtual machine 100 created
Use case 3: Show the configuration of a virtual machine, specifying its ID
Code:
qm config 100
Motivation:
Reviewing the configuration of an existing virtual machine is critical for maintenance, tuning, and troubleshooting. By examining the VM’s configuration, system administrators can verify settings, audit the system state, and prepare adjustments to the VM’s specifications.
Explanation:
qm config
: This subcommand retrieves and displays the configuration of a specified virtual machine.100
: Specifies the ID of the virtual machine whose configuration is to be shown.
Example Output:
bootdisk: ide0
cores: 2
ide0: local-lvm:vm-100-disk-0,format=qcow2,size=4G
memory: 2048
name: ExampleVM1
net0: e1000=DE:AD:BE:EF:AA:BB,bridge=vmbr0
Use case 4: Start a specific virtual machine
Code:
qm start 100
Motivation:
Starting a virtual machine is necessary to bring it online and make its resources available to users or applications. This operation is essential when a VM needs to be used after configuration changes or after a downtime.
Explanation:
qm start
: Initiates the start operation.100
: Indicates the ID of the virtual machine to be started.
Example Output:
Starting VM 100
Use case 5: Send a shutdown request, then wait until the virtual machine is stopped
Code:
qm shutdown 100 && qm wait 100
Motivation:
Gracefully shutting down a virtual machine ensures that all processes are closed properly, and data is safely written to disk, minimizing data corruption risks. The combined usage with the wait
subcommand guarantees that operations only proceed once the VM is fully stopped.
Explanation:
qm shutdown
: Sends a request to shut down the virtual machine.100
: Specifies the virtual machine’s ID to be shut down.&&
: Logical AND operator to run the next command only if the current command succeeds.qm wait
: Pauses any further actions until the specified VM has completely stopped.
Example Output:
Shutdown VM 100
Waiting for VM 100 to stop...
Use case 6: Destroy a virtual machine and remove all related resources
Code:
qm destroy 100 --purge
Motivation:
Removing a virtual machine along with all its associated resources is necessary when cleaning up unused systems or retiring obsolete environments, ensuring that you recover allocated resources back to the pool. This helps maintain a tidy and efficient virtual environment.
Explanation:
qm destroy
: Removes the specified virtual machine.100
: Denotes the ID of the virtual machine to be destroyed.--purge
: Ensures that all resources related to the virtual machine are completely removed from the system.
Example Output:
Destroying VM 100
VM 100 and all associated resources have been successfully removed
Conclusion
The qm
command-line interface is a robust tool for managing virtual machines in a Proxmox environment. Understanding how to use these various subcommands empowers administrators to efficiently create, manage, and terminate virtual machines, ensuring smooth operation and resource management in their virtualized infrastructure. Each use case demonstrates the command’s capabilities and showcases how specific parameters can be leveraged for practical VM management tasks.