Systemd And VirtualBox

Home » CentOS » Systemd And VirtualBox
CentOS 14 Comments

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@.service

[Unit]
Description=VBox Virtual Machine %i Service Requires=systemd-modules-load.service vboxballoonctrl-service.service After=systemd-modules-load.service vboxballoonctrl-service.service Conflicts=shutdown.target

[Service]
User=
Group=vboxusers Restart=on-failure TimeoutSec=5min Environment=”VBOX_USER_HOME=/home/rkampen/VirtualBox VMs/%i”
ExecStart=/usr/bin/VBoxHeadless -s %i ExecStop=/usr/bin/VBoxManage controlvm %i savestate

[Install]
WantedBy=multi-user.target

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

>$ systemctl status vboxvmstarter@Windoze10_2.service
● vboxvmstarter@Windoze10_2.service – VBox Virtual Machine Windoze10_2
Service
Loaded: loaded (/etc/systemd/system/vboxvmstarter@.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, status=1/FAILURE)
Main PID: 1906 (code=exited, status=1/FAILURE)
CGroup:
/system.slice/system-vboxvmstarter.slice/vboxvmstarter@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@Windoze10_2.service: main process exited, code=exited, status=1/FAILURE
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@Windoze10_2.service: control process exited, code=exited status=1
Hint: Some lines were ellipsized, use -l to show in full.

as 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. TIA
Rob 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.

14 thoughts on - Systemd And VirtualBox

  • I deliberately bailed on VirtualBox when we moved to C7, as KVM offered everything I needed with less hassle.

    I take it you’ve considered switching?

    jh

  • Considered, very briefly. I have had great success and stability with running VirtualBox on both CentOS 5 & 6 for the few Windoze apps that my clients need to run and have up on a server 24×7. The set ups I am using have been running reliably for over 8 years and remote manged with zero issues – HUGE thanks to the CentOS team for an awesome OS system delivery Thus, I have simply installed the latest VirtualBox on CentOS 7 and gone from there. I was aware that systemd existed and deliberately waited until this year to upgrade the hardware and OS, thinking issues like this should have been sorted by now. Are there any good tutorial / howtos for KVM? Although at this point I
    am back on another continent and reluctant to shift to KVM when over 20
    hours fly time away from the server.

  • Why would that be an issue? It’s not Xen where you have to boot into a special kernel … it’s just the ordinary kernel. In fact I’d be surprised if you had to reboot at all, you should just have to install the virtualization group (along with virt-tools and virt-manager to make your life easier, dont’ forget to install fonts if using virt-manager over X
    forward and wanting to avoid little boxes instead of characters) and be up and running.

  • thanks James. I have started working through the document you indicated and will see how it goes. It may take a few days to sort out enough time. BTW, will I be able to use the Windows10 image file that VirtualBox uses?
    Is there a tool that changes the format of the vm image if its different?
    Or am I faced with a new Windoze install and installing the Windoze Apps all over again?
    That may be an issue as the Windoze application is quite complex and the last two times I have installed it, I had to use the app provider’s help line to solve Windoze 10 issues as the default install has some things that need changing in order for their app to work.

  • –17vw3U7nfkmumR6RSdixDR4BcmRAnVC6r Content-Type: text/plain; charset=windows-1252
    Content-Transfer-Encoding: quoted-printable

    You can convert a Virtual Box VM into a KVM VM, it is a 2 step process. First is to convert ALL the drives to RAW format, then convert them to qcow2 image.

    If you only have one drive for the VM, it is fairly easy. Here is one of many links from google:

    https://kuther.net/content/convert-virtualbox-kvmqemu

    Lots of other links available as well.

    The qemu-img in CentOS 7 can do this in one step instead of 2 though …

    qemu-img convert -f vdi -O qcow2 vm.vdi vm.qcow2

    (You would substitute your actual vdi file name for vm.vdi and name the output file whatever you want instead of vm.qcow2).

    Once you have a qcow2 file, you just import it in virt-manager and it should work.

    –17vw3U7nfkmumR6RSdixDR4BcmRAnVC6r

  • I don’t understand the issue… I’ve installed CentOS-7 on Virtualbox without hassle. it just runs.

    what problem are you trying to solve?

  • In article <20160517130235.GA6498@fcshome.stoneham.ma.us>, Fred Smith wrote:

    That sounds like you mean C7 as a guest. I’ve done that easily too.

    It sounds like he is talking about C7 as a host. I haven’t tried that.

    Cheers Tony

  • I’m running CentOS7 as my host and when I was using Virtualbox, I had my VM’s autostarting for a while. I simply followed this answer [0] on
    “askubuntu.com” and it worked flawlessly. However, I’ve since migrated all my VM’s to KVM once performance on KVM surpassed that of Virtualbox
    (most of my VM’s are Linux servers).

    My $0.02, ak.

    [0]
    https://askubuntu.com/questions/404665/how-to-start-virtual-box-machines-automatically-when-booting/548134

  • thanks for the pointer which of the 9 answers did you use – there are four with [0] points. I
    did see this some time ago and got a variant working under CentOS 6. I
    was hoping to use the new-fangled systemd, partly as a learning exercise, but also to avoid having bespoke config files and methods of starting daemons proliferating which the methods described on askubuntu.com seem to be. rob

  • thanks, the other link helped but there are still errors in all the various instructions one error not noted was the /etc/defaults/virtualbox file it – cannot have spaces!
    it should be

    # virtualbox defaults file VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

    My server has a very well exercised reboot as I have finally got it done Thanks for all the pointers, finally have something that seems to be reliable.