Create a Headless Virtualbox Service on Ubuntu

VirtualBox is a hypervisor that supports many different operating systems. It is possible to host multiple different operating systems on a basic computer.

0 . Latest updates and prerequisites.

2023.10.01 – First draft, Ubuntu 22.04 Server.
2024.10.27 – Updated for Ubuntu 24.04 Server.

Leave a comment if the post is missing some detail.

Sudo or root access is needed for this, additionally, a basic Docker environment, as the control panel runs in a container.

The computer must have virtualisation support enabled or only some 32 bit guests are possible.

1 . Install VirtualBox.

The keys from the official repository must be trusted:

sudo wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg

Then add the repository:

sudo echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list

Update package data:

sudo apt update

Install VirtualBox:

sudo apt install VirtualBox-7.0

Download the version specific VirtualBox Extensions:

ver=$( vboxmanage -v | cut -dr -f1)
cd
wget https://download.virtualbox.org/virtualbox/$ver/Oracle_VM_VirtualBox_Extension_Pack-$ver.vbox-extpack

Install the extensions:

sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-$ver.vbox-extpack

Create a user, group and password for the software to run as:

sudo useradd -m -d /home/vbox -g vboxusers -s /bin/false vbox 
sudo passwd vbox

Create a basic configuration file:

sudo nano /etc/default/virtualbox

At a minimum, the configuration file must have these variables, substitute host_IP_address for the actual value:

VBOXWEB_USER=vbox
VBOXWEB_HOST=host_IP_address
VBOXWEB_PORT=18083

Restart the web service and check if it is running:

sudo systemctl restart vboxweb-service
sudo systemctl status vboxweb-service

You should see something like this, showing “running” in green:

 vboxweb-service.service
     Loaded: loaded (/usr/lib/virtualbox/vboxweb-service.sh; enabled; ven>
     Active: active (running) since Sun 2023-10-01 13:54:19 UTC; 13ms ago
    Process: 8331 ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start >
      Tasks: 10 (limit: 18996)
     Memory: 10.4M
        CPU: 60ms
     CGroup: /system.slice/vboxweb-service.service
             ├─8343 /usr/lib/virtualbox/vboxwebsrv --background -H 172.16>
             ├─8345 /usr/lib/virtualbox/VBoxXPCOMIPCD
             └─8351 /usr/lib/virtualbox/VBoxSVC --auto-shutdown

There should also be a reserved port opened, it can be seen with netstat:

root@server40:~# netstat -tulpn | grep 18083
tcp        0      0 172.16.30.40:18083      0.0.0.0:*               LISTEN      8343/vboxwebsrv

Notice 18083, that is the VirtualBox web management port. With all of the experiementing to write this post, this service proved to be problematic. It is often the case time must be taken inbetween service restarting and always check the port is available at the expected IP with netcat:

sudo nc -vz host_IP_address 18083

Substitute host_IP_address for the actual value. The port should be accepting connections:

Connection to 172.16.30.202 18083 port [tcp/*] succeeded!

2 . Install the VirtualBox web based control panel.

Install docker-compose:

sudo apt install docker-compose-v2

The web control panel needs only interface with the web service port, bearing that in mind, the panel can be installed by creating a file, /opt/docker/docker-compose.yml and adding this section , for the phpvirtualbox package:

 ...
   vbox_http:
     container_name: vbox_http
     image: jazzdd/phpvirtualbox
     ports:
       - "8081:80"
     environment:
       ID_HOSTPORT: "server_ip_address:18083"
       ID_NAME: "server_name"
       ID_USER: "vbox_username"
       ID_PW: "vbox_username_password"
       CONF_browserRestrictFolders: "/home,/data,"
     restart: unless-stopped
...

Start the service from within the /opt/docker directory:

docker compose up -d

Once the configuration is loaded, the web control panel becomes available. The default user/pass is admin/admin. Change the password immediately through the File menu.

The VirtualBox environment can now be controlled by a web panel.

3 . Create a virtual guest.

From the web control panel, create a new server taking care of the location of ISO images and disk files.

root@server40:/opt/docker# mkdir -p /opt/virtualbox/server41
root@server40:/opt/docker# chown vbox:root /opt/virtualbox/
root@server40:/opt/docker# chmod 775 /opt/virtualbox/

Beware that disk files can become big and operating system files should lie on SSDs for performance.

Once the server is up and running, it can be remote controlled until a remote service is installed and setup, such as RDP for WIndows or SSH for many others. Check the remote display is setup, then connect to a terminal as a console user, using one of the ports from this setting for the server:

Each server will take a successive port number for the console interface. Beware this is convenience but also a security concern. Use this feature sparingly or setup a firewall limitation for the console, it is an overpowered view of the virtual environment.

4 . Supporting this blog.

This type of content takes a lot of effort to write. Each post is drafted, researched, then tested multiple times, even a simple step or detail might take more than a few hours to go from the idea to a published blog post.

Did you notice there are no adverts on this site?

If you feel I have saved you some time, you can support me by;

©horsefreeglue.com, 2024. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given.

Spread the love
error: Content is protected !!