LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Virtualbox: Howto start a new machine on boot and then stop it on halt (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/virtualbox-howto-start-a-new-machine-on-boot-and-then-stop-it-on-halt-849449/)

cabrilo 12-10-2010 03:46 AM

Virtualbox: Howto start a new machine on boot and then stop it on halt
 
Hello all,

As an environmentally conscious programmer, I decided to retire my old development box and virtualize it instead. So now, I have a GUEST Debian instance running in VirtualBox on top of my linux HOST. I find the setup much better - saves energy, and it's easier to back up and administer.

So, I would like to do the following: I want my GUEST to start when the host boots up. This is not an issue. I will just VBoxHeadless -startvm Debian somewhere on boot.

However, I am a bit fuzzy on how to best go about shutting the GUEST down when the HOST halts. The problem here is that the script that does this must be blocking - i.e. HOST must not halt before the GUEST does shuts down.

Now, I'm not too familiar with writing init scripts, especially upstart scripts that my distribution now uses. I suppose they are blocking, but unless I have to deal with them, I'd rather take a less manual labor approach.

How would I go about this the easiest way? Any suggestions? Any ready-made scripts?

Thanks

catkin 12-10-2010 12:40 PM

My knowledge is of Slackware not ubuntu but nobody else has answered in more than 24 hours ...

VirtualBox installs a boot/shutdown script that has the VM shutdown capability you ask for. On Slackware it is rc.vboxdrv so it is probably vboxdrv within the upstart directories. rc.vboxdrv can be configured using /etc/default/virtualbox. This usage not described in the VirtualBox 3.2.8 User Manual but is mentioned in a comment in the rc.vboxdrv script. Unfortunately it does not work for me as described in this VirtualBox forum thread. It should be possible to script around this problem but it makes sense to explore the mechanism provided by VirtualBox first.

cabrilo 12-10-2010 12:57 PM

Quote:

Originally Posted by catkin (Post 4187253)
My knowledge is of Slackware not ubuntu but nobody else has answered in more than 24 hours ...

VirtualBox installs a boot/shutdown script that has the VM shutdown capability you ask for. On Slackware it is rc.vboxdrv so it is probably vboxdrv within the upstart directories. rc.vboxdrv can be configured using /etc/default/virtualbox. This usage not described in the VirtualBox 3.2.8 User Manual but is mentioned in a comment in the rc.vboxdrv script. Unfortunately it does not work for me as described in this VirtualBox forum thread. It should be possible to script around this problem but it makes sense to explore the mechanism provided by VirtualBox first.

Thanks! That seems to be the proper way to do it.

Thanks again, very helpful.

catkin 12-10-2010 01:09 PM

Quote:

Originally Posted by cabrilo (Post 4187264)
Thanks! That seems to be the proper way to do it.

Thanks again, very helpful.

Well, it will be helpful if it works! Please let us know how you get on.

cabrilo 12-10-2010 01:36 PM

Quote:

Originally Posted by catkin (Post 4187274)
Well, it will be helpful if it works! Please let us know how you get on.

It works. However, a bit of funny business which may be related to your problem:

If there is a virtual machine running, it works perfectly fine.

However, when there are no virtual machines running, sometimes (and only sometimes!) it fails with this:

Code:

ERROR: failed to create the VirtualBox object!
ERROR: code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available)
Most likely, the VirtualBox COM server is not running or failed to start.
Wrong owner (1000) of '/tmp/.vbox-cabrilo-ipc'.

I have no idea what exactly causes it - if I see a better pattern, I'll let you know.

catkin 12-10-2010 01:42 PM

Quote:

Originally Posted by cabrilo (Post 4187300)
I have no idea what exactly causes it - if I see a better pattern, I'll let you know.

Thanks for the update. Similar symptoms. AFAIK that message (actually I get many, followed by a 30 second sleep) happens when a VM has been started and shutdown before host shutdown. If a solution is not forthcoming I'll have a go at scripting a workaround.

catkin 12-14-2010 05:20 AM

Reported as a defect at http://www.virtualbox.org/ticket/7844


All times are GMT -5. The time now is 10:52 AM.