| name | proxmox-ve |
| description | Manage QEMU/KVM virtual machines on Proxmox VE using the qm command-line tool. Use when working with Proxmox VE for: (1) VM lifecycle operations (create, start, stop, destroy), (2) Cloning VMs and creating templates, (3) Snapshot management and rollback, (4) VM migration between nodes, (5) Disk operations (import, resize, move), (6) Guest agent interactions, (7) Cloud-init configuration, (8) Any task involving the 'qm' command or Proxmox VM management. |
Proxmox VE VM Management
Comprehensive VM management for Proxmox VE using the qm command-line tool with helper scripts for common operations and reference documentation.
Quick Start
The qm command is the primary tool for managing QEMU/KVM virtual machines in Proxmox VE:
qm list
qm status <vmid>
qm start <vmid>
qm shutdown <vmid>
qm stop <vmid>
Core Operations
1. VM Lifecycle Management
Use the provided vm_lifecycle.py script for safe VM operations with validation:
python3 scripts/vm_lifecycle.py start 100
python3 scripts/vm_lifecycle.py stop 100
python3 scripts/vm_lifecycle.py stop 100 --force
python3 scripts/vm_lifecycle.py restart 100
python3 scripts/vm_lifecycle.py status 100
python3 scripts/vm_lifecycle.py destroy 100
Or use qm commands directly:
qm create 100 --name myvm --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
qm set 100 --memory 4096 --cores 4
qm set 100 --scsi0 local-lvm:32
qm start 100
qm shutdown 100
qm stop 100
qm reboot 100
qm destroy 100
2. Cloning VMs
Use the clone_vm.py script for validated cloning:
python3 scripts/clone_vm.py 100 200 --name cloned-vm
python3 scripts/clone_vm.py 100 201 --name test-vm --linked
python3 scripts/clone_vm.py 100 202 --target node2 --name remote-clone
Or use qm directly:
qm clone 100 200 --name cloned-vm --full
qm clone 100 201 --name test-vm
qm clone 100 202 --target node2 --storage node2-storage --full
3. Template Management
Use the create_template.py script for best-practice template creation:
python3 scripts/create_template.py 900
python3 scripts/create_template.py 900 --skip-prep
The script guides through proper VM preparation:
- Cleaning temporary files and logs
- Removing SSH host keys
- Clearing machine-id
- Installing cloud-init
- System updates
Or use qm directly (after manual preparation):
qm set 900 --ide2 local-lvm:cloudinit
qm template 900
qm clone 900 100 --name web-server --full
4. Snapshot Management
Use the snapshot_manager.py script for snapshot operations:
python3 scripts/snapshot_manager.py create 100
python3 scripts/snapshot_manager.py create 100 \
--name before-upgrade \
--description "Before kernel upgrade"
python3 scripts/snapshot_manager.py create 100 --vmstate
python3 scripts/snapshot_manager.py list 100
python3 scripts/snapshot_manager.py delete 100 before-upgrade
python3 scripts/snapshot_manager.py rollback 100 before-upgrade
Or use qm directly:
qm snapshot 100 before-upgrade --description "Before upgrade" --vmstate
qm listsnapshot 100
qm rollback 100 before-upgrade
qm delsnapshot 100 before-upgrade
5. Migration
Migrate VMs between nodes in the cluster:
qm migrate 100 node2 --online
qm shutdown 100
qm migrate 100 node2
qm start 100
qm migrate 100 node2 --online --bwlimit 100000
6. Disk Operations
qm set 100 --scsi1 local-lvm:50
qm disk resize 100 scsi0 +20G
qm disk move 100 scsi0 --storage faster-storage
qm disk import 100 /tmp/disk.qcow2 local-lvm
qm set 100 --scsi2 local-lvm:vm-100-disk-2
qm set 100 --delete scsi1
7. Guest Agent Operations
Requires qemu-guest-agent installed in VM:
qm set 100 --agent 1
qm guest cmd 100 fsfreeze-freeze
qm guest cmd 100 fsfreeze-thaw
qm guest cmd 100 shutdown
qm guest exec 100 -- /bin/ls -la /tmp
qm guest passwd 100 root
8. Cloud-Init Configuration
qm set 100 --ide2 local-lvm:cloudinit
qm set 100 --ciuser admin --cipassword securepass
qm set 100 --ipconfig0 ip=192.168.1.100/24,gw=192.168.1.1
qm set 100 --ipconfig0 ip=dhcp
qm set 100 --nameserver 8.8.8.8 --searchdomain example.com
qm set 100 --sshkeys ~/.ssh/authorized_keys
qm cloudinit dump 100 user
qm cloudinit dump 100 network
When to Use What
Use Scripts When
- Need validation and safety checks
- Want automatic waiting/polling for state changes
- Working interactively and want guided experience
- Need consistent error handling
Use qm Commands When
- Writing automation scripts
- Need maximum flexibility and control
- Using advanced options not in helper scripts
- Integrating with other tools
Reference Documentation
Complete Command Reference
See references/qm-command-reference.md for comprehensive documentation of all qm commands, options, and flags.
Step-by-Step Workflows
See references/common-workflows.md for detailed guides on:
- Creating VMs from scratch
- Template creation and usage
- Snapshot-based workflows
- Cloning strategies
- Migration procedures
- Disk management tasks
- Cloud-init setup
Best Practices
See references/best-practices.md for:
- VM ID allocation strategies
- Template management guidelines
- Snapshot strategies and pitfalls
- Storage considerations
- CPU and memory configuration
- Security best practices
- Troubleshooting guides
Common Patterns
Template-Based VM Deployment
python3 scripts/create_template.py 900 --skip-prep
for i in {1..3}; do
qm clone 900 $((100 + i)) --name "web-$i" --full
qm set $((100 + i)) --ipconfig0 ip=192.168.1.$((100 + i))/24,gw=192.168.1.1
qm start $((100 + i))
done
Safe Update Workflow
python3 scripts/snapshot_manager.py create 100 \
--name before-update \
--description "Before system update"
python3 scripts/snapshot_manager.py rollback 100 before-update
python3 scripts/vm_lifecycle.py start 100
python3 scripts/snapshot_manager.py delete 100 before-update
Development Clone Pattern
qm clone 100 200 --name dev-test
qm start 200
qm stop 200
qm destroy 200
Important Considerations
VM IDs
- Valid range: 100-999,999,999
- Must be unique across cluster
- Consider using ID ranges for organization (100-199 for templates, 200-299 for production, etc.)
Snapshots Are Not Backups
- Snapshots live on same storage (single point of failure)
- Have performance overhead
- Not designed for long-term retention
- Use Proxmox Backup Server or vzdump for actual backups
Template Preparation Is Critical
- Always clean machine-specific data before templating
- Remove SSH host keys:
rm /etc/ssh/ssh_host_*
- Clear machine-id:
truncate -s 0 /etc/machine-id
- Install cloud-init and qemu-guest-agent
- Update system before templating
Storage Format Matters
- raw: Best performance, no overhead, fixed size (recommended for production)
- qcow2: Space efficient, snapshot support, slight overhead (good for templates)
CPU Type for Migration
- Use generic CPU types (kvm64) for clusters where migration is needed
- Use host CPU type for best performance on single-host deployments
- Online migration requires matching CPU families
Scripts Directory
vm_lifecycle.py - Safe VM lifecycle operations with validation and state monitoring
clone_vm.py - VM cloning with validation and common options
snapshot_manager.py - Comprehensive snapshot management (create, list, delete, rollback)
create_template.py - Template creation with best-practice guidance
All scripts support --help for detailed usage information.