Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Apr 2011 12:15:37 -0700
From:      Tobias Oberstein <tobias.oberstein@tavendo.de>
To:        "freebsd-emulation@freebsd.org" <freebsd-emulation@freebsd.org>
Subject:   rc.d script for running multiple VirtualBox VMs from /etc/rc.conf
Message-ID:  <634914A010D0B943A035D226786325D422B76F91CA@EXVMBX020-12.exch020.serverdata.net>

next in thread | raw e-mail | index | archive | help
--_002_634914A010D0B943A035D226786325D422B76F91CAEXVMBX02012ex_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

I wanted to configure multiple VirtualBox VMs to startup automatically at b=
oot time and generally be a nice citizen to the FreeBSD way of starting up =
stuff.

Using that rc.d script (see attached) you can configure starting up multipl=
e VirtualBox VMs from /etc/rc.conf:

## VirtualBox VMs
vboxvm_enable=3D"YES"
vboxvm_machines=3D"vm1 vm2"

## VM1
vboxvm_vm1_enable=3D"YES"
vboxvm_vm1_name=3D"vm1"
vboxvm_vm1_user=3D"vbox_vm1"
vboxvm_vm1_log=3D"vboxvm.log"
vboxvm_vm1_vncport=3D"5901"
vboxvm_vm1_vncpassword=3D"secret1"

## VM2
vboxvm_vm2_enable=3D"YES"
vboxvm_vm2_name=3D"vm2"
vboxvm_vm2_user=3D"vbox_vm2"
vboxvm_vm2_log=3D"vboxvm.log"
vboxvm_vm2_vncport=3D"5902"
vboxvm_vm2_vncpassword=3D"secret2"

=3D=3D

The script must be put to

/usr/local/etc/rc.d/vboxvm

and understands three commands: start, stop and status.

You can use it on all VMs configured (and enabled)

$ /usr/local/etc/rc.d/vboxvm status
VBox machine 'vm1' is running.
VBox machine 'vm2' is running.

or on a specific VM

$ /usr/local/etc/rc.d/vboxvm stop vm1

=3D=3D

The parameters:

vboxvm_<VM Name>_enable
=3D> mandatory : enable/disable the VM

vboxvm_<VM Name>_name
=3D> mandatory : VirtualBox name of the VM

vboxvm_<VM Name>_user
=3D> mandatory : the Unix user under which the VM will be run (using VBoxHe=
adless)

vboxvm_<VM Name>_log
=3D> optional : log file when VBoxHeadless runs the VM

vboxvm_<VM Name>_vncport
=3D> optional : when given, VBoxHeadless with active VNC server embedded

vboxvm_<VM Name>_vncpassword
=3D> optional : when VNC is active, a password

=3D=3D

bugs/limits:

1) the restart/rcvar commands do now work
2) when the system shuts down, it doesnt wait for "stop" to finish graceful=
 shutdown of VMs

I'm new to writing rc.d on FreeBSD, so if someone knows how to fix those, I=
'd be interested.

=3D=3D

credits: the script skeleton was shamelessly stolen from /usr/local/etc/rc.=
d/apache22 ;)

cheers,
Tobias


--_002_634914A010D0B943A035D226786325D422B76F91CAEXVMBX02012ex_
Content-Type: text/plain; name="vboxvm.txt"
Content-Description: vboxvm.txt
Content-Disposition: attachment; filename="vboxvm.txt"; size=2999;
	creation-date="Tue, 12 Apr 2011 11:51:34 GMT";
	modification-date="Tue, 12 Apr 2011 11:51:34 GMT"
Content-Transfer-Encoding: base64

IyEvYmluL3NoCgojIFBST1ZJREU6IHZib3h2bQojIFJFUVVJUkU6IExPR0lOCiMgS0VZV09SRDog
c2h1dGRvd24KCi4gL2V0Yy9yYy5zdWJyCgpuYW1lPSJ2Ym94dm0iCnJjdmFyPWBzZXRfcmN2YXJg
Cgpsb2FkX3JjX2NvbmZpZyAkbmFtZQoKaWYgWyAtbiAiJDIiIF07IHRoZW4KCW1hY2hpbmU9IiQy
IgoJaWYgWyAieCR7dmJveHZtX21hY2hpbmVzfSIgIT0gIngiIF07IHRoZW4KCQlldmFsIHZib3h2
bV9uYW1lPSJcJHt2Ym94dm1fJHttYWNoaW5lfV9uYW1lOi19IgoJCWlmIFsgIngke3Zib3h2bV9u
YW1lfSIgPSAieCIgXTsgdGhlbgoJCQllY2hvICJZb3UgbXVzdCBkZWZpbmUgYSBWTSBuYW1lICh2
Ym94dm1fJHttYWNoaW5lfV9uYW1lKSIKCQkJZXhpdCAxCgkJZmkKCQlldmFsIHZib3h2bV91c2Vy
PSJcJHt2Ym94dm1fJHttYWNoaW5lfV91c2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C1uZSAiMCIgXTsgdGhlbgogICAgICAg
ZWNobyAiVkJveCBtYWNoaW5lICcke3Zib3h2bV9uYW1lfScgaXMgcnVubmluZy4iCiAgICBlbHNl
CiAgICAgICBlY2hvICJWQm94IG1hY2hpbmUgJyR7dmJveHZtX25hbWV9JyBpcyBwb3dlcmVkIGRv
d24uIgogICAgZmkKfQoKcnVuX3JjX2NvbW1hbmQgIiQxIgo=

--_002_634914A010D0B943A035D226786325D422B76F91CAEXVMBX02012ex_--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?634914A010D0B943A035D226786325D422B76F91CA>