April 21, 2021



VirtualBox – Creating & controlling virtual machines in headless mode


Create the virtual machine, named MySQL in this example:
VBoxManage createvm –name “MySQL” –register

We give it 512MB ram, enable acpi, boot on dvd and a bridged network card:
VBoxManage modifyvm “MySQL” –memory 512 –acpi on –boot1 dvd –nic1 bridged –bridgeadapter1 eth0

Create the virtual hard drive (Size in MB):
VBoxManage createhd –filename MySQL.vdi –size 10000

Set up the IDE controllers for the DVD player and the hard drive. We also mount an Debian 7 iso image into the dvd player:
VBoxManage storagectl “MySQL” –name “IDE Controller” –add ide

VBoxManage storageattach “MySQL” –storagectl “IDE Controller” –port 0 –device 0 –type hdd –medium MySQL.vdi

VBoxManage storageattach “MySQL” –storagectl “IDE Controller” –port 1 –device 0 –type dvddrive –medium /home/debian-7.1.0-i386-netinst.iso

The virtual machine should now be ready to run.
If you haven’t allready, installing screen would be handy. So you can free up your console if you like. apt-get install screen


To run the virtual machine from our example.
screen vboxheadless –startvm “MySQL”
You can now press ctrl+a and then ctrl+d to deattach from the process and have access to console again.

To stop the virtual machine you can do this.
vboxmanage controlvm “MySQL” poweroff

To unmount the installation iso, you can do that like this.
VBoxManage storageattach “MySQL” –storagectl “IDE Controller” –port 1 –device 0 –type dvddrive –medium none

To have your virtual machine to start up automaticly on boot. Add this to your boot script: vboxmanage startvm “MySQL” –type headless


If you need for some reasons to remove your virtual machine. You need to start with unregistering the hard drive, and then delete it. Then you can unregister the virtual machine and remove it. Here is how.
To list the hard drives: vboxmanage list hdds
Remove the hard drive: vboxmanage modifyvm “MySQL” –hda none
Find the UUID for the hard drive: vboxmanage showvminfo “MySQL” | grep vdi*
Unregister the hard drive: vboxmanage unregisterimage disk f3620364-399d-413b-b08e-d8b2f13392f0
Delete the hard drive file (of course use your own location): rm -rf /home/MySQL.vdi
Unregister the virtual machine: vboxmanage unregister vm MySQL

Your virtual machine and virtual hard drive is now gone.

Happy imagining!