Unable to manage a VM if started from rc.local

Discussions related to using VirtualBox on Linux hosts.
Post Reply
proci
Posts: 3
Joined: 24. Jul 2008, 16:44

Unable to manage a VM if started from rc.local

Post by proci »

Hi,
I start a VM from rc.local using /usr/bin/VBoxManage startvm WXP -type vrdp >/home/vboxstart.log. After the VM startup is completed I'm unable to verify if the VM is running or not using VBoxManage list runningvms (I'm logged as root)...
If the VM is started from the console using the same command, I'm able to view the VM status. Why?
(Fedora Core 9, VBox 1.6.2)
bundabrg
Posts: 47
Joined: 22. Feb 2008, 04:01

Post by bundabrg »

I've noticed this as well. When I run VirtualBox using VBoxHeadless or VBoxSDL, it does not show as running using "VBoxManage list runningvms".

I've not investigated it enough yet.

- Brendan
brandonheat
Posts: 10
Joined: 26. Jul 2008, 14:13

Post by brandonheat »

try run the VBoxManage in rc.local as below
  • su - root -c " /usr/bin/VBoxManage startvm WXP -type vrdp >/home/vboxstart.log"
You have to specify which user (above is root) to start the because it look for ".VirtualBox" at the home directory. --brandon
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post by TerryE »

Alternatively create a startVMs script which you can su -<user> -c and this can handle setting VBOX_USER_HOME appending to log files etc.

Also note that in general leaving the RDP port to default is not a good idea, since this means that you can only start one VM per host.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
proci
Posts: 3
Joined: 24. Jul 2008, 16:44

Post by proci »

Thanks Brandon: IT WORKS!
Mesmerism
Posts: 1
Joined: 15. Aug 2008, 20:53

Post by Mesmerism »

Is there any good solution to this problem other than running everything as root?

I have tried "VBOX_USER_HOME=/usershome/.VirtualBox/ VBoxManage list runningvms" but that doesnt seem to help if the users doesnt match. I think it has something to do with the user-named lock files created in /tmp, eg .vbox-user-ipc

This kind of defeats the purpose of "rc.vboxdrv stop" if root cant manipulate user vms. It isnt possible to send acpipowerbutton signals to the vms before the system shuts down.

Kind of a serious flaw I think.

---------------

Actually on second look while writing this post.. it might be related to the mysterious loss of state I keep getting, eg:
$ VBoxManage list vms
..
State: powered off (since ...
- or -
State: aborted

when the vm is running just fine (Im logged into it with windows remote desktop).

The VM is started with "VBOX_USER_HOME=/usershome/.VirtualBox/ VBOX_LOG_DIST=nofile DISPLAY=asdf nohup VBoxHeadless -s testXP &"

This is ver 1.6.4 on Slackware 10.2

thanks
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post by TerryE »

As long as you get your ownership and protections correct (including umasks) then you can use sudo to start the VM in any account and group. You just need to remember that you need to export the correct context before starting up any VBoxManage commands to manage this. You may want to wrap this all up in a shell script. You can also allow unprivileged accounts to do this if you you set up sudoers correctly. It's just a matter of getting all the details correct.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
greenpossum
Volunteer
Posts: 98
Joined: 11. Jul 2008, 08:10

Re: Unable to manage a VM if started from rc.local

Post by greenpossum »

I don't know if this is your problem but I encountered something similar when starting a VM from an init script using Debian/Ubuntu's start-stop-server (probably the same with startproc in RPM based distros). The problem is that even though you may set the uid of the VBoxHeadless process right, it cannot determine the username. By trial and error I found that VBoxHeadless looks at $LOGNAME to get the username, so if you set this before the call, IPC will work correctly. IPC is needed for some VBoxManage calls.

Have a look in /tmp. If you see a socket with the name /tmp/.vbox--ipc, then this is the problem. The TRAC ticket is:

http://www.virtualbox.org/ticket/1890
Post Reply