9

I've recently updated a headless server to Ubuntu Server 15.10.

  • Basic Ubuntu Server
  • LAMP
  • Xubuntu minimal install

I've installed virtualbox 5.0.14 from default Ubuntu sources. I've downloaded and installed virtualbox/5.0.14/Oracle_VM_VirtualBox_Extension_Pack-5.0.14-105127.vbox-extpack

I've defined a user vbox in group vboxusers, and basically virtualbox itself works fine. But I want it to be remotely configurable by using phpvirtualbox.

I downloaded and installed phpvirtualbox-5.0-5.zip

I added the VBOXWEB_USER=vbox to file /etc/default/virtualbox.

When visiting the webpage from another machine, I got an error Could not connect to host (see msg1, and with more details in msg2, not really important though, I think.).

Using sudo netstat -peanut, it looked like vboxwebsrv was not using the correct IP address. It showed the local address as ::1:18083 instead of the expected 192.168.1.12:18083.

After some googling, I added VBOXWEB_HOST=192.168.1.12 to file /etc/default/virtualbox, but still no change after restarting the service.

However, if I stopped the service with sudo systemctl stop vboxweb.service and started it manually with sudo vboxwebsrv -H 192.168.1.12, that worked fine. sudo netstat -peanut now reported it with the expected IP/port adress.

Most of the documentation I looked at referred to init.d and I started thinking that perhaps systemd does not use the /etc/default/virtualbox file... I found that I could edit the file /lib/systemd/system/vboxweb.service, and added a -H 192.168.1.12 to the ExecStart command. After a restart of the vboxweb service, it worked! :o)

Enabled service so that it would start automatically at boot time:

sudo systemctl enable vboxweb.service

But after rebooting, there was no vboxweb showing in sudo netstat -peanut at all, although ps -ef showed the service started:

$ps -ef

root 1383 1 0 mars02 ? 00:00:00 /usr/lib/virtualbox/vboxwebsrv --pidfile /run/vboxweb.pid --background -H 192.168.1.12 -p 18083

A restart of the service will fix it, but it will not come up correctly after reboot.

So I was thinking that perhaps the vboxweb.service was started too early in the systemd initialization process. So I edited the vboxweb.service file again, with After=apache2.service (and later also tried After=multi-user.target), and verified with systemd-analyse plot that the init of vboxweb was indeed moved to the very end of the initialization sequence. But still, wboxweb was not listed in netstat -peanut

So finally to my questions:

  1. Are there conflicts between init.d and systemd, e.g. that virtualbox (from standard Ubuntu sources) relies on files that are init.d specific, while Ubuntu has moved on to systemd?
  2. Any other reason why the VBOXWEB_HOST setting in the /etc/default/virtualbox file had no effect?
  3. Was it correct to edit the vboxweb.service file (specifically with the host parameter).
  4. (and this is the important one) How do I get vboxweb service up and running with correct IP/port settings at boot time? I am all out of ideas :/

PS: I know I could have shortened this post a lot, and just kept the main question here, as I have resolved the rest (leaving only a couple of questions), but I thought it could be interesting for others to see how I've worked on this problem.

BR, Rolf

0

4 Answers 4

6

After some more googling and mucking about, I finally came up with a solution:

1) I concluded that the /etc/defaults/virtualbox file did not seem to have any effect on anything (just a remnant from the init.d days?). So the user and group settings in that file was wasted.

Solution: Added User=vbox and Group=vboxusers in the [Service] section of the vboxweb.service file.

2) Some of the problems I had was due to the vboxweb.config file referring to a pid-file in the /run folder, and vbox has no write access to that folder. First I tried to make a subfolder, owned by vbox, in which to store the pid file, but I learned that the /run folder gets wiped at boot time, including all subfolders.

Solution: Created a subfolder in vbox homedir, and updated vboxweb.config file with that location.

3) For some reason (which still eludes me), referring to the actual IP address, 192.168.1.12, in config.php (in the phpvirtualbox folder) and in the vboxweb.config file (as mentioned in the original post), did not work at boot time. (A later restart of the service would work though.)

Solution: Updated both config.php and vboxweb.config with IP address 127.0.0.1 instead of 192.168.1.12.

Case closed! :o) ...apart for all the questions about why things are the way they are, but I can live with that :o)

BR, Rolf

2
  • I have the exactly same problem, but in my case /etc/default/virtualbox make difference in configuration and there is no vboxweb.config in my system, still trying to figure out whats Is happening. Nov 3, 2017 at 17:28
  • 1
    TLDR; The Oracle package has a completely different systemd unit file and respects /etc/defaults/virtualbox Sorry to necromance, but adding this in hopes it'll be useful for future. I installed virtualbox 5.2.18-dfsg-2~ubuntu18.04.3 on 18.04 from the ubuntu repos and as stated it completely ignored /etc/default/virtualbox. HOWEVER, out of curiosity I also installed the Oracle version and had no issues whatsoever. Something about the Ubuntu unit file/startup script is breaking/ignoring etc/defaults/virtualbox in a way that the Oracle pkg handles just fine.
    – mrlitsta
    Feb 21, 2019 at 23:04
2

In my install version there were some built-in bugs in the services:

$ dpkg -l | grep -i virtualbox
ii  virtualbox                                 6.1.10-dfsg-1~ubuntu1.20.04.1         amd64        x86 virtualization solution - base binaries
ii  virtualbox-dkms                            6.1.10-dfsg-1~ubuntu1.20.04.1         amd64        x86 virtualization solution - kernel module sources for dkms
ii  virtualbox-qt                              6.1.10-dfsg-1~ubuntu1.20.04.1         amd64        x86 virtualization solution - Qt based user interface

Plus you have to define at least one parameter as per this:

On Linux, the web service can be automatically started during host boot by adding appropriate parameters to the file /etc/default/virtualbox. There is one mandatory parameter, VBOXWEB_USER, which must be set to the user which will later start the VMs.

Let's suppose this user is pjfinn. Here are the fix/mods. Add the user to the vboxusers group:

$ sudo usermod -a -G vboxusers pjfinn

Create the directory run under pjfinn's home:

$ mkdir /home/pjfinn/run

Then apply the following patches.

Patch #1:

*** /etc/default/virtualbox-orig  2020-12-07 17:02:51.567517505 +0100
--- /etc/default/virtualbox 2020-12-07 18:23:58.436155855 +0100
***************
*** 21,23 ****
--- 21,26 ----
  #   30 seconds for the VMs to shutdown
  SHUTDOWN_USERS=""
  SHUTDOWN=poweroff
+ 
+ # 2020/12 pj_finnegan fix - define mandatory parameter
+ VBOXWEB_USER=pjfinn

Patch #2:

*** /lib/systemd/system/vboxweb.service-orig 2020-12-07 16:13:43.776834092 +0100
--- /lib/systemd/system/vboxweb.service   2020-12-07 19:24:07.352940488 +0100
***************
*** 1,11 ****
  [Unit]
  Description=VirtualBox Web Service
! After=network.target
  
  [Service]
  Type=forking
  ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start
! PIDFile=/run/vboxweb.pid
  
  [Install]
  WantedBy=multi-user.target
--- 1,13 ----
  [Unit]
  Description=VirtualBox Web Service
! Requires=virtualbox.service
! After=network.target virtualbox.service
  
  [Service]
  Type=forking
  ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start
! ExecStop=/usr/lib/virtualbox/vboxweb-service.sh stop
! PIDFile=/home/pjfinn/run/vboxweb.pid
  
  [Install]
  WantedBy=multi-user.target

Patch #3:

*** /usr/lib/virtualbox/vboxweb-service.sh-orig 2020-12-07 17:00:04.901783182 +0100
--- /usr/lib/virtualbox/vboxweb-service.sh  2020-12-07 18:08:43.586981699 +0100
***************
*** 29,34 ****
--- 29,37 ----
  # X-Required-Target-Start: network-online
  ### END INIT INFO
  
+ # 2020/10 pj_finnegan fix - save binary PIDFILE received from systemd
+ VBOXWEB_PIDFILE="$PIDFILE"
+ 
  PATH=$PATH:/bin:/sbin:/usr/sbin
  SCRIPTNAME=vboxweb-service.sh
  
***************
*** 135,140 ****
--- 138,148 ----
          [ -n "$VBOXWEB_ROTATE" ]         && PARAMS="$PARAMS -R $VBOXWEB_ROTATE"
          [ -n "$VBOXWEB_LOGSIZE" ]        && PARAMS="$PARAMS -S $VBOXWEB_LOGSIZE"
          [ -n "$VBOXWEB_LOGINTERVAL" ]    && PARAMS="$PARAMS -I $VBOXWEB_LOGINTERVAL"
+ 
+         # 2020/12 pj_finnegan fix - avoid error:
+         #  Can't open PID file /run/vboxweb.pid (yet?) after start: Operation not permitted
+         [ -n "$VBOXWEB_PIDFILE" ]        && PARAMS="$PARAMS -P $VBOXWEB_PIDFILE"
+ 
          # set authentication method + password hash
          if [ -n "$VBOXWEB_AUTH_LIBRARY" ]; then
              su - "$VBOXWEB_USER" -c "$vboxmanage setproperty websrvauthlibrary \"$VBOXWEB_AUTH_LIBRARY\""

Then execute the commands:

$ sudo systemctl daemon-reload

Finally the admin commands:

$ sudo systemctl start vboxweb.service
$ systemctl status vboxweb.service
● vboxweb.service - VirtualBox Web Service
     Loaded: loaded (/lib/systemd/system/vboxweb.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2020-12-07 18:13:42 CET; 2s ago
    Process: 8997 ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start (code=exited, status=0/SUCCESS)
   Main PID: 9023 (vboxwebsrv)
      Tasks: 20 (limit: 18850)
     Memory: 15.0M
     CGroup: /system.slice/vboxweb.service
             ├─9023 /usr/lib/virtualbox/vboxwebsrv --background -P /home/pjfinn/run/vboxweb.pid
             ├─9025 /usr/lib/virtualbox/VBoxXPCOMIPCD
             └─9031 /usr/lib/virtualbox/VBoxSVC --auto-shutdown

Dec 07 18:13:42 yourhost systemd[1]: Starting VirtualBox Web Service...
Dec 07 18:13:42 yourhost vboxweb-service.sh[8997]: vboxweb-service.sh: Starting VirtualBox web service.
Dec 07 18:13:42 yourhost vboxweb-service.sh[9014]: Starting VirtualBox web service.
Dec 07 18:13:42 yourhost systemd[1]: Started VirtualBox Web Service.

$ sudo systemctl stop vboxweb.service
$ systemctl status vboxweb.service
● vboxweb.service - VirtualBox Web Service
     Loaded: loaded (/lib/systemd/system/vboxweb.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Mon 2020-12-07 18:19:45 CET; 2s ago
    Process: 8997 ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start (code=exited, status=0/SUCCESS)
    Process: 9135 ExecStop=/usr/lib/virtualbox/vboxweb-service.sh stop (code=exited, status=0/SUCCESS)
   Main PID: 9023 (code=exited, status=0/SUCCESS)

Dec 07 18:13:42 yourhost systemd[1]: Starting VirtualBox Web Service...
Dec 07 18:13:42 yourhost vboxweb-service.sh[8997]: vboxweb-service.sh: Starting VirtualBox web service.
Dec 07 18:13:42 yourhost vboxweb-service.sh[9014]: Starting VirtualBox web service.
Dec 07 18:13:42 yourhost systemd[1]: Started VirtualBox Web Service.
Dec 07 18:19:39 yourhost systemd[1]: Stopping VirtualBox Web Service...
Dec 07 18:19:39 yourhost vboxweb-service.sh[9135]: vboxweb-service.sh: Stopping VirtualBox web service.
Dec 07 18:19:45 yourhost systemd[1]: vboxweb.service: Succeeded.
Dec 07 18:19:45 yourhost systemd[1]: Stopped VirtualBox Web Service.

$ sudo systemctl restart vboxweb.service

should all work fine, and the errors at boot should disappear.

1

rolfhsp's answer is really helpful.

In addition, if vboxweb.service is modified to run as some other user which is non root, another failure would occur. In this situation, the cause is logged as "Failed to open “/dev/vboxdrvu”, errno=13, rc=VERR_VM_DRIVER_NOT_ACCESSIBLE", which means the user has no permission to access /dev/vboxdrvu.

By default, /dev/vboxdrvu along with /dev/vboxnetctl and /dev/vboxdru are all permitted for root only (crw-------). for non-root users to access it, the permission must be modified. According to this blog, it is archived by simply putting a "rules" file into /lib/udev/ with content below:

/lib/udev/rules.d/20-virtualbox2.rules:

KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
KERNEL=="vboxdrvu", NAME="vboxdrvu", OWNER="root", GROUP="vboxusers", MODE="0660"
KERNEL=="vboxnetctl", NAME="vboxnetctl", OWNER="root",GROUP="vboxusers", MODE="0660"

Then restart the system, after reboot, those files have new permissions:

crw-------. 1 root root      10, 54 Mar 20 00:24 /dev/vboxdrv
crw-rw----. 1 root vboxusers 10, 53 Mar 20 00:24 /dev/vboxdrvu
crw-rw----. 1 root vboxusers 10, 52 Mar 20 00:24 /dev/vboxnetctl

Although vboxdru is still unchanged, vboxdrvu already has good permission for a non-root (in vboxusers group) to access. After this modification, vboxweb.service could be run by a non-root user successfully.

0

Compiling directly the VirtualBox instead of installing it using apt works for me:

  1. Download the .run file in https://download.virtualbox.org/virtualbox/6.1.26/ (this is version 6.1.26, replace the URL with the most recent or your version)
  2. Install gcc, make and perl apt-get update && apt-get install gcc make perl.
  3. Install the .run file. bash *.run.

After installing in this way

  1. Put your user in vboxusers groups, created already in the installation of VirtualBox usermod -aG vboxusers $USER
  2. Create virtualbox file inside /etc/default with the follow content:
VBOXWEB_USER="{YOUR_USER}"
  1. Restart the server
  2. Check if vboxwebsrv is running ps aux | grep vboxwebsrv

Done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .