New Virtual Machine
Create the Machine
VBoxManage createvm --name "${VM_NAME}" --register
#VBoxManage createvm --name "${VM_NAME}" --basefolder "${BASE_DIR}" --register
VBoxManage modifyvm ${VM_UUID} --cpus 4
VBoxManage modifyvm ${VM_UUID} --memory 512
#VBoxManage modifyvm ${VM_UUID} --vram 256
VBoxManage modifyvm ${VM_UUID} --audio none
VBoxManage modifyvm ${VM_UUID} --acpi on
VBoxManage modifyvm ${VM_UUID} --ioapic on
VBoxManage modifyvm ${VM_UUID} --boot1 dvd
VBoxManage modifyvm ${VM_UUID} --nic1 bridged --bridgeadapter1 "${INTERFACE}"
Optional Steps
# for Windows:
VBoxManage modifyvm ${VM_UUID} --nictype1 82540EM
# for EFI boot:
VBoxManage modifyvm ${VM_UUID} --firmware efi64
Create the Storage
read VM_DIR < <( vboxmanage showvminfo ${VM_UUID} --machinereadable | sed -nre '/^CfgFile="/{s!^[^"]+"!!;s!/[^/]+"$!!;p;q 0}' )
VBoxManage createhd --filename "${VM_DIR}/base.vdi" --size "$((8 * 1024))"
VBoxManage storagectl ${VM_UUID} --name "IDE Controller" --add ide
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ${DISK_UUID}
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium emptydrive
Install an OS
DISK_IMG="/ell/software/os/ubuntu/ubuntu-18.04.2-server-amd64.iso"
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "${DISK_IMG}"
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium emptydrive
Start the VM
VBoxManage startvm ${VM_UUID} --type headless
Get Console Access
VBoxManage controlvm ${VM_UUID} vrde on
VBoxManage controlvm ${VM_UUID} vrde off
#VBoxManage controlvm ${VM_UUID} vrdeproperty Client/DisableInput=1
Install Guest Additions
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium additions
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium emptydrive
Power Off / Reset the VM
VBoxManage controlvm ${VM_UUID} acpipowerbutton
VBoxManage controlvm ${VM_UUID} poweroff
VBoxManage controlvm ${VM_UUID} reset
Guest Additions
DISK_IMG=/usr/share/virtualbox/VBoxGuestAdditions.iso
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "${DISK_IMG}"
VBoxManage storageattach ${VM_UUID} --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium emptydrive