11#! /bin/bash
2- MACHINENAME=" socios_vm_test"
3- # Disk_location="/tmp/socios/$Server_name.vdi"
4- # Image_file="/tmp/socios/ubuntu.iso"
2+ if [ -d socios ]; then
3+ rm -rf socios
4+ fi
5+ mkdir -p socios
6+ chmod -R 755 socios
7+
8+ echo " Copying the ISO Image to Root Path"
9+
10+ cp /tmp/socios/ubuntu.iso socios
11+
12+ # Destination to save the VDI File
13+ DESTINATION=socios/VirtualBoxVMs
14+ ISO=socios
15+
16+ # List available Guest OS on MAC Machine
17+ echo " Available Guest OS on MAC Machine "
18+ VBoxManage list ostypes | grep -i ubuntu
19+
20+ echo " Enter the VM name: "
21+ read MACHINENAME
522
623# Creating virtual machine
724echo " Creating a $MACHINENAME virtual machine"
8- vboxmanage createvm --name $MACHINENAME --ostype " Ubuntu_64" --register --basefolder ` pwd `
25+ vboxmanage createvm --name $MACHINENAME --ostype " Ubuntu_64" --register --basefolder $DESTINATION
926
1027# Set memory and network
1128echo " Setting up the memory and network for created $MACHINENAME virtual machine"
1229VBoxManage modifyvm $MACHINENAME --ioapic on
1330VBoxManage modifyvm $MACHINENAME --memory 4096
14- vboxmanage modifyvm $MACHINENAME --vram 128
31+ vboxmanage modifyvm $MACHINENAME --vram 256
1532VBoxManage modifyvm $MACHINENAME --nic1 nat
1633vboxmanage modifyvm $MACHINENAME --cpus 4
1734vboxmanage modifyvm $MACHINENAME --graphicscontroller VMSVGA
1835
1936diskutil list
20- echo " Select the partition disk to install the OS"
21-
22- read -p " Provide the disk space want to use for Linux OS: " disk_input
23-
24- disk=$( /dev/" $disk_input " )
37+ echo " Enter the storage size"
38+ read -p " Enter the storage size in GB in numerals:" gb
39+ size=` expr $gb \* 1024`
2540
2641# Create Disk and connect Debian Iso
27- # VBoxManage createhd --filename `pwd`/$MACHINENAME/$MACHINENAME.vdi --size 40000 --format VDI
28- VBoxManage internalcommands createrawvmdk -filename ` pwd` /" $MACHINENAME " /$MACHINENAME .vmdk -rawdisk disk
29- VBoxManage modifyvm " $MACHINENAME " --boot1 dvd --boot2 disk --boot3 none
42+ echo " Creating Virtual Hard Disk"
43+ VBoxManage createhd --filename $DESTINATION /$MACHINENAME /$MACHINENAME .vdi --size $size --format VDI --variant Standard
44+
45+ # Add Storage Controller to Virtual Machine
46+ VBoxManage storagectl $MACHINENAME --name " SATA Controller" --add sata --bootable on
3047
31- # Configuration of virtual hard_disk
32- VBoxManage storagectl " $MACHINENAME " --name " SATA Controller" --add sata --controller IntelAhci
33- VBoxManage storageattach $MACHINENAME --storagectl " SATA Controller" --port 0 --device 0 --type hdd --medium ` pwd` /$MACHINENAME /$MACHINENAME_DISK .vdi
48+ # Attach Virtual Hard Disk to Virtual Storage Controller
49+ VBoxManage storageattach $MACHINENAME --storagectl " SATA Controller" --port 0 --device 0 --type hdd --medium $DESTINATION /$MACHINENAME /$MACHINENAME .vdi
3450
35- # Configuration of ISO_image
51+ # Add IDE Controller to Virtual Machine (To Later Connect ISO/CD/DVD)
3652VBoxManage storagectl $MACHINENAME --name " IDE Controller" --add ide --controller PIIX4
37- VBoxManage storageattach $MACHINENAME --storagectl " IDE Controller" --port 1 --device 0 --type dvddrive --medium ` pwd` /ubuntu.iso
3853
39- # Enable RDP
40- VBoxManage modifyvm $MACHINENAME --vrde on
41- VBoxManage modifyvm $MACHINENAME --vrdemulticon on --vrdeport 10001
54+ # Resize virtual machine (VDI and VHD)
55+ # VBoxManage modifyhd "$DESTINATION/$MACHINENAME/$MACHINENAME.vdi" −−resize 40000
56+ # This changes the size of the virtual hard drive to 40000 MB
57+
58+ # Attach ISO_image
59+ VBoxManage storageattach $MACHINENAME --storagectl " IDE Controller" --port 1 --device 0 --type dvddrive --medium $ISO /ubuntu.iso
60+
61+ # Start the Virtual Machine in Headless Mode
62+ VBoxManage startvm $MACHINENAME
63+
64+ # Resize the Virtualbox in VM
65+ VBoxManage setextradata " $MACHINENAME " GUI/ScaleFactor 2.5
4266
43- # Start the VM
44- VBoxHeadless --startvm $MACHINENAME
67+ echo " ISO image booted in Virtualbox.... Start setup process"
0 commit comments