Start VirtualBox virtual machines on boot

Discussions related to using VirtualBox on Linux hosts.
Post Reply
xwisdom
Posts: 6
Joined: 13. Jul 2008, 15:56

Start VirtualBox virtual machines on boot

Post 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
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post 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.
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

Post 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?
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
greenpossum
Volunteer
Posts: 98
Joined: 11. Jul 2008, 08:10

Post 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.
huijaa
Posts: 9
Joined: 14. Aug 2008, 18:52

opensuse

Post by huijaa »

Can it work on OpenSuSE 10.3/11.0 ?
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
greenpossum
Volunteer
Posts: 98
Joined: 11. Jul 2008, 08:10

Re: opensuse

Post 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
huijaa
Posts: 9
Joined: 14. Aug 2008, 18:52

Re: opensuse

Post by huijaa »

script
drone1
Posts: 6
Joined: 14. Aug 2008, 21:46

Post 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.
greenpossum
Volunteer
Posts: 98
Joined: 11. Jul 2008, 08:10

Post 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.
Post Reply