diff options
Diffstat (limited to 'test-env/provision-vm.sh')
| -rwxr-xr-x | test-env/provision-vm.sh | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/test-env/provision-vm.sh b/test-env/provision-vm.sh new file mode 100755 index 0000000..97bfb32 --- /dev/null +++ b/test-env/provision-vm.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Default Configuration +VM_NAME="kernel-test-lab" +VCPUS=2 +RAM=4096 +DISK_SIZE=20 +BRIDGE_INT="virbr0" +ISO_DIR="/var/lib/libvirt/images" +ISO_PATH="" + +#OS_VARIANT=$(osinfo-query os | grep -i "$(basename "$ISO_PATH" | cut -d'-' -f1)" | head -n1 | awk '{print $1}') +# more than likely this will be set to none or "" see: https://linux.die.net/man/1/virt-install +OS_VARIANT="" + +usage() { + cat << EOF +┌──────────────────────────────────────────────────────────┐ +│░█░█░█░█░█▄█░░░█▀█░█▀▄░█▀█░█░█░▀█▀░█▀▀░▀█▀░█▀█░█▀█░█▀▀░█▀▄│ +│░█▀▄░▀▄▀░█░█░░░█▀▀░█▀▄░█░█░▀▄▀░░█░░▀▀█░░█░░█░█░█░█░█▀▀░█▀▄│ +│░▀░▀░░▀░░▀░▀░░░▀░░░▀░▀░▀▀▀░░▀░░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀│ +└──────────────────────────────────────────────────────────┘ +*KVM Provisioning Utility for Isolated Kernel and Network Testing. + +Usage: sudo $0 [OPTIONS] + +Options: + -n NAME Name of the Virtual Machine (Default: kernel-test-lab) + -c CPUS Number of vCPUs to allocate (Default: 2) + -m RAM Memory allocation in MB (Default: 4096) + -d DISK Disk size in GB (Default: 20) + -b BRIDGE Host bridge interface (Default: virbr0) + -i ISO Absolute path to ISO (Bypasses interactive selection) + -ov OSVARIANT Optimize the guest configuration for a specific os variant (Bypasses Interactive selection) + -h Display this technical manual + +Example: + sudo ./provision-lab.sh -n kernel-dev-01 -c 4 -m 8192 -d 40 +EOF + exit 0 +} + +if [[ $EUID -ne 0 ]]; then + echo "Error: Execution requires root privileges." >&2 + exit 1 +fi + +while getopts "n:c:m:d:b:i:ov:h" opt; do + case ${opt} in + n) VM_NAME=$OPTARG ;; + c) VCPUS=$OPTARG ;; + m) RAM=$OPTARG ;; + d) DISK_SIZE=$OPTARG ;; + b) BRIDGE_INT=$OPTARG ;; + i) ISO_PATH=$OPTARG ;; + ov) OS_VARIANT=$OPTARG ;; + h) usage ;; + *) usage ;; + esac +done + +if [[ -z "$ISO_PATH" ]]; then + echo "--- KVM Lab Provisioner ---" + echo "Scanning $ISO_DIR for installation media..." + + mapfile -t ISO_LIST < <(ls "$ISO_DIR"/*.iso 2>/dev/null) + + if [ ${#ISO_LIST[@]} -eq 0 ]; then + echo "Error: No ISO files detected in $ISO_DIR" >&2 + exit 1 + fi + + select opt in "${ISO_LIST[@]}" "Cancel"; do + if [[ "$opt" == "Cancel" ]]; then exit 0; fi + if [[ -f "$opt" ]]; then + ISO_PATH="$opt" + break + else + echo "Invalid selection." + fi + done +fi + +if [[ -z "$OS_VARIANT" ]]; then + echo "Need a OS Variant..." + read OS_VARIANT +fi + +echo "Provisioning Details:" +echo " Name: $VM_NAME" +echo " vCPUs: $VCPUS" +echo " RAM: $RAM MB" +echo " Storage: $DISK_SIZE GB" +echo " Bridge: $BRIDGE_INT" +echo " ISO: $ISO_PATH" +echo " Profile: $OS_VARIANT" + +# error was: ERROR Kernel arguments are only supported with location or kernel installs +# changed from location to cdrom; can't pass kernel args unless you use --location +# --extra-args "console=ttyS0,115200n8 serial" \ +virt-install \ + --name "$VM_NAME" \ + --vcpus "$VCPUS" \ + --memory "$RAM" \ + --disk "size=$DISK_SIZE,format=qcow2" \ + --os-variant "$OS_VARIANT" \ + --location "$ISO_PATH" \ + --extra-args "console=ttyS0,115200n8 serial" \ + --network "bridge=$BRIDGE_INT" \ + --graphics none \ + --console pty,target_type=serial \ + --check all=off \ + --hvm \ + --virt-type kvm \ + --noreboot + +echo "--- Provisioning Sequence Complete ---" +echo "To begin testing: virsh start $VM_NAME --console" |
