Home > Proxmox CLI
Slide 1 / 18

Proxmox CLI

Command Line Reference

Virtual Environment Management

Proxmox VE adalah hypervisor berbasis Debian dengan UI web. CLI utama: qm (VM), pct (Container), pvesm (Storage), pvecm (Cluster).

Setup

Authentication

SSH Login ke Node

# SSH ke Proxmox node
ssh root@proxmox-host

# Atau dari luar cluster
ssh [email protected] -p 22

API Token

# Setup API token untuk automation
pveum user token add @pam  --privsep=0
# Output: UUID dan secret
VM Management

List VMs

# Semua VM dan Container
qm list

# Atau pvesh
pvesh get /cluster/resources

Output Example

VMIDStatusNameMemDisk
100runningubuntu-vm2G32G
101stoppedwin104G64G
VM Management

Create VM

qm create 100 \
  --name "ubuntu-vm" \
  --ostype l26 \
  --cores 2 \
  --memory 2048 \
  --net0 virtio,bridge=vmbr0 \
  --disk0 local-lvm:32 \
  --ide2 local:iso/ubuntu-22.04.iso,media=cdrom \
  --boot order=ide2 \
  --onboot 1

OSType Options

VM Management

Start/Stop/Restart

# Start VM
qm start 100

# Stop (graceful)
qm stop 100

# Force stop
qm stop 100 --forceStop

# ACPI shutdown request
qm shutdown 100

# Reboot VM
qm reboot 100

Batch Operation

for vm in 100 101 102; do qm start $vm; done
VM Management

VM Console

# Serial console
qm terminal 100

# SPICE console
qm spice 100

# Attach ke running VM
qm monitor 100

Exit Monitor

quit
Tip: Gunakan Ctrl+] untuk exit dari serial console
VM Management

VM Configuration

# Edit config - resize memory & cores
qm set 100 --memory 4096 --cores 4

# Add network
qm set 100 --net1 virtio,bridge=vmbr1

# Add disk
qm set 100 --disk1 local-lvm:50

# Set boot order
qm set 100 --boot order=scsi0

Cloud-Init

qm set 100 --ciuser admin --cipassword "password" \
  --sshkeys /root/.ssh/authorized_keys
VM Management

Clone & Snapshot

Clone VM

qm clone 100 200 --name "ubuntu-clone" --full

Snapshot

# Create snapshot
qm snapshot 100 "backup-before-update"

# List snapshots
qm listsnapshot 100

# Rollback
qm rollback 100 "backup-before-update"

# Delete snapshot
qm delsnapshot 100 "backup-before-update"
Container

Container Management (pct)

List Containers

pct list

Create Container

pct create 200 local:vztmpl/ubuntu-22.04.tar.gz \
  --rootfs local-lvm:8 \
  --memory 1024 \
  --cores 2 \
  --net0 virtio,bridge=vmbr0 \
  --hostname "my-container" \
  --password "password"
Container

Container Operations

# Start/Stop/Restart
pct start 200
pct stop 200
pct shutdown 200   # Graceful
pct restart 200

# Console
pct console 200   # Attach console
pct enter 200      # Enter container shell

# Config
pct config 200
pct set 200 --memory 2048 --cores 4

# Delete
pct destroy 200 --purge 1
Storage

Storage Management (pvesm)

# List storage
pvesm status
pvesm list local
pvesm list local-lvm

# Add storage
pvesm add dir local --path /var/lib/vz \
  --content iso,vztmpl,backup

# Remove storage
pvesm remove local
Storage

ISO & Templates

# Upload ISO
pvesm upload local iso/ubuntu.iso /path/to/ubuntu.iso

# List ISOs
pvesm list local --content iso

# Download template
pveam update
pveam available --section system
pveam download local ubuntu-22.04-standard_22.04-1_amd64.tar.gz

Resize Disk

pvesm resize 100 scsi0 +10G
Cluster

Cluster Management (pvecm)

# Cluster Status
pvecm status
pvecm nodes
pvecm clusterinfo

# Add node - di node baru
pvecm join 192.168.1.100

# Create cluster - di node utama
pvecm create -clustername "mycluster" -node1 "pve1"

# Remove node
pvecm delnode nodename

# Force quorum (disaster recovery)
pvecm expected 1
Backup

Backup & Restore (vzdump)

Create Backup

# Backup single VM
vzdump 100 --mode suspend --storage local --compress zstd

# Backup all VMs
vzdump --all --mode suspend --storage local

Restore

# Restore VM
vzdump --restore 100 --storage local \
  --filename /var/lib/vz/dump/vzdump-qemu-100-2024_01_01-00_00.tar.zst

# Restore container
vzdump --restore 200 --storage local \
  --filename /var/lib/vz/dump/vzdump-lxc-200-2024_01_01-00_00.tar.gz
Network

Network Configuration

List Network

pvesh get /nodes/pve1/network

Network Interfaces

# Edit /etc/network/interfaces
auto vmbr0
iface vmbr0 inet static
    address 192.168.1.100/24
    gateway 192.168.1.1
    bridge-ports eth0
    bridge-stp off
    bridge-fd 0

VLAN

qm set 100 --net0 virtio,bridge=vmbr0,tag=100
Monitoring

Monitoring & Logs

Resource Usage

# Node stats
pvesh get /nodes/pve1/status

# VM stats
pvesh get /nodes/pve1/qemu/100/status

# Cluster resources
pvesh get /cluster/resources

Logs

# VM logs
qm log 100

# Node syslog
pvesh get /nodes/pve1/syslog --limit 50

# Cluster log
pvesh get /cluster/log --limit 50
Reference

Quick Reference

# Get VMID dari nama
qm list | grep "ubuntu"

# Reset VM
qm reset 100

# Send key to VM
qm sendkey 100 "ret"

# Mount ISO
qm set 100 --ide2 local:iso/ubuntu.iso

# Unmount ISO
qm set 100 --ide2 none

# USB Passthrough
qm set 100 --usb0 host=1-2

# PCI Passthrough
qm set 100 --hostpci0 01:00,pcie=1,x-vga=1
Advanced

One-Liners & Troubleshooting

Useful One-liners

# Start all VMs
for vm in $(qm list | awk 'NR>1 {print $1}'); do 
  qm start $vm; 
done

# List VM IPs
for vm in $(qm list | awk 'NR>1 {print $1}'); do 
  echo "VM $vm:"; 
  qm guest cmd $vm network-get-interfaces | \
    jq -r '.[].ip-addresses[].address' 2>/dev/null
done

Troubleshooting

# Check cluster quorum
pvecm status

# Check corosync
systemctl status corosync

# Check pve-cluster
systemctl status pve-cluster

# Check LVM
pvdisplay; vgdisplay; lvdisplay

Kuis: Proxmox CLI

Apa CLI tool untuk Proxmox?

Command apa untuk list VMs di Proxmox?

Proxmox VE menggunakan teknologi apa?