Page 1 of 1

Start VirtualBox virtual machines on boot

Posted: 24. Aug 2008, 15:27
by xwisdom
Hello Everyone,

If you're using linux and you're looking for a way to autmatically start your VMs with Host/NAT interfaces then here's the solution for you:

http://farfewertoes.com/stories/2008-03 ... s-on-boot/

PS. I think this solution should be mentioned in the VirtualBox user manual under the linux section.

__
xwisdom
http://xwisdomhtml.com

Posted: 24. Aug 2008, 21:31
by Sasquatch
And why should it be mentioned in the manual? You can just create a laucher for when you log on and turn on automatic logon. Same deal, different method. I don't see the advantage of it being in the manual. It's a users decision to auto start it, and it works just the same as any other program, like a web browser.

Posted: 24. Aug 2008, 21:35
by TerryE
I agree that this is too detailed for the manual but the reference is of a quality that if we did maintain a Useful links and posts section for each forum, it is usefule enough to find a place.

Posted: 25. Aug 2008, 00:43
by greenpossum
Sasquatch wrote:And why should it be mentioned in the manual? You can just create a laucher for when you log on and turn on automatic logon.
It's probably too detailed for the manual and could be linked to somewhere, but I take issue with the idea that some human has to logon and launch the VM from the launcher. VBox isn't software for running another OS only from the desktop. People do and will want virtualised services that automatically start at boot. Otherwise what was all work on VBoxHeadless for?

Posted: 25. Aug 2008, 11:04
by Sasquatch
greenpossum wrote:
Sasquatch wrote:And why should it be mentioned in the manual? You can just create a laucher for when you log on and turn on automatic logon.
It's probably too detailed for the manual and could be linked to somewhere, but I take issue with the idea that some human has to logon and launch the VM from the launcher. VBox isn't software for running another OS only from the desktop. People do and will want virtualised services that automatically start at boot. Otherwise what was all work on VBoxHeadless for?
Then you can search the forum to find the correct syntax to put in your rc.local file.

Posted: 25. Aug 2008, 13:08
by greenpossum
Sasquatch wrote: Then you can search the forum to find the correct syntax to put in your rc.local file.
What makes you think I don't know how to do it? I wrote an init script for Ubuntu for a VM I developed. I could easily write one for any distro you can name, including ones where rc.local is the wrong place to put it. I'm just commenting on your assumption that everyone should be satisfied to run VBox from the desktop.

opensuse

Posted: 25. Aug 2008, 13:26
by huijaa
Can it work on OpenSuSE 10.3/11.0 ?

Posted: 25. Aug 2008, 13:57
by Sasquatch
greenpossum wrote:
Sasquatch wrote: Then you can search the forum to find the correct syntax to put in your rc.local file.
What makes you think I don't know how to do it? I wrote an init script for Ubuntu for a VM I developed. I could easily write one for any distro you can name, including ones where rc.local is the wrong place to put it. I'm just commenting on your assumption that everyone should be satisfied to run VBox from the desktop.
I didn't mean to put it like that. My main assumption is that VB, by it's manual, expects the user to open it from the Desktop. There are other front ends, but not necessarily for the same purpose.

Re: opensuse

Posted: 25. Aug 2008, 15:00
by greenpossum
huijaa wrote:Can it work on OpenSuSE 10.3/11.0 ?
Do you mean the OP's package or the Ubuntu script I wrote?

If the one I wrote, not without some massaging for which you have to understand how init scripts are constructed. For one thing, OpenSUSE uses startproc/killproc instead of Debian/Ubuntu's start-stop-daemon. For another thing, on OpenSUSE you have to fill in the metadata at the top of the init script so that SuSEconfig will put the script in the correct point in the boot sequence. Also I made no attempt to generalise it for any VM so bits of it are specific to my VM. They are not hard to discover though. But you're welcome to my script, it's part of my writeup on how to run IPCop in a VM here:

http://www.geocities.com/ken_yap_aus/ipcop-in-vbox.html

Re: opensuse

Posted: 25. Aug 2008, 19:09
by huijaa
script

Posted: 26. Aug 2008, 17:40
by drone1
ALL of that is WAY overkill...

Under gentoo,

Simply create an install/setup under a seperate user account w/ VBoxManage (with all necessary settings for NAT, VRDP, shares...) and then add the following to
/etc/conf.d/local.start

(or create a script, add it to and call it instead)
vbox-startup.sh

Code: Select all

su - 'user' VBoxHeadless -s 'VM-name' &
This will start the headless setup w/ VRDP when linux boots.

Here's a simple shutdown script to stop it clean for reboot which I add
/etc/conf.d/local.stop

vbox-shutdown.sh

Code: Select all

#!/bin/bash
#run as user vbox
su - vbox VBoxManage controlvm WinXP acpipowerbutton
#sends shutdown to running VM
proc=1
while [ $proc -ne 0 ]
do
   sleep 5
#waits 5 seconds cause windows is slow that way
   proc=$(ps -fU vbox |grep VBoxHeadless | wc -l)
done
#runs until a 0 count is returned on 'VBoxHeadless' processes
On a sidenote, VBoxHeadless is causing kernel panics on my server if left to run continuosly. Not sure if this is a problem with 'virtualbox-bin' or other, but I've set VBoxHeadless up to only run during the hours of 7am and 6pm, using cron. Next working on a script for nightly VM snapshots.

Posted: 27. Aug 2008, 00:22
by greenpossum
drone1 wrote:ALL of that is WAY overkill...
I think the OP wanted to generalise to start any number of VMs from init scripts.

Incidentally your start and stop scripts are about the same number of lines as a start/stop init script would be. There are a certain amount of commands that have to be issued in any case.