How to install VirtualBox 6.x with phpVirtualbox web interface on Debian 11 bull

74 阅读5分钟

How to install VirtualBox 6.x with phpVirtualbox web interface on Debian 11 bullseye/openmediavault 6

The new Open Media Vault 6 uses Debian 11 as the base system. And for a long time, Virtual Box didn't support it. After it did, everyone whose using OMV6 has gone to the KVM platform for virtualization needs. And for the cause of that, everything related to this topic is either fractions or incomplete. I have tried KVM for a short time, and the overall experience of that is just something off for me. So I am doing this with Virtual Box again and writing this down for later use, or maybe it just helps someone who's in flavoured with me in Virtual Box.

1. Prerequisites:

A working system could be either a Debian 11 bullseye or the open media vault 6, which is essentially Debian 11.

2. Plans:

  1. Install Virtual Box 6 headless version.
  2. Install Docker to containerize the web interface coming from the project phpvirtualbox.
  3. Setting up phpvirtualbox using Docker/Docker Compose.

3. Installations:

3.1 Install Virtual Box

First, before we install the Virtual Box itself, we need to tackle the dependencies for it to run without errors.

Use this command line to install them.

sudo apt install wget build-essential python2

Next, we need to download the installer. There're many ways to install Virtual Box on a Linux system. But for the sake of this tutorial, I'll go with the installer one.

Here's a list of all the releases: download.virtualbox.org/virtualbox/

Because the PHP program for the web interface is only supporting up to 6.x, so we'll go with 6.1.40, which is the last version before 7.

Use wget to download the files straight into the file system. And then, add the execute permission for the installer and run it.

# download file
wget https://download.virtualbox.org/virtualbox/6.1.40/VirtualBox-6.1.40-154048-Linux_amd64.run

# grant permission
chmod u+x VirtualBox-6.1.40-154048-Linux_amd64.run

# execute it
sudo ./VirtualBox-6.1.40-154048-Linux_amd64.run

Virtual Box extension pack is a binary package that extends the functionality of Virtual Box. It provides extensions like USB support and hardware pass-through. But for the most important ones, we need it for RDP, which stands for Remote Desktop Protocol. Because it is headless, we can't exactly see anything unless we use another system to connect to it. That's why we have to install it.

# download
wget https://download.virtualbox.org/virtualbox/6.1.40/Oracle_VM_VirtualBox_Extension_Pack-6.1.40.vbox-extpack

# installation
sudo vboxmanage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-6.1.40.vbox-extpack

Next, we need to create a user and a user group for Virtual Box.

# create user with a home directory
sudo useradd -m username

# change its password
sudo passwd username

Log in as that user and add a user group for yourself.

sudo usermod -aG vboxusers $(id -un)

You can verify it by typing id -nG. It will show all your groups like this:

users www-data vboxusers home

Then we reboot for things to kick in.

reboot

Up to this point, you should be able to verify the installation by this.

virtualbox -h

If nothing goes wrong, then it will output something like this:

Oracle VM VirtualBox VM Selector v6.1.40
(C) 2005-2022 Oracle Corporation
All rights reserved.

No special options.

If you are looking for --startvm and related options, you need to use VirtualBoxVM.

But of course, it goes wrong on my side...

See if you're having the same issues I have:

3.1.1 Common errors:

1. Header problem:

WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (6.0.0-0.deb11.2-amd64) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

         You will not be able to start VMs until this problem is fixed.

And we do as it says:

sudo /sbin/vboxconfig

Output something like this:

vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    linux-headers-amd64 linux-headers-6.0.0-0.deb11.2-amd64
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    linux-headers-amd64 linux-headers-6.0.0-0.deb11.2-amd64
    ...

This is caused by not having the headers lib installed. Follow what it suggests and install them all.

sudo apt install linux-headers-amd64 linux-headers-6.0.0-0.deb11.2-amd64

Then try these two again:

sudo /sbin/vboxconfig

virtualbox -h

2. GL problem:

If it shows something like:

/opt/VirtualBox/VirtualBox: error while loading shared libraries: libGL.so.1: cannot open shared object file: No such file or directory

That's because it lacks OpenGL support. Install this:

apt install libglu1-mesa

If it works, congratulations! 🙌🙌

Now log in as the user you created earlier and do this:

vboxwebsrv -b -H0.0.0.0 -p10082 -F/vm/logs/vboxwebsrv.log

This is the headless Virtual Box server side for accepting HTTP requests.

-b means it starts in the backgroud. -H for listening on all addresses. -p for which port you want it to listen to. -F is the file for storing logs.

3. Directory problem:

It may crash at once if you don't have a home directory for this user. Like this:

vboxwebsrv: error: failed to initialize COM! hrc=NS_ERROR_FAILURE

In case that happens, create a home directory manually for it. It will put the config stuff in the home directory of the current user.

You may use the following ways to check if the service is up.

# expect outputs
curl localhost:port

# expect the process is in the list
ps -ef | grep vbox

# ditto
lsof -i :port

If the service is up, then we're good for this part.

3.2 Get Docker Engine

For different ways of installing Docker, see here: docs.docker.com/engine/inst…

Use the convenience script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh

That should do everything right, but you can test it out if you want.

3.3 Run phpvirtualbox with Docker

phpvirtualbox is a web interface that allows you to interact with a remote Virtual Box instance.

Here's the project: github.com/phpvirtualb…

But we're not going to deploy it with a PHP server and all that hassles. Here's another project based on phpvirtualbox: github.com/jazzdd86/ph…

Which turns the former into a Docker image that we can easily set up with just one command line:

docker run --name <a-name-here> --restart=unless-stopped \
    -p <port-for-access-the-gui>:80 \
    -e ID_HOSTPORT=<the-host-ip:port> \
    -e ID_NAME=<a-random-name-you-like> \
    -e ID_USER=<your-username> \
    -e ID_PW='<your-password>' \
    -e CONF_browserRestrictFolders="<directories-you-want-the-vm-to-have-access-to>" \
    -d jazzdd/phpvirtualbox

You'll need to change all the fields in quotes. Here's a reference case:

docker run --name vbox --restart=always \
    -p 10080:80 \
    -e ID_HOSTPORT=192.168.1.1:10082 \
    -e ID_NAME=VboxServer \
    -e ID_USER=vbox \
    -e ID_PW='vbox' \
    -e CONF_browserRestrictFolders="/vm" \
    -d jazzdd/phpvirtualbox

After it's up, navigates to http://the-host-ip:port in the browser and use the default account: admin/admin to log in. And you should see a GUI that somewhat resembles the Virtual Box standard alone version.

4. One more thing:

There's a catch you might wanna know: This phpvirtualbox GUI is not 100% aligned with the Virtual Box that we install. Which includes these problems (but not least):

1. Some settings just won't work.

There're some settings in the GUI that you won't be able to change. I've noticed at least the Keyboard, Mouse, Audio and Video accelerations, amongst other options. They remain the same even if you have saved them. It's not too bad. But not brilliant, if you ask. If you need them working, there's a workaround: Use the Virtual Box command line tool to change these settings. You can set up the basics via the GUI and then tweak those little things in the terminal.

# to list the virtual machines, copy their name/id
vboxmanage list vms

# check their info
vboxmanage showvminfo vm-name

# change audio settings
vboxmanage modifyvm vm-name --audioin on --audioout on

# change keyboard, mouse settings
vboxmanage modifyvm vm-name --keyboard usb --mouse usb

# get a list of all the options
vboxmanage modifyvm

2. The RDP from Virtual Box isn't perfect.

Even though we need the RDP from the extension pack to initialize the virtual machines out of the box yet, it is not perfect. I have noticed that the audio from the RDP from the Virtual Box host is not working right. It turns everything into a stuttering, high-pitched sound. It sounds like a bunch of chipmunks speaking through a Gater FX. And the workaround is to have the virtual machines set up the RDP from their system, and we connect to those. For example, in Windows. Turn on the Remote Desktop feature in Settings, and instead of connecting to the host IP, connect to the guest IP with the bridged network. And the sound will be back to normal again.

And here's all for today. Thanks for reading~