[Solved] Starting VirtualBox from batch failing

Discussions related to using VirtualBox on Linux hosts.
Post Reply
MarkFoley
Posts: 150
Joined: 19. Aug 2016, 03:20

[Solved] Starting VirtualBox from batch failing

Post by MarkFoley »

I have a backup job that shuts down the VM, does a backup of all VirtualBox files, then restarts the VM. Unfortunately, the restart does not work. The job is run from cron as root and is:

Code: Select all

# su -l mfoley --command "/usr/bin/VBoxManage startvm WIN7VM"
VBoxManage: error: The virtual machine 'WIN7VM' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
Waiting for VM "WIN7VM" to power on...
If I run this command as root from the command line, it works. What's going on?
Last edited by socratis on 21. May 2018, 00:03, edited 1 time in total.
Reason: Marked as [Solved].
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Starting VirtualBox from batch failing

Post by socratis »

"signal 6" is a libc memory allocation error AFAIK.

But I have a more "basic" question. When you run that command (why as root?) someone is logged in, there is a window manager responsible for actually drawing the VM. When you run that cron job, where's that VM going to be displayed? Is anyone logged in?

How about if you try either of the following commands:
  • su -l mfoley --command "VBoxManage startvm WIN7VM --type headless"
    su -l mfoley --command "VBoxHeadless --startvm WIN7VM"
Also, from ch. 2.3.5 Starting VirtualBox on Linux:
All VirtualBox applications (VirtualBox, VBoxSDL, VBoxManage and VBoxHeadless) require the VirtualBox directory to be in the library path:
  • LD_LIBRARY_PATH=. ./VBoxManage showvminfo "Windows XP"
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
MarkFoley
Posts: 150
Joined: 19. Aug 2016, 03:20

Re: Starting VirtualBox from batch failing

Post by MarkFoley »

socratis wrote:"signal 6" is a libc memory allocation error AFAIK.

But I have a more "basic" question. When you run that command (why as root?) someone is logged in, there is a window manager responsible for actually drawing the VM. When you run that cron job, where's that VM going to be displayed? Is anyone logged in?
"Why root", because root is doing a system-wide backup, which includes backing up the VM. It first shuts down the VM via 'su mfoley --command "/usr/bin/VBoxManage controlvm WIN7VM savestate"'. Note that the script actually runs through the list of running VMs (in case there is more than one -- there isn't really, but just in case) shutting them down in the save state and logging which ones were shut down for later. After the backup is complted, the root cron job attempts to restart the VMs based on the log of ones shut down.

Yes, there is a user logged in on Linux. I am using KDE and if the user running the VM logs out it shuts down the VM, in which case the root cron job won't find a VM to shutdown and hence won't attempt to start it. I am expecting the VM to be displayed on that logged in user's screen.

When, as that logged in normal user, I 'su' to root and run the startvm, it fires up just fine. Since I'm doing that as root, why is it any different that root doing that in a cron script? This particular restart VM error is consistent with 3 VMs on 3 different Linux workstations.
How about if you try either of the following commands:
  • su -l mfoley --command "VBoxManage startvm WIN7VM --type headless"
    su -l mfoley --command "VBoxHeadless --startvm WIN7VM"
Well, I don't want it to be headless. The idea is to backup production workstations and have the user none the wiser the next morning, especially if lots of windows with unsaved files are left open at end of day, which is typical!
Also, from ch. 2.3.5 Starting VirtualBox on Linux:
All VirtualBox applications (VirtualBox, VBoxSDL, VBoxManage and VBoxHeadless) require the VirtualBox directory to be in the library path:
  • LD_LIBRARY_PATH=. ./VBoxManage showvminfo "Windows XP"
OK, this gives me a clue! I was wondering if something needed to be set in the environment. Unfortunately, LD_LIBRARY_PATH is not set even with an interactive logon, but I'll try listing the ENV in both interactive and cron modes and see if there is some difference. (to be honest, I'm not sure what that env set command does. When I run 'LD_LIBRARY_PATH=. VBoxManage showvminfo WIN7VM' LD_LIBRARY_PATH is not set to anything)
Martin
Volunteer
Posts: 2561
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Starting VirtualBox from batch failing

Post by Martin »

MarkFoley wrote:When, as that logged in normal user, I 'su' to root and run the startvm, it fires up just fine. Since I'm doing that as root, why is it any different that root doing that in a cron script?
If I remember correctly the runtime environment of cron doesn't have input/output access (and no way to access the gui).
MarkFoley
Posts: 150
Joined: 19. Aug 2016, 03:20

Re: Starting VirtualBox from batch failing

Post by MarkFoley »

I just tried this again using the PATH setting of the login user in the cron script. It didn't make any difference, same error.
Martin wrote:If I remember correctly the runtime environment of cron doesn't have input/output access (and no way to access the gui).
To test that idea, I logged into the host from a remote computer and su'd to root. I.e. I did not su from the local user to whom the VM belongs and who does have a KDE GUI session. The result was the same error, as if run from the cron job.

So, after the local user, with a KDE/GUI session, opens a terminal window, su's to root and runs 'su -l userId --command "/usr/bin/VBoxManage startvm vmname" it will work, but not if run from root with no GUI session. This seems to back your theory.

Is there therefore no way for a root cron job to start a VM on behalf of a user who DOES have a GUI session?
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Starting VirtualBox from batch failing

Post by socratis »

MarkFoley wrote:Is there therefore no way for a root cron job to start a VM on behalf of a user who DOES have a GUI session?
It would be best if that question was asked in a Linux related forum, you'll have better chances. Not that no one will know here, but the expertise of this forum are mostly VirtualBox based...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
andyp73
Volunteer
Posts: 1631
Joined: 25. May 2010, 23:48
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Assorted Linux, Windows Server 2012, DOS, Windows 10, BIOS/UEFI emulation

Re: Starting VirtualBox from batch failing

Post by andyp73 »

MarkFoley wrote:Is there therefore no way for a root cron job to start a VM on behalf of a user who DOES have a GUI session?
Thinking aloud...

Can you not set up two per user cron jobs one to suspend the VM and the other to restart it? That then gives you a time window in which your root job can do the backup. You might also need to use .bash_login and .bash_logout to create lock files which you can check for the presence (or lack) of in order to synchronise things.

-Andy.
My crystal ball is currently broken. If you want assistance you are going to have to give me all of the necessary information.
Please don't ask me to do your homework for you, I have more than enough of my own things to do.
MarkFoley
Posts: 150
Joined: 19. Aug 2016, 03:20

Re: Starting VirtualBox from batch failing

Post by MarkFoley »

andyp73 wrote:Thinking aloud...

Can you not set up two per user cron jobs one to suspend the VM and the other to restart it? That then gives you a time window in which your root job can do the backup. You might also need to use .bash_login and .bash_logout to create lock files which you can check for the presence (or lack) of in order to synchronise things.
I did try that. I created a cron job for the same KDE/GUI user (not root) who was logged into the desktop the whole time. It failed with the same error:

Code: Select all

VBoxManage: error: The virtual machine 'WIN7VM' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
I will do as socratis suggested and post this question on Linuxquestions.org. In the meantime, if anyone on this forum knows what might cause an "NS_FAILURE component MachineWrap interface IMachine". A signal 6 is
A process dying with this signal is usually due to it calling the abort(3) function. That generally indicates that the process itself has found that some essential pre-requisite for correct function is not available and voluntarily killing itself, ...
These are errors generated by VBoxManage.
Martin
Volunteer
Posts: 2561
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Starting VirtualBox from batch failing

Post by Martin »

Unfortunately "code NS_ERROR_FAILURE (0x80004005)" is just a generic "something has gone wrong" error message.
MarkFoley
Posts: 150
Joined: 19. Aug 2016, 03:20

Re: Starting VirtualBox from batch failing

Post by MarkFoley »

Found the answer:

Code: Select all

DISPLAY=:0 backupVM.sh
where backupVM.sh is the backup script containing the 'VBoxManage startvm'. I've also tried this in the crontab:

Code: Select all

30 1 1,15 * * /bin/bash -c "DISPLAY=:0 $HOME/backupVM >> $HOME/backupVM.log 2>&1"
and I've tried it as both the VM owner/user and as root. It works both ways. Now I can back up users' VMs after hours and they'll be non-the-wiser when they come in the next day!
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Starting VirtualBox from batch failing

Post by socratis »

The DISPLAY! Makes sense!
Glad you got it going and thanks for the feedback!
Marking as [Solved].
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply