Running a Virtual box VM in headless mode

I cannot believe I haven't tried this before. Virtualbox VMs can run in a headless mode. This is perfect for running a linux server VM without having to turn on the VirtualBox UI.

So I have been trying to build the NodeMCU custom firmware and it is just easier to do on a linux VM. So I went ahead and installed Ubuntu 16.04 LTS in a virtual machine and built the toolchain and then the sdk. I was just annoyed with the default command line and not to mention I would have to share directories from host to vm.

Before you do that, you might want to setup ssh on the vm so that you can ssh from your host. The best way to do it, is to setup port forwarding.

I forwarded 3022 to 22 on the vm. So add the rule under advanced settings > port forwarding while attached to: NAT

Verify the rule via command line (shut down the VM from the UI)

VBoxManage showvminfo NodeMCU | grep 'Rule' which results in

NIC 1 Rule(0):   name = ssh, protocol = tcp, host ip = , host port = 3022, guest ip = , guest port = 22  

If you don't see the rule, you can manually add it via the command line

VBoxManage modifyvm NodeMCU --natpf1 "ssh,tcp,,3022,,22"

Once you're done with that, enable the Virtual Remote Desktop Extension (VRDE).

VBoxManage modifyvm NodeMCU --vrde on

and then finally turn it on

VboxHeadless -s NodeMCU and it should show up with what port it's running on.

And now to ssh into the machine

ssh -p 3022 [email protected]

And boom! No more clunky UI.