VirtualBox 5.2 headless on Ubuntu 17.10

Following on from my previous guide VirtualBox Headless on Ubuntu 16.04 I have now updated this for Ubuntu 17.10 as I got a new server 🙂

This guide explains how you can run virtual machines with VirtualBox 5.2 on a headless Ubuntu 17.10 server. Normally you use the VirtualBox GUI to manage your virtual machines, but a server does not have a desktop environment. Fortunately, VirtualBox comes with a tool called VBoxHeadless that allows you to connect to the virtual machines over a remote desktop connection, so there’s no need for the VirtualBox GUI.

1 Preliminary Note
I have tested this on a freshly installed Ubuntu 17.10 server (host system) where I’m logged in as a normal user.

The only option chosen during the install was SSHD Server.

After initial boot, I usually add a few standard things:

sudo apt-get install -y vim-nox

Ensure everything is updated:

sudo apt update && sudo apt upgrade && sudo apt dist-upgrade

Ensure everything is tidied up:

sudo apt clean && sudo apt autoclean && sudo apt autoremove

Install Linux headers:
(The dkms package ensures that the VirtualBox host kernel modules are properly updated if the Linux kernel version changes.)

sudo apt -y install gcc make linux-headers-$(uname -r) dkms

2 Installing VirtualBox
To install VirtualBox 5.2 on our Ubuntu 17.10 server …

Download the VirtualBox public key:

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

Add VirtualBox sources to apt :

sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list'

Unfortunately at the time of writing there is no Artful release of VirtualBox 5.2, so I had to use the one from Zesty.

To do this I modified the “/etc/apt/sources.list.d/virtualbox.list” file by commenting out the exiting line and adding

deb http://download.virtualbox.org/virtualbox/debian zesty contrib

… and update our package database:
sudo apt-get update

Install VirtualBox 5.2:
sudo apt install -y virtualbox-5.2

3 Installing VirtualBox Extensions
VirtualBox has “extension packs” that provide functionality like remote desktop connection support (VRDP).
VBOXVERSION=`VBoxManage --version | sed -r 's/([0-9])\.([0-9])\.([0-9]{1,2}).*/\1.\2.\3/'`
wget -q -N "http://download.virtualbox.org/virtualbox/$VBOXVERSION/Oracle_VM_VirtualBox_Extension_Pack-$VBOXVERSION.vbox-extpack"
sudo VBoxManage extpack install --replace Oracle*.vbox-extpack

Agree to the terms and install.

8. Add headless user
– Add a vbox user
sudo adduser vbox
– Add the user to the vboxusers group:
sudo adduser vbox vboxusers

9. Configure autostart
Modify the file /etc/default/virtualbox and add a few variables.

VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and
VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings.


echo 'VBOXAUTOSTART_DB=/etc/vbox' | sudo tee -a /etc/default/virtualbox
echo 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg' | sudo tee -a /etc/default/virtualbox

Create the autostart.cfg file
NB: You may need to change the username or add others, depending on your installation.

echo '# Default policy is to deny starting a VM, the other option is "allow".' | sudo tee /etc/vbox/autostart.cfg
echo 'default_policy = deny' | sudo tee -a /etc/vbox/autostart.cfg
echo '# Create an entry for each user allowed to run autostart' | sudo tee -a /etc/vbox/autostart.cfg
echo 'vbox = {' | sudo tee -a /etc/vbox/autostart.cfg
echo 'allow = true' | sudo tee -a /etc/vbox/autostart.cfg
echo '}' | sudo tee -a /etc/vbox/autostart.cfg

If you are the only user you can just add the line default_policy = allow to the autostart.cfg file.

Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.
sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox

Add each of the users to the vboxusers group.
sudo usermod -a -G vboxusers USERNAME
(replace USERNAME with the username)
NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions.

Create start/stop files
cd /etc/vbox
sudo touch vbox.start
sudo touch vbox.stop

And change owner with:
sudo chown vbox:vboxusers vbox.start
sudo chown vbox:vboxusers vbox.stop

Enable autostart/autostop:
Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

su vbox VBoxManage setproperty autostartdbpath /etc/vbox

and enable autostart/autostop for an individual VM with
NB: The VM needs to be shut down for this command
VBoxManage modifyvm gitlab --autostart-enabled on --autostop-type acpishutdown

NB: autostop types: disabled, savestate, poweroff, acpishutdown
This will create a myuserid.start file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.
sudo service vboxautostart-service restart

9. Clean up and reboot
As good practice I always update and clean up before rebooting when installing new software

sudo apt update && sudo apt upgrade
sudo apt clean && sudo apt autoclean && sudo apt autoremove

sudo reboot now

2 thoughts on “VirtualBox 5.2 headless on Ubuntu 17.10

Leave a Reply