VirtualBox Command Line Basics

Most people know VirtualBox (their website, my blog entries) as a way to run another operating system desktop on top of your current OS. You can run a Linux desktop on Windows, or you can run a Windows desktop on Linux or Mac. In fact, you can run almost anything on anything. But VirtualBox has an incredibly powerful command line hiding behind their pretty GUI. And I'm finding it reasonably easy to use. This write-up will only scratch the surface: maybe I'll get into more at a later date.

I think it's worth mentioning (particularly for Linux users) that you should do all this as the user who owns the virtual machine(s): there's no need to be root/Administrator, in fact it's probably a bad idea. This article will mention actions that sound administrative in nature (like using a secondary IP on the machine), but when VirtualBox was installed and the user was granted permission to use it, all those rights come along with the access.

The simplest action we can do is to see what machines are available:

$ vboxmanage list vms
"WinXP" {e001ce0e-9e4c-4302-b493-25a5857d29a3}
"Main OpenWRT CC x86 Router" {8e13bca6-d3ed-4d42-a8e4-b723dc1a238b}
"OpenWrt 18.06.0 x86-64" {c3069795-e3af-47f0-a369-c1c3ad97c8a9}
"Volumio2018-12" {adb2028a-af0d-4fa4-a03b-7db1e5be1c59}
"DebStretchStable" {f09fe8fa-90b8-401f-a723-d011d81e93f3}
"Deb10stable64-201912" {d19e3598-9e5e-45ab-ab23-7699709a467d}
"Deb10stable64-201912 Clone" {c03312fb-75a9-40e4-bc36-dd3e688e7213}
"Deb10stable64GUI-202004" {131ddd81-4436-4736-a87d-7201af5e5a19}
"Deb10Dummy" {ddaf79c3-5a35-4704-bf60-3f87f723dbb0}

If you prefer your commands fancy-looking, the base command is also available as VBoxManage - but to me that's just too much trouble to type. To find out which VMs are running:

$ vboxmanage list runningvms
"Deb10Dummy" {ddaf79c3-5a35-4704-bf60-3f87f723dbb0}

It's worth running vboxmanage list to see all of the available options of the "list" sub-command.

Where this gets interesting is if you have VMs that are useful headless: in my case, this means machines that have public-facing IP addresses and public-facing services. Volumeio is a pre-packaged possibility, but recently I'm using VirtualBox to create Debian servers to emulate standard cloud servers so that I can provision them with Ansible allowing me to spin up local web servers, database servers, whatever I want - all running off a small machine sitting in the corner.

Would it be better to use Proxmox or some other libvirt-based system to create VMs? Almost certainly. But I had a go with Proxmox and hated it, so I've returned to this good-enough tool that I'm familiar with.

To have a public-facing IP on a VirtualBox VM, you'll need to set up one of the VM machine's Network Adapters as a "Bridged Adapter." I'd recommend it be a fixed IP - although that's up to you, and setting up a fixed IP is a bit of a pain. Remember you're setting these machines up headless and if they're DHCP, you can only access them by name and the IP will change ...

Before you take this next step, make sure the machine is externally accessible as you expect it to be when you run it from the regular GUI VirtualBox interface. To start a machine headless:

$ vboxmanage startvm Deb10Dummy --type headless

To take the machine down again, you can use this command:

$ vboxmanage controlvm Deb10Dummy poweroff

For machines that have public SSH access I prefer to log in to them and run poweroff & exit which is probably a cleaner shutdown, but both methods work.

Further Reading

vboxmanage is provided without a man page. The --help option produces an impressive 900 lines of options, without really telling you what any of them do. The documentation you need is here: