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