Proxmox VE: Useful Terminal Commands

This document provides a curated collection of essential command-line interface (CLI) commands for managing your Proxmox Virtual Environment (VE) setup. While Proxmox offers a comprehensive web interface, direct terminal access allows for scripting, automation, and advanced troubleshooting.

Windows 11 install tips

1. VM/Container Management (qm and pct)

The qm command-line tool is used for managing KVM virtual machines, while pct is used for LXC containers. These commands are essential for controlling the lifecycle of your virtualized guests.

  • List all VMs and Containers:

    qm list # Lists KVM virtual machines
    pct list # Lists LXC containers

    This shows VMID/CTID, name, status, memory, and disk usage.

  • Start a VM/Container:

    qm start <VMID>
    pct start <CTID>
    # Example:
    qm start 100
  • Stop a VM/Container (graceful shutdown):

    qm shutdown <VMID>
    pct shutdown <CTID>
    # This sends an ACPI shutdown signal (VM) or gracefully stops the container.
  • Stop a VM/Container (forced power off/stop):

    qm stop <VMID>
    pct stop <CTID>
    # WARNING: This forcefully terminates the VM/container and can cause data corruption.
  • Check VM/Container Status:

    qm status <VMID>
    pct status <CTID>
    # Example:
    qm status 100
  • Create a VM (Example with Common Options): Creating a VM from the CLI allows for precise control. This example shows a basic creation and setting an ISO.

    # Create VM 101 with name "my-web-server", 2GB RAM, 2 CPU cores
    qm create 101 --name my-web-server --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
     
    # Add a virtual disk (e.g., 32GB on local-lvm storage)
    qm set 101 --scsi0 local-lvm:32
     
    # Attach an ISO image for installation (e.g., Ubuntu 22.04 ISO from local storage)
    qm set 101 --ide2 local:iso/ubuntu-22.04.iso,media=cdrom
     
    # Set boot device (e.g., boot from disk)
    qm set 101 --boot order=scsi0

2. Storage Replication (pvesr)

The pvesr command-line tool manages the Proxmox VE storage replication framework, which is crucial for high availability and disaster recovery.

  • Create a Replication Job:

    pvesr create-local-job <VMID>-0 <TARGET_NODE> --schedule "*/5" --rate 10

    This example creates a replication job for <VMID> (e.g., 100-0 for VM 100’s disk 0) to <TARGET_NODE>, running every 5 minutes with a bandwidth limit of 10 Mbps.

  • Disable a Replication Job:

    pvesr disable <JOB_ID>
    # Example:
    pvesr disable 100-0
  • Enable a Replication Job:

    pvesr enable <JOB_ID>
    # Example:
    pvesr enable 100-0
  • Change the Schedule of a Replication Job:

    pvesr update <JOB_ID> --schedule "0 * * * *"
    # This changes the schedule for <JOB_ID> to run once per hour.

3. High Availability (ha-manager)

The ha-manager tool automates the management of high availability for VMs and containers within a Proxmox cluster.

  • Add a VM/Container to HA Configuration:

    ha-manager add vm:<VMID>
    ha-manager add ct:<CTID>
    # Example:
    ha-manager add vm:150 # Adds VM with ID 150 to HA.
  • Set the State of an HA-Managed VM/Container:

    ha-manager set vm:<VMID> --state started
    # This command attempts to start the VM/container and keeps it running according to HA rules.
  • View HA Manager and Resource State:

    ha-manager status

4. Cluster Administration (pvecm)

The pvecm command is used for managing the Proxmox VE cluster itself, including checking status and adding nodes.

  • Check Cluster Status:

    pvecm status
    # This provides a snapshot of your cluster's health, member nodes, and quorum status.
  • Add Nodes to a Cluster:

    pvecm add <NODE_IP>
    # Used to join a new Proxmox node to an existing cluster.

5. Backups (vzdump)

The vzdump utility is used for creating backups of VMs and containers, supporting various backup modes and compression options.

  • Create a Backup of a VM/Container:
    vzdump <VMID_OR_CTID> --mode snapshot --compress zstd --storage <STORAGE_NAME>
    # Example:
    vzdump 100 --mode snapshot --compress zstd --storage local
    • --mode snapshot: Creates a live snapshot of the VM (requires qemu-guest-agent for consistency).
    • --compress zstd: Uses Zstandard compression for the backup file.
    • --storage <STORAGE_NAME>: Specifies the Proxmox storage where the backup will be saved (e.g., local, backup-nfs).