Skip to content

VM/CT Management

Procedures for creating, managing, and migrating VMs and containers.

Creating New VMs/Containers

1. Get Next VMID

# Get next available VMID for px1 production
infra next-vmid px1 prod

# Get next available VMID for px5 dev
infra next-vmid px5 dev

2. Get Next IP Address

# Get next available IP for UK site
infra next-ip uk

# Get next available IP for France site
infra next-ip france

3. Create Container (LXC)

# Create from template
pct create <vmid> local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst \
  --hostname <name> \
  --storage ceph-pool \
  --rootfs ceph-pool:8 \
  --memory 2048 \
  --cores 2 \
  --net0 name=eth0,bridge=vmbr0,tag=10,ip=<ip>/24,gw=REDACTED_IP \
  --unprivileged 1

# Start container
pct start <vmid>

4. Create VM (QEMU)

# Create VM
qm create <vmid> \
  --name <name> \
  --memory 4096 \
  --cores 2 \
  --net0 virtio,bridge=vmbr0,tag=10 \
  --scsihw virtio-scsi-pci \
  --scsi0 ceph-pool:32

# Attach ISO and boot
qm set <vmid> --ide2 local:iso/debian-12.iso,media=cdrom
qm set <vmid> --boot order=ide2
qm start <vmid>

5. Configure SSH Access

# Set up bi-directional SSH access
setup-vm-ssh <vmid>

Managing VMs/Containers

Start/Stop Operations

# Container operations
pct start <vmid>
pct shutdown <vmid>    # Graceful shutdown
pct stop <vmid>        # Force stop
pct reboot <vmid>

# VM operations
qm start <vmid>
qm shutdown <vmid>     # Graceful shutdown
qm stop <vmid>         # Force stop
qm reboot <vmid>

Execute Commands

# Container - direct execution
pct exec <vmid> -- <command>
pct exec 1112 -- systemctl status postgresql

# VM - via QEMU guest agent
qm guest exec <vmid> -- <command>

Console Access

# Container console
pct enter <vmid>

# VM console (via VNC)
# Use Proxmox web UI or:
qm terminal <vmid>

Resize Disk

# Container
pct resize <vmid> rootfs +10G

# VM
qm resize <vmid> scsi0 +10G

Modify Resources

# Container - update memory and CPU
pct set <vmid> --memory 4096 --cores 4

# VM - update memory and CPU
qm set <vmid> --memory 4096 --cores 4

Migration

Live Migration (Same Cluster)

# Migrate container to another node
pct migrate <vmid> <target-node>

# Migrate VM to another node
qm migrate <vmid> <target-node>

# Online migration (VM must have shared storage)
qm migrate <vmid> <target-node> --online

Cross-Site Migration (UK ↔ France)

For cross-site migration (px1/px2/px3 ↔ px5):

  1. Create vzdump backup:

    vzdump <vmid> --storage local --compress zstd
    

  2. Copy to target node:

    scp /var/lib/vz/dump/vzdump-*-<vmid>-*.tar.zst root@<target-node>:/var/lib/vz/dump/
    

  3. Restore on target:

    # Container
    pct restore <new-vmid> /var/lib/vz/dump/vzdump-lxc-<vmid>-*.tar.zst
    
    # VM
    qmrestore /var/lib/vz/dump/vzdump-qemu-<vmid>-*.vma.zst <new-vmid>
    

Cloning

Clone Container

# Full clone
pct clone <source-vmid> <new-vmid> --full --storage ceph-pool

# Linked clone (uses less space)
pct clone <source-vmid> <new-vmid>

Clone VM

# Full clone
qm clone <source-vmid> <new-vmid> --full --storage ceph-pool

# Change name after clone
qm set <new-vmid> --name <new-name>

Deletion

# Stop first
pct stop <vmid>  # or qm stop <vmid>

# Destroy container
pct destroy <vmid>

# Destroy VM
qm destroy <vmid>

# Force destroy (including disks)
qm destroy <vmid> --purge

Templates

Create Template from Container

pct template <vmid>

Create Template from VM

qm template <vmid>

Templates can then be cloned for new instances.

Best Practices

  1. Always use the VMID convention: [N][P][SS] format
  2. Run setup-vm-ssh after creating new VMs/CTs
  3. Document the purpose in the VM/CT notes field
  4. Add to infra database via Domain Manager API for tracking
  5. Configure backups for production workloads