Created
July 14, 2025 06:41
-
-
Save eranco74/1cdd593f07ec95ff66070da853b6e44c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if VM name and ISO source are provided | |
if [ -z "$1" ] || [ -z "$2" ]; then | |
echo "Usage: $0 <vm_name> <iso_path_or_url>" | |
exit 1 | |
fi | |
VM_NAME="$1" | |
ISO_SOURCE="$2" | |
ISO_PATH="" | |
# Determine if the ISO source is a URL or a local path | |
if [[ "$ISO_SOURCE" =~ ^(http|https|ftp):// ]]; then | |
echo "ISO source is a URL. Attempting to download..." | |
# Create a temporary directory for the downloaded ISO | |
DOWNLOAD_DIR="/tmp/iso_downloads" | |
mkdir -p "$DOWNLOAD_DIR" | |
ISO_FILENAME=$(basename "$ISO_SOURCE") | |
ISO_PATH="$DOWNLOAD_DIR/$ISO_FILENAME" | |
# Download the ISO | |
if ! wget -O "$ISO_PATH" "$ISO_SOURCE"; then | |
echo "Error: Failed to download ISO from $ISO_SOURCE" | |
exit 1 | |
fi | |
echo "ISO downloaded to: $ISO_PATH" | |
elif [ -f "$ISO_SOURCE" ]; then | |
echo "ISO source is a local path." | |
ISO_PATH="$ISO_SOURCE" | |
else | |
echo "Error: Invalid ISO source. Must be a valid local path or a URL." | |
exit 1 | |
fi | |
echo "Starting virt-install for VM: $VM_NAME" | |
echo "Using ISO: $ISO_PATH" | |
virt-install \ | |
--name "$VM_NAME" \ | |
--memory 16384 \ | |
--vcpus 8 \ | |
--disk path=/root/dell/disks/dev-scripts/pool/"$VM_NAME".qcow2,size=200,format=qcow2 \ | |
--cdrom "$ISO_PATH" \ | |
--network network=default \ | |
--os-type linux \ | |
--os-variant rhel9-unknown \ | |
--graphics vnc,listen=0.0.0.0 \ | |
--noautoconsole | |
echo "virt-install process completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment