[CentOS] Systemd and VirtualBox

Rob Kampen rkampen at kampensonline.com
Tue May 17 07:55:01 UTC 2016

The continuing challenges of getting a workable server continue.
The latest spins of VirtualBox seem to have solved the issues of DKMS 
auto compiles of the driver being aborted. The yum updates work as 
expected, provided one stops the running vms manually first.

However, trying to get systemd to start the vms is proving to be a PITA.
I have extensively googled and found that there are no specific 
instructions for Fedora/Redhat/CentOS and VirtualBox setups for systemd. 
After many trials and errors I have this systemd service file:

filename - /etc/systemd/system/vboxstarter at .service

Description=VBox Virtual Machine %i Service
Requires=systemd-modules-load.service vboxballoonctrl-service.service
After=systemd-modules-load.service vboxballoonctrl-service.service

Environment="VBOX_USER_HOME=/home/rkampen/VirtualBox VMs/%i"
ExecStart=/usr/bin/VBoxHeadless -s %i
ExecStop=/usr/bin/VBoxManage controlvm %i savestate


and on occasions the invocation
systemctl start vboxvmstarter at Windoze10_2.service
will work, although recently it is failing always with

 >$ systemctl status vboxvmstarter at Windoze10_2.servicevboxvmstarter at Windoze10_2.service - VBox Virtual Machine Windoze10_2 
    Loaded: loaded (/etc/systemd/system/vboxvmstarter at .service; enabled; 
vendor preset: disabled)
    Active: deactivating (stop-sigterm) (Result: exit-code) since Tue 
2016-05-17 03:25:02 EDT; 4s ago
   Process: 1987 ExecStop=/usr/bin/VBoxManage controlvm %i savestate 
(code=exited, status=1/FAILURE)
   Process: 1906 ExecStart=/usr/bin/VBoxHeadless -s %i (code=exited, 
  Main PID: 1906 (code=exited, status=1/FAILURE)
/system.slice/system-vboxvmstarter.slice/vboxvmstarter at Windoze10_2.service
            └─1940 /usr/lib/virtualbox/VBoxSVC --auto-shutdown

May 17 03:25:02 media.pcol.org systemd[1]: Started VBox Virtual Machine 
Windoze10_2 Service.
May 17 03:25:02 media.pcol.org systemd[1]: Starting VBox Virtual Machine 
Windoze10_2 Service...
May 17 03:25:02 media.pcol.org systemd[1]: 
vboxvmstarter at Windoze10_2.service: main process exited, code=exited, 
May 17 03:25:02 media.pcol.org VBoxManage[1987]: VBoxManage: error: 
Could not find a registered machine named 'Windoze10_2'
May 17 03:25:02 media.pcol.org VBoxManage[1987]: VBoxManage: error: 
Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), com...pports
May 17 03:25:02 media.pcol.org VBoxManage[1987]: VBoxManage: error: 
Context: "FindMachine(Bstr(a->argv[0]).raw(), machine.a...VM.cpp
May 17 03:25:02 media.pcol.org systemd[1]: 
vboxvmstarter at Windoze10_2.service: control process exited, code=exited 
Hint: Some lines were ellipsized, use -l to show in full.

as <username> a vboxmanage list vms
"Windoze10_2" {51c8f956-9aba-4d2a-942c-8f46889d5bc0}

shows the required vm.
as root or using sudo it returns nothing.
thus my only conclusion is that systemd actually runs this as root and 
ignores the User= line of the [Service] stanza.

No idea where to from here, so if there is anyone that has a working 
systemd autostart VirtualBox setup on a headless CentOS 7 server - 
please advise what you have done to get it working.
Or any systemd gurus that can point me at the specific foo required to 
beat this deamon into submission.
P.S. I deliberately set up the VirtualBox vms under a non privileged 
user account. I have tried setting up a symbolic link from /root to the 
~/username/VirtualBox\ VMs folder and made root a member of the 
virtualboxusers group - no difference, as expected, but getting desperate.

More information about the CentOS mailing list