Files
ROMFASTSQL/proxmox/lxc108-oracle/roa-windows-setup/test/clone-vm300.sh
Marius 318de18e15 docs(vm303): full clone, template 300 sters, handoff inchis
VM 303 rula ca linked clone din VM 300, deci template-ul contaminat nu putea
fi sters. Transformat in full clone si VM 300 eliminat din infrastructura.

Metoda: zfs send/recv local + swap de volid in config. `qm move-disk` nu era
o optiune — PVE respinge mutarea pe acelasi storage, iar pentru zvol-uri
conditia din Qemu.pm:4688 e mereu adevarata (numele n-are sufix de format).

- inventarele nu mai listeaza VM 300; VM 310 ramane singurul template
- clone-vm300.sh: comentariul spune de ce sursa e 310 (numele e istoric)
- handoff-ul sters la cererea utilizatorului; faptele care mai conteaza sunt
  mutate inline in README-uri, ca sa nu ramana referinte moarte

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MoFGxftQw92PX4Sdkn94pv
2026-08-11 00:55:41 +03:00

220 lines
6.1 KiB
Bash

#!/bin/bash
# =============================================================================
# Clone Windows 11 Template (VM 310) for Oracle Testing
# =============================================================================
#
# Purpose: Create a test VM for Oracle installation testing
#
# Usage:
# ./clone-vm300.sh [TARGET_VMID] [TARGET_NAME]
#
# Examples:
# ./clone-vm300.sh # Creates VM 301 named oracle-test-301
# ./clone-vm300.sh 305 # Creates VM 305 named oracle-test-305
# ./clone-vm300.sh 320 roa-prod # Creates VM 320 named roa-prod
#
# IMPORTANT — sursa e VM 310 (numele scriptului e istoric):
# VM 300 `Win11-Template` a fost STERS 2026-08-11. NU era sysprep-uit: purta numele
# (ROACENTRAL) si SID-ul de masina al VM 201, iar clonele din el nu se puteau
# autentifica prin SMB/NTLM nici cu VM 201, nici intre ele.
# VM 310 `Win11-Template-Sysprep` e varianta generalizata; fiecare clona primeste
# SID si nume proprii la prima pornire (trece prin OOBE).
#
# Prerequisites:
# - Run on Proxmox host (pvemini, pve1, or pveelite)
# - VM 310 exists as sysprepped Windows 11 template
# - Sufficient storage space (~50GB per clone)
#
# =============================================================================
set -e
# -----------------------------------------------------------------------------
# Configuration
# -----------------------------------------------------------------------------
SOURCE_VMID=310
TARGET_VMID=${1:-301}
TARGET_NAME=${2:-"oracle-test-${TARGET_VMID}"}
# Storage for new VM (change if needed)
TARGET_STORAGE="local-zfs"
# Node where to create the VM (empty = same as source)
TARGET_NODE=""
# Full clone (true) or linked clone (false)
FULL_CLONE=true
# Start VM after creation
AUTO_START=true
# Description for the new VM
DESCRIPTION="Oracle 21c Test VM - Created $(date '+%Y-%m-%d %H:%M')"
# -----------------------------------------------------------------------------
# Validation
# -----------------------------------------------------------------------------
echo "=============================================="
echo "Proxmox VM Clone Script"
echo "=============================================="
echo ""
echo "Source VM: $SOURCE_VMID"
echo "Target VM: $TARGET_VMID"
echo "Target Name: $TARGET_NAME"
echo "Full Clone: $FULL_CLONE"
echo "Auto Start: $AUTO_START"
echo ""
# Check if running on Proxmox
if ! command -v qm &> /dev/null; then
echo "ERROR: This script must be run on a Proxmox host"
echo " (qm command not found)"
exit 1
fi
# Check if source VM exists
if ! qm status $SOURCE_VMID &> /dev/null; then
echo "ERROR: Source VM $SOURCE_VMID does not exist"
exit 1
fi
# Check if target VMID is already in use
if qm status $TARGET_VMID &> /dev/null 2>&1; then
echo "ERROR: Target VMID $TARGET_VMID already exists"
echo " Choose a different VMID or remove existing VM:"
echo " qm destroy $TARGET_VMID"
exit 1
fi
# Confirm before proceeding
read -p "Proceed with cloning? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
# -----------------------------------------------------------------------------
# Clone VM
# -----------------------------------------------------------------------------
echo ""
echo "Creating clone..."
CLONE_CMD="qm clone $SOURCE_VMID $TARGET_VMID --name $TARGET_NAME"
if [ "$FULL_CLONE" = true ]; then
CLONE_CMD="$CLONE_CMD --full"
fi
if [ -n "$TARGET_STORAGE" ]; then
CLONE_CMD="$CLONE_CMD --storage $TARGET_STORAGE"
fi
if [ -n "$TARGET_NODE" ]; then
CLONE_CMD="$CLONE_CMD --target $TARGET_NODE"
fi
echo "Running: $CLONE_CMD"
eval $CLONE_CMD
echo "Clone created successfully"
# -----------------------------------------------------------------------------
# Configure VM
# -----------------------------------------------------------------------------
echo ""
echo "Configuring VM..."
# Set description
qm set $TARGET_VMID --description "$DESCRIPTION"
# Optionally increase resources for Oracle
# qm set $TARGET_VMID --memory 8192 --cores 4
echo "VM configured"
# -----------------------------------------------------------------------------
# Start VM
# -----------------------------------------------------------------------------
if [ "$AUTO_START" = true ]; then
echo ""
echo "Starting VM..."
qm start $TARGET_VMID
# Wait for VM to start
sleep 5
# Check status
STATUS=$(qm status $TARGET_VMID | awk '{print $2}')
echo "VM Status: $STATUS"
fi
# -----------------------------------------------------------------------------
# Output Summary
# -----------------------------------------------------------------------------
echo ""
echo "=============================================="
echo "VM Clone Complete"
echo "=============================================="
echo ""
echo "VMID: $TARGET_VMID"
echo "Name: $TARGET_NAME"
echo "Status: $(qm status $TARGET_VMID | awk '{print $2}')"
echo ""
echo "Console URL: https://$(hostname -I | awk '{print $1}'):8006/#v1:0:=qemu%2F${TARGET_VMID}:4::::::"
echo ""
echo "Next steps:"
echo " 1. Connect to VM console"
echo " 2. Complete Windows OOBE if needed"
echo " 3. Install Oracle 21c XE or SE"
echo " 4. Run ROA setup scripts"
echo ""
echo "To delete this VM when done:"
echo " qm stop $TARGET_VMID"
echo " qm destroy $TARGET_VMID"
echo ""
# -----------------------------------------------------------------------------
# Helper Commands
# -----------------------------------------------------------------------------
# Print helpful commands
cat << 'COMMANDS'
# Useful Proxmox commands:
# List all VMs
qm list
# VM status
qm status TARGET_VMID
# Start/Stop/Restart VM
qm start TARGET_VMID
qm stop TARGET_VMID
qm restart TARGET_VMID
# Access VM console
qm terminal TARGET_VMID
# Clone with different storage
qm clone 300 TARGET_VMID --name NAME --full --storage local-lvm
# Snapshot before testing
qm snapshot TARGET_VMID snap-before-oracle --description "Before Oracle install"
# Rollback to snapshot
qm rollback TARGET_VMID snap-before-oracle
# Delete VM
qm stop TARGET_VMID && qm destroy TARGET_VMID
COMMANDS
exit 0