Projekt

Allgemein

Profil

Setup virtualboxhost43 » Historie » Version 1

Jeremias Keihsler, 13.01.2017 12:42

1 1 Jeremias Keihsler
h1. Install Procedure für VirtualBox 4.3
2
3
h2. Requirements
4
5
To install VirtualBox you will need the following:
6
* a installed and supported operating system (e.g. CentOS 6.x)
7
* root-access
8
* a fast internet connection
9
* [[repo_virtualbox|Virtualbox-Repo]]
10
* [[repo_rpmforge|rpmforge]]
11
12
h2. Preliminary Note
13
14
This procedure is based on a documentation supplied by www.proclos.com.
15
16
You may also find additional information at
17
* http://wiki.centos.org/HowTos/Virtualization/VirtualBox/
18
19
h2. Install Virtual Box
20
21
h3. Install DKMS
22
23
Install Dynamic Kernel Module System: (automatically installs appropriate kernel modules per
24
selected version)
25
<pre><code class="bash">
26
yum install dkms
27
</code></pre>
28
29
h3. Install C-Compiler and Kernel-Devel
30
31
Install the GNU C compiler and the kernel development packages using
32
<pre><code class="bash">
33
yum install gcc
34
</code></pre>
35
followed by
36
<pre><code class="bash">
37
yum install kernel-devel
38
</code></pre>
39
Reboot your guest system in order to activate the updates and then proceed as described above.
40
<pre><code class="bash">
41
reboot
42
</code></pre>
43
44
h3. Install VirtualBox
45
46
<pre><code class="bash">
47
yum install VirtualBox-4.3
48
</code></pre>
49
Start virtual box. @GNOME-Menu->Applications->System Tools->Oracle VM VirtualBox@
50
51
h3. Install VirtualBox-Extension (if needed)
52
53
Download the extension from the virtualbox homepage www.virtualbox.org.
54
Add the extension (VirtualBox 4.3.x Oracle VM VirtualBox Extension Pack) using @Preferences->Extensions->Add@. This extension is needed to attach usb devices to the guest machines and to be
55
able to connect to guest machines using WindowsRemote Desktop-Client, which is very handy, if you need graphical access.
56
57
<pre bash VBextpack_update.sh>
58
#!/bin/bash
59
version=$(vboxmanage -v)
60
echo $version
61
var1=$(echo $version | cut -d 'r' -f 1)
62
echo $var1
63
var2=$(echo $version | cut -d 'r' -f 2)
64
echo $var2
65
file="Oracle_VM_VirtualBox_Extension_Pack-$var1-$var2.vbox-extpack"
66
echo $file
67
wget http://download.virtualbox.org/virtualbox/$var1/$file -O /tmp/$file
68
VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"
69
VBoxManage extpack install /tmp/$file --replace
70
</pre>
71
72
h2. Setup vboxusers
73
74
The Linux installers create the system user group vboxusers during installation. Any system user who is going to use USB devices from VirtualBox guests must be a member of that group. A user can be made a member of the group vboxusers through the GUI user/group management or at the command line with
75
76
<pre><code class="bash">
77
usermod -a -G vboxusers username
78
</code></pre>
79
80
Note that adding an active user to that group will require that user to log out and back in again. This should be done manually after successful installation of the package.
81
82
h2. Automatic Start/Stop of virtual machines
83
84
To automatically run the guest machines in headless mode on host machine startup, do the following((A new feature of VirtualBox 4.2 is a supplied init-script to automatically start/stop virtual-machines. This I've not tested yet. The old 4.1 way is still working fine. So this section remains as 4.1 until something better is tested.
85
)):
86
87
add the list of names of the virtual machines that should be started / stopped automatically in following files:
88
@/etc/virtualbox/machines_enabled_start@ and @/etc/virtualbox/machines_enabled_stop@
89
90
Each virtual machine name has to in a seperate line. You can create and fill the files by the use of @vim@ or any other texteditor.
91
<pre><code class="bash">
92
cd /etc
93
mkdir virtualbox
94
vim /etc/virtualbox/machines_enabled_start
95
</code></pre>
96
<pre><code class="bash">
97
vim /etc/virtualbox/machines_enabled_stop
98
</code></pre>
99
100
Afterwards you can check the file-content by
101
<pre><code class="bash">
102
cat /etc/virtualbox/machines_enabled_start
103
</code></pre>
104
the content should look like:
105
<pre><code class="bash">
106
firewall-pfsense
107
clusterOne
108
clusterTwo
109
postgresql-solo
110
windows7-janus
111
</code></pre>
112
As the machines are started and stopped in the same order as in the files being listed you maybe want to stop the machines in reverse order.
113
<pre><code class="bash">
114
cat /etc/virtualbox/machines_enabled_stop
115
</code></pre>
116
the content could look like:
117
<pre><code class="bash">
118
windows7-janus
119
postgresql-solo
120
clusterTwo
121
clusterOne
122
firewall-pfsense
123
</code></pre>
124
125
Also create a file @/etc/init.d/vboxcontrol@ with following content:
126
127
Don't forget to set the correct user @VM_USER@
128
<pre>
129
#! /bin/sh
130
# vboxcontrol   Startup script for VirtualBox Virtual Machines
131
#
132
# chkconfig: 345 98 02
133
# description: Manages VirtualBox VMs
134
# processname: vboxcontrol
135
#
136
# pidfile: /var/run/vboxcontrol/vboxcontrol.pid
137
#
138
### BEGIN INIT INFO
139
#
140
### END INIT INFO
141
#
142
# Version 20110509 by Jeremias Keihsler based on:
143
# Version 20090301 by Kevin Swanson <kswan.info> based on:
144
# Version 2008051100 by Jochem Kossen <jochem.kossen@gmail.com>
145
# http://farfewertoes.com
146
#
147
# Released in the public domain
148
#
149
# This file came with a README file containing the instructions on how
150
# to use this script.
151
#
152
153
# Source function library.
154
if [ -f /etc/init.d/functions ] ; then
155
. /etc/init.d/functions
156
elif [ -f /etc/rc.d/init.d/functions ] ; then
157
. /etc/rc.d/init.d/functions
158
else
159
exit 1
160
fi
161
162
################################################################################
163
# INITIAL CONFIGURATION
164
VBOXDIR="/etc/virtualbox"
165
VM_USER="OMB"
166
USE_NAT="no"
167
168
export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/sbin:/sbin"
169
170
if [ -f $VBOXDIR/config ]; then
171
. $VBOXDIR/config
172
fi
173
174
SU="su $VM_USER -c"
175
VBOXMANAGE="VBoxManage -nologo"
176
177
################################################################################
178
# FUNCTIONS
179
180
# Determine if USE_NAT is set to "yes"
181
use_nat() {
182
if [ "$USE_NAT" = "yes" ]; then
183
return `true`
184
else
185
return `false`
186
fi
187
}
188
189
log_failure_msg() {
190
echo $1
191
}
192
193
log_action_msg() {
194
echo $1
195
}
196
197
# Check for running machines every few seconds; return when all machines are
198
# down
199
wait_for_closing_machines() {
200
RUNNING_MACHINES=`$SU "$VBOXMANAGE list runningvms" | wc -l`
201
if [ $RUNNING_MACHINES != 0 ]; then
202
sleep 2
203
wait_for_closing_machines
204
fi
205
}
206
207
################################################################################
208
# RUN
209
case "$1" in
210
start)
211
if [ -f /etc/virtualbox/machines_enabled_start ]; then
212
213
cat /etc/virtualbox/machines_enabled_start | while read VM; do
214
log_action_msg "Starting VM: $VM ..."
215
$SU "$VBOXMANAGE startvm "$VM" --type headless"
216
sleep 20
217
RETVAL=$?
218
done
219
touch /var/lock/subsys/vboxcontrol
220
fi
221
;;
222
stop)
223
# NOTE: this stops all running VM's. Not just the ones listed in the
224
# config
225
cat /etc/virtualbox/machines_enabled_stop  | while read VM; do
226
log_action_msg "Shutting down VM: $VM ..."
227
$SU "$VBOXMANAGE controlvm "$VM" acpipowerbutton"
228
sleep 10
229
done
230
rm -f /var/lock/subsys/vboxcontrol
231
wait_for_closing_machines
232
;;
233
export)
234
# NOTE: this stops and exports the listed VMs
235
cat /etc/virtualbox/machines_enabled_export  | while read VM; do
236
  log_action_msg "Shutting down VM: $VM ..."
237
  $SU "$VBOXMANAGE controlvm "$VM" acpipowerbutton"
238
  /bin/echo -en "\a" > /dev/console
239
  sleep 10
240
done
241
wait_for_closing_machines
242
JKE_DATE=$(date +%F)
243
cat /etc/virtualbox/machines_enabled_export  | while read VM; do
244
  log_action_msg "Exporting VM: $VM ..."
245
  $SU "$VBOXMANAGE export "$VM" -o "$VM"_"$JKE_DATE"."ova" --manifest --vsys 0 --version $JKE_DATE"
246
done
247
rm -f /var/lock/subsys/vboxcontrol
248
;;
249
start-vm)
250
log_action_msg "Starting VM: $2 ..."
251
$SU "$VBOXMANAGE startvm "$2" --type headless"
252
;;
253
stop-vm)
254
log_action_msg "Stopping VM: $2 ..."
255
$SU "$VBOXMANAGE controlvm "$2" acpipowerbutton"
256
;;
257
poweroff-vm)
258
log_action_msg "Powering off VM: $2 ..."
259
$SU "$VBOXMANAGE controlvm "$2" poweroff"
260
;;
261
export-vm)
262
# NOTE: this exports the given VM
263
log_action_msg "Exporting VM: $2 ..."
264
JKE_DATE=$(date +%F)
265
$SU "$VBOXMANAGE export "$2" -o "$2"_"$JKE_DATE"."ova" --manifest --vsys 0 --version $JKE_DATE"
266
;;
267
status)
268
echo "The following virtual machines are currently running:"
269
$SU "$VBOXMANAGE list runningvms" | while read VM; do
270
echo -n "$VM ("
271
echo -n `$SU "VBoxManage showvminfo ${VM%% *}|grep Name:|sed -e 's/^Name:s*//g'"`
272
echo ')'
273
done
274
;;
275
276
*)
277
echo "Usage: $0 {start|stop|status|export|start-vm <VM
278
name>|stop-vm <VM name>|poweroff-vm <VM name>}|export-vm <VMname>"
279
exit 3
280
esac
281
282
exit 0
283
</pre>
284
285
To make the file executeable do
286
<pre><code class="bash">
287
chmod +x /etc/init.d/vboxcontrol
288
</code></pre>
289
Add vboxcontrol as service:
290
<pre><code class="bash">
291
cd /etc/init.d
292
chkconfig --add vboxcontrol
293
</code></pre>
294
Manually start the service
295
<pre><code class="bash">
296
service vboxcontrol start
297
</code></pre>
298
you can check the runlevels by
299
<pre><code class="bash">
300
chkconfig --list vboxcontrol
301
</code></pre>
302
you should get an output like:
303
<pre><code class="bash">
304
vboxcontrol     0:off   1:off   2:off   3:on   4:on   5:on   6:off
305
</code></pre>
306
307
With this setup, guest machines are also automatically shutdown cleanly in a host shutdown
308
process. The shell-script @vboxcontrol@ processes the file @machines_enabled_stop@. The first machines is sent a ACPI-Poweroff-Signal, after 10 seconds the second machine and so on. After the last machine have got the ACPI-Poweroff-Signal the script waits until all machines have reached power-off-status. By doing so a crashed or hanging virtual machine will prevent a shutdown of the host-system.
309
310
At boot-time each virtual machine being listed in the file @machines_enabled_start@ is being started according to the order within the file. The time gap between each machine is 20 seconds.
311
312
h2. Problem