#!/bin/bash # Proxmox Production VM Creator - Optimized for DevMatrix # Run this on the Proxmox host as root # Source: https://git.lemonlink.eu/devmatrix/devmatrix-scripts set -e # Configuration - EDIT THESE FOR YOUR ENVIRONMENT VM_ID=202 # DevMatrix Production VM VM_NAME="DevMatrix-Prod" VM_IP="192.168.5.211/24" VM_GW="192.168.5.1" VM_CPU=6 # 6 cores (plenty for production) VM_RAM=16384 # 16GB RAM (you have 94GB available) VM_DISK=150 # 150GB on NVMe (pve-main) STORAGE="pve-main" # Your NVMe storage BRIDGE="vmbr1" # Your network bridge # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log() { echo -e "${BLUE}[PROXMOX]${NC} $1"; } success() { echo -e "${GREEN}[✓]${NC} $1"; } warning() { echo -e "${YELLOW}[!]${NC} $1"; } error() { echo -e "${RED}[✗]${NC} $1"; exit 1; } # Check if running on Proxmox if [ ! -f "/etc/pve/priv/authkey.pub" ]; then error "This script must be run on the Proxmox host" fi # Check if VM already exists if qm status $VM_ID > /dev/null 2>&1; then error "VM $VM_ID already exists!" fi # Check if storage exists if ! pvesm status | grep -q "$STORAGE"; then error "Storage '$STORAGE' not found! Available storages:" pvesm status exit 1 fi # Check if bridge exists if ! ip link show "$BRIDGE" > /dev/null 2>&1; then error "Bridge '$BRIDGE' not found! Available bridges:" ip link show | grep "vmbr" exit 1 fi log "🚀 Creating DevMatrix Production VM" log "====================================" log "" log "Configuration:" log " VM ID: $VM_ID" log " Name: $VM_NAME" log " CPU: $VM_CPU cores (Intel Xeon E5645)" log " RAM: $((VM_RAM / 1024))GB" log " Disk: ${VM_DISK}GB ($STORAGE NVMe)" log " Network: $BRIDGE" log " IP: $VM_IP" log "" read -p "Continue? (y/N): " confirm if [[ $confirm != [yY] ]]; then error "Aborted" fi # Download Ubuntu cloud image if not exists CLOUD_IMAGE="/var/lib/vz/template/iso/jammy-server-cloudimg-amd64.img" if [ ! -f "$CLOUD_IMAGE" ]; then log "Downloading Ubuntu 22.04 cloud image..." mkdir -p /var/lib/vz/template/iso wget -q --show-progress \ https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img \ -O "$CLOUD_IMAGE" success "Downloaded Ubuntu cloud image" fi # Create VM with optimized settings log "Creating VM with optimized settings..." qm create $VM_ID \ --name "$VM_NAME" \ --memory $VM_RAM \ --balloon 0 \ --cores $VM_CPU \ --cpu cputype=host \ --sockets 2 \ --numa 1 \ --net0 virtio,bridge=$BRIDGE,firewall=1 \ --scsihw virtio-scsi-single \ --ostype l26 \ --agent enabled=1,fstrim_cloned_disks=1 \ --cpuunits 2048 \ --onboot 1 # Import disk to NVMe storage log "Importing disk to $STORAGE..." qm importdisk $VM_ID "$CLOUD_IMAGE" $STORAGE --format qcow2 # Attach disk with discard for TRIM support qm set $VM_ID --scsi0 ${STORAGE}:vm-${VM_ID}-disk-0,discard=on,iothread=1 # Resize disk log "Resizing disk to ${VM_DISK}GB..." qm disk resize $VM_ID scsi0 ${VM_DISK}G # Create CloudInit drive on same storage log "Configuring CloudInit..." qm set $VM_ID --ide2 ${STORAGE}:cloudinit # Set boot order qm set $VM_ID --boot order=scsi0 # Configure serial for console qm set $VM_ID --serial0 socket --vga serial0 # Set IP configuration qm set $VM_ID --ipconfig0 ip=$VM_IP,gw=$VM_GW # Set user/password qm set $VM_ID --ciuser devmatrix qm set $VM_ID --cipassword $(openssl rand -base64 24) # Configure SSH keys if available if [ -f "/root/.ssh/authorized_keys" ]; then log "Adding SSH keys from host..." qm set $VM_ID --sshkeys < /root/.ssh/authorized_keys fi # Enable QEMU agent with full features qm set $VM_ID --agent enabled=1,fstrim_cloned_disks=1,type=virtio # Add tags for organization qm set $VM_ID --tags production,mission-control,devmatrix # Set start at boot qm set $VM_ID --onboot 1 # Configure backups (will use Proxmox backup settings) log "Configuring backup options..." # Start VM log "Starting VM..." qm start $VM_ID # Wait for VM to boot log "Waiting for VM to boot (30s)..." sleep 30 success "✅ Production VM created and started!" log "" log "VM Details:" log " ID: $VM_ID" log " Name: $VM_NAME" log " IP: $VM_IP" log " Console: https://$(hostname -I | awk '{print $1}'):8006/#v1:0:=$VM_ID" log " Storage: $STORAGE (NVMe)" log " Network: $BRIDGE" log "" log "Next steps:" log "1. Open console: qm console $VM_ID" log "2. SSH into VM: ssh devmatrix@192.168.5.211" log "3. Run setup script" log "" log "To view VM status:" log " qm status $VM_ID" log " qm list" log "" log "Optimization notes:" log " ✓ 6 CPU cores (NUMA optimized)" log " ✓ 16GB RAM (dedicated, no ballooning)" log " ✓ 150GB NVMe storage (TRIM enabled)" log " ✓ 2 sockets for better NUMA performance" log " ✓ High CPU priority (2048)" log " ✓ Auto-start on boot" log " ✓ QEMU guest agent enabled" log ""