File size: 1,700 Bytes
ebe38d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#!/bin/bash
# Variables
VM_NAME="UbuntuVM"
UBUNTU_VERSION="20.04.3"
ISO_FILENAME="ubuntu-$UBUNTU_VERSION-server-amd64.iso"
ISO_URL="http://cdimage.ubuntu.com/releases/$UBUNTU_VERSION/release/$ISO_FILENAME"
VM_DIR="$HOME/VirtualBox VMs/$VM_NAME"
HDD_PATH="$VM_DIR/$VM_NAME.vdi"
RAM_SIZE="2048" # Size in MB
VRAM_SIZE="1028" # Size in MB
HDD_SIZE="20000" # Size in MB
# Download Ubuntu ISO
echo "Downloading Ubuntu $UBUNTU_VERSION Server ISO..."
curl -o "$ISO_FILENAME" "$ISO_URL"
# Create VM
VBoxManage createvm --name "$VM_NAME" --ostype "Ubuntu_64" --register
# Modify VM settings
VBoxManage modifyvm "$VM_NAME" --ioapic on
VBoxManage modifyvm "$VM_NAME" --memory "$RAM_SIZE" --vram "$VRAM_SIZE"
VBoxManage modifyvm "$VM_NAME" --nic1 nat
VBoxManage modifyvm "$VM_NAME" --boot1 dvd --boot2 disk --boot3 none --boot4 none
VBoxManage modifyvm "$VM_NAME" --graphicscontroller vboxvga
VBoxManage modifyvm "$VM_NAME" --audio none
# Create a virtual hard disk
VBoxManage createmedium disk --filename "$HDD_PATH" --size "$HDD_SIZE" --format VDI
# Attach the virtual hard disk
VBoxManage storagectl "$VM_NAME" --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach "$VM_NAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$HDD_PATH"
# Attach the downloaded Ubuntu ISO
VBoxManage storagectl "$VM_NAME" --name "IDE Controller" --add ide
VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$ISO_FILENAME"
# Set up NAT Network with port forwarding
# Start the VM
VBoxManage startvm "$VM_NAME" --type headless
echo "VM $VM_NAME created and started. You can SSH into it using port 2222."
|