Running VirtualBox VM in headless mode
Diarmuid O'Briain, diarmuid@obriain.com<20/02/2016>, version 1.0
Last updated: 20-02-2016 09:42
VirtualBox allows for the running of the Virtual Machine (VM) in headless mode meaning that there is no emulation of graphics. The VM runs as a server and can be accessed via SSH. This reduces what the VM must emulate making it far more efficent. Assuming that VirtualBox is installed and a number of VMs exist.
List virtual machines
From the command prompt of the host (and without the VirtualBox grapical dashboard running), list the available VirtualBox VMs.
ob@e550:~$ VBoxManage list vms "AsteriskNOW" {f26fad29-beff-40ff-a811-fa3ff2bb9f5e} "Debian8-i386" {17a05e94-e657-48dc-871b-51f7472a89ec} "Debian8-i386-CORE-VM" {dc2471a1-0a44-40df-afd7-0dd38774baea} "vCORE-4.8-i386" {698426cb-6d29-43ea-bd8b-80b373d202b5} "CORE-Switching" {c7e3e170-29ee-4620-89b5-d30dff2512c3}
Start VM in headless mode
Start the VM to run in headless mode in the background.
ob@e550:~$ VBoxManage startvm Debian8-i386-CORE-VM --type headless Waiting for VM "Debian8-i386-CORE-VM" to power on... VM "Debian8-i386-CORE-VM" has been successfully started. ob@e550:~$ VBoxManage showvminfo Debian8-i386-CORE-VM | grep State State: running (since 2016-02-19T15:46:35.817000000)
Get the VM IP Address
First get the MAC address of the VM, then look at the host Address Resolution Protocol (ARP) table to find the associated IP address.
ob@e550:~$ vboxmanage showvminfo Debian8-i386-CORE-VM --details | grep 'NIC 1' NIC 1: MAC: 0800279D3BDA, Attachment: Bridged Interface 'wlan0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none ob@e550:~$ arp Address HWtype HWaddress Flags Mask Iface 192.168.10.4 ether 08:00:27:9d:3b:da C wlan0 smile-admin.localdomain ether f4:63:49:19:e4:82 C wlan0 192.168.10.5 (incomplete) wlan0 0800279D3BDA --> 08:00:27:9d:3b:da --> 192.168.10.4
Connect via SSH
It is now a simple matter of connecting to the IP address with SSH. If a graphical application needs to be ran, use the -X option for X11 forwarding. Here is an example of running the CORE Emulator dashboard.
ob@e550:~$ ssh -X core@192.168.10.4 core@192.168.10.4's password: xxxx The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Fri Feb 19 15:36:17 2016 from 192.168.10.2 core@CORE-i386:~$ core
Power off VM
To power down a headless VM. Identify the VM from the running VMs.
ob@e550:~$ vboxmanage list runningvms "Debian8-i386-CORE-VM" {dc2471a1-0a44-40df-afd7-0dd38774baea}
Power off the VM you wish to shutdown.
ob@e550:~$ VBoxManage controlvm Debian8-i386-CORE-VM poweroff 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%