Last active
February 7, 2023 17:18
-
-
Save kdssoftware/1cc3dfa09f26e6233fcab81e241f5eeb to your computer and use it in GitHub Desktop.
Auto create machine in vbox using a script.
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 | |
# Starts a new machine with 20GB RAM and 150GB DISK | |
# basepath /mnt/kiko | |
# Download debian.iso | |
if [ ! -f ./debian.iso ]; then | |
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-11.6.0-amd64-netinst.iso -O debian.iso | |
fi | |
sudo mkdir /mnt/kiko/$MACHINENAME | |
#Create VM - This command uses as base folder the current directory: | |
VBoxManage createvm --name $MACHINENAME --ostype "Debian_64" --register --basefolder /mnt/kiko/$MACHINENAME | |
#Set memory and network - In this example: 20Gb RAM and 1 network card behind NAT. | |
VBoxManage modifyvm $MACHINENAME --ioapic on | |
VBoxManage modifyvm $MACHINENAME --memory 20480 --vram 128 | |
VBoxManage modifyvm $MACHINENAME --nic1 nat # or --nic1 bridged --bridgeadapter1 eno1 | |
#Create Disk and connect Debian Iso - One 150Gb SATA HD, and one CDROM (with Debian ISO) drive attached to an IDE Controller. | |
VBoxManage createhd --filename /mnt/kiko/$MACHINENAME/$MACHINENAME.vdi --size 150000 --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 /mnt/kiko/$MACHINENAME/$MACHINENAME.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 - Remote Desktop enabled on port 3391 (useful for administration on an headless environment). | |
VBoxManage modifyvm $MACHINENAME --vrde on | |
VBoxManage modifyvm $MACHINENAME --vrdemulticon on --vrdeport 3395 | |
VBoxManage modifyvm $MACHINENAME --vrdeproperty VNCPassword=$MACHINENAME #vnc password is the same as the machinename | |
#Start the VM | |
VBoxHeadless --startvm $MACHINENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment