VirtualBox – Creating & controlling virtual machines in headless mode

virtual_box_logo_smallCreate…

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

Control…

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

Destroy…

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!

About Author

Related Posts

php8 gd

PHP8 gd Activate after installation

PHP8 GD activate after installation. GD doesn’t get activated by default. Not even a reboot after installation will activate it. So how do we do it? In…

Debian 12: linux-image-6.1.0-10amd64

Troubleshooting dependency issues in Debian 12: Resolving linux-image-6.1.0-10amd64 package dependency problems. If you installed the Debian 12 from the live image the issue is the raspi-firmware. Even…

4 Best Free Nas Software That Is Open Source

Free NAS software or operating systems that are free to use and will turn a computer into a NAS more advanced than the dedicated boxes sold. What…

Raspbian default password

Raspbian default password

Looking for the Raspbian default password? It is the most essential username and password that you will need for your raspberry. At least if you are running…

OpenMediaVault default password

OpenMediaVault default password

OpenMediaVault default password is printed in the documentation. I did not see it the first time I installed it either. So I had to do some detective…

Debian change dns

Debian change DNS settings to a new DNS

Debian change DNS settings for speed improvement or privacy. It is really easy to do. So let us see how it’s done and get to it. The…

Leave a Reply