-
-
Save andreafortuna/9c7e342dbff00edefbaebcbfd034193f to your computer and use it in GitHub Desktop.
Automatically create and start a Debian VM on VirtualBOX
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 | |
MACHINENAME=$1 | |
# Download debian.iso | |
if [ ! -f ./debian.iso ]; then | |
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.9.0-amd64-netinst.iso -O debian.iso | |
fi | |
#Create VM | |
VBoxManage createvm --name $MACHINENAME --ostype "Debian_64" --register --basefolder `pwd` | |
#Set memory and network | |
VBoxManage modifyvm $MACHINENAME --ioapic on | |
VBoxManage modifyvm $MACHINENAME --memory 1024 --vram 128 | |
VBoxManage modifyvm $MACHINENAME --nic1 nat | |
#Create Disk and connect Debian Iso | |
VBoxManage createhd --filename `pwd`/$MACHINENAME/$MACHINENAME_DISK.vdi --size 80000 --format VDI | |
VBoxManage storagectl $MACHINENAME --name "SATA Controller" --add sata --controller IntelAhci | |
VBoxManage storageattach $MACHINENAME --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium `pwd`/$MACHINENAME/$MACHINENAME_DISK.vdi | |
VBoxManage storagectl $MACHINENAME --name "IDE Controller" --add ide --controller PIIX4 | |
VBoxManage storageattach $MACHINENAME --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium `pwd`/debian.iso | |
VBoxManage modifyvm $MACHINENAME --boot1 dvd --boot2 disk --boot3 none --boot4 none | |
#Enable RDP | |
VBoxManage modifyvm $MACHINENAME --vrde on | |
VBoxManage modifyvm $MACHINENAME --vrdemulticon on --vrdeport 10001 | |
#Start the VM | |
VBoxHeadless --startvm $MACHINENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a very handy script, thank you!
I had an issue with line 16... I think my shell (Focal Fossa bash) interpreted
$MACHINENAME_DISK
as a different, undefined bash var from$MACHINENAME
. The resulting file created byvboxmanage
was.vdi
! This might have worked, as it was consistent with the rest of the script, but I'm unsure. I changed line 16 to:And subsequent references to the disk file to be consistent.
Cheers!
~~LT