Projekt

Allgemein

Profil

Setup virtualboxhost60 » Historie » Version 1

Jeremias Keihsler, 25.12.2018 23:16

1 1 Jeremias Keihsler
h1. Install Procedure for VirtualBox 6.0
2
3
h2. Requirements
4
5
To install VirtualBox you will need the following:
6
* a installed and supported operating system (e.g. CentOS 7.x)
7
* root-access
8
* a fast internet connection
9
* [[repo_epel|EPEL]]
10
* [[repo_virtualbox|VirtualBox - Repo]]
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
a possible solution to get the autostart-service up and running finally  is found here:
20
http://nathangiesbrecht.com/centos-7-virtualbox-vboxautostart-service-setup
21
22
h2. Install Virtual Box
23
24
h3. Install DKMS
25
26
Install Dynamic Kernel Module System: (automatically installs appropriate kernel modules per
27
selected version)
28
<pre><code class="bash">
29
yum install dkms
30
</code></pre>
31
32
h3. Install C-Compiler and Kernel-Devel
33
34
Install the GNU C compiler and the kernel development packages using
35
<pre><code class="bash">
36
yum install gcc
37
</code></pre>
38
followed by
39
<pre><code class="bash">
40
yum install kernel-devel
41
</code></pre>
42
Reboot your guest system in order to activate the updates and then proceed as described above.
43
<pre><code class="bash">
44
reboot
45
</code></pre>
46
47
h3. Install VirtualBox
48
49
<pre><code class="bash">
50
yum install VirtualBox-6.0
51
</code></pre>
52
Start virtual box. @GNOME-Menu->Applications->System Tools->Oracle VM VirtualBox@
53
54
h2. Install VirtualBox-Extension
55
56
Download the extension from the virtualbox homepage www.virtualbox.org.
57
Add the extension (VirtualBox 6.0.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
58
able to connect to guest machines using WindowsRemote Desktop-Client, which is very handy, if you need graphical access.
59
60
@VBextpack_update.sh@
61
<pre>
62
#!/bin/bash
63
version=$(vboxmanage -v)
64
echo $version
65
var1=$(echo $version | cut -d 'r' -f 1)
66
echo $var1
67
var2=$(echo $version | cut -d 'r' -f 2)
68
echo $var2
69
file="Oracle_VM_VirtualBox_Extension_Pack-$var1-$var2.vbox-extpack"
70
echo $file
71
wget http://download.virtualbox.org/virtualbox/$var1/$file -O /tmp/$file
72
VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"
73
VBoxManage extpack install /tmp/$file --replace
74
</pre>
75
76
h2. Setup vboxusers
77
78
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
79
80
<pre><code class="bash">
81
usermod -a -G vboxusers username
82
</code></pre>
83
84
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.
85
86
h2. Automatic Start/Stop of virtual machines systemd-style
87
88
89
this is taken from http://www.ericerfanian.com/automatically-starting-virtualbox-vms-on-archlinux-using-systemd/
90
91
Add a file called @vboxvmservice@.service@ in @/etc/systemd/system/.@
92
93
<pre vboxvmservice@.service>
94
[Unit]
95
Description=VBox Virtual Machine %i Service
96
Requires=systemd-modules-load.service
97
After=systemd-modules-load.service
98
99
[Service]
100
User=user
101
Group=vboxusers
102
ExecStart=/usr/bin/VBoxHeadless -s %i
103
ExecStop=/usr/bin/VBoxManage controlvm %i savestate
104
105
[Install]
106
WantedBy=multi-user.target
107
</pre>
108
109
Replace the user after user= with the username you want to run the VMs. Make sure that the user is in the vboxusers group. If you need to delay the start of the VMs until after your network is started or a network share is mounted, locate the service you want to wait for using ‘systemctl’ and then substitute the service, mount, or network behind ‘After=’.
110
111
You can also replace ‘savestate’ in ‘ExecStop=’ with ‘poweroff’ or ‘acpipowerbutton’ to hard-stop the VM, or ask for a clean shut-down, respectively.
112
113
To enable one or more VMs at boot, enter:
114
115
<pre><code class="bash">
116
systemctl enable vboxvmservice@vm_name.service
117
</code></pre>
118
h2. 5 Automatic Start/Stop of virtual machines SystemV-style
119
120
121
As an alternative to the following solution, someone might find https://sourceforge.net/projects/vboxtool/ interesting to investigate.
122
123
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.
124
)):
125
126
add the list of names of the virtual machines that should be started / stopped automatically in following files:
127
@/etc/virtualbox/machines_enabled_start@ and @/etc/virtualbox/machines_enabled_stop@
128
129
Each virtual machine name has to in a separate line. You can create and fill the files by the use of @vim@ or any other text-editor.
130
<pre><code class="bash">
131
cd /etc
132
mkdir virtualbox
133
vim /etc/virtualbox/machines_enabled_start
134
</code></pre>
135
<pre><code class="bash">
136
vim /etc/virtualbox/machines_enabled_stop
137
</code></pre>
138
139
Afterwards you can check the file-content by
140
<pre><code class="bash">
141
cat /etc/virtualbox/machines_enabled_start
142
</code></pre>
143
the content should look like:
144
<pre><code class="bash">
145
firewall-pfsense
146
clusterOne
147
clusterTwo
148
postgresql-solo
149
windows7-janus
150
</code></pre>
151
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.
152
<pre><code class="bash">
153
cat /etc/virtualbox/machines_enabled_stop
154
</code></pre>
155
the content could look like:
156
<pre><code class="bash">
157
windows7-janus
158
postgresql-solo
159
clusterTwo
160
clusterOne
161
firewall-pfsense
162
</code></pre>
163
164
Also create a file @/etc/init.d/vboxcontrol@ with following content:
165
166
Don't forget to set the correct user @VM_USER@
167
<pre>
168
#! /bin/sh
169
# vboxcontrol   Startup script for VirtualBox Virtual Machines
170
#
171
# chkconfig: 345 98 02
172
# description: Manages VirtualBox VMs
173
# processname: vboxcontrol
174
#
175
# pidfile: /var/run/vboxcontrol/vboxcontrol.pid
176
#
177
### BEGIN INIT INFO
178
#
179
### END INIT INFO
180
#
181
# Version 20110509 by Jeremias Keihsler based on:
182
# Version 20090301 by Kevin Swanson <kswan.info> based on:
183
# Version 2008051100 by Jochem Kossen <jochem.kossen@gmail.com>
184
# http://farfewertoes.com
185
#
186
# Released in the public domain
187
#
188
# This file came with a README file containing the instructions on how
189
# to use this script.
190
#
191
192
# Source function library.
193
if [ -f /etc/init.d/functions ] ; then
194
. /etc/init.d/functions
195
elif [ -f /etc/rc.d/init.d/functions ] ; then
196
. /etc/rc.d/init.d/functions
197
else
198
exit 1
199
fi
200
201
################################################################################
202
# INITIAL CONFIGURATION
203
VBOXDIR="/etc/virtualbox"
204
VM_USER="OMB"
205
USE_NAT="no"
206
207
export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/sbin:/sbin"
208
209
if [ -f $VBOXDIR/config ]; then
210
. $VBOXDIR/config
211
fi
212
213
SU="su $VM_USER -c"
214
VBOXMANAGE="VBoxManage -nologo"
215
216
################################################################################
217
# FUNCTIONS
218
219
# Determine if USE_NAT is set to "yes"
220
use_nat() {
221
if [ "$USE_NAT" = "yes" ]; then
222
return `true`
223
else
224
return `false`
225
fi
226
}
227
228
log_failure_msg() {
229
echo $1
230
}
231
232
log_action_msg() {
233
echo $1
234
}
235
236
# Check for running machines every few seconds; return when all machines are
237
# down
238
wait_for_closing_machines() {
239
RUNNING_MACHINES=`$SU "$VBOXMANAGE list runningvms" | wc -l`
240
if [ $RUNNING_MACHINES != 0 ]; then
241
sleep 2
242
wait_for_closing_machines
243
fi
244
}
245
246
################################################################################
247
# RUN
248
case "$1" in
249
start)
250
if [ -f /etc/virtualbox/machines_enabled_start ]; then
251
252
cat /etc/virtualbox/machines_enabled_start | while read VM; do
253
log_action_msg "Starting VM: $VM ..."
254
$SU "$VBOXMANAGE startvm "$VM" --type headless"
255
sleep 20
256
RETVAL=$?
257
done
258
touch /var/lock/subsys/vboxcontrol
259
fi
260
;;
261
stop)
262
# NOTE: this stops all running VM's. Not just the ones listed in the
263
# config
264
cat /etc/virtualbox/machines_enabled_stop  | while read VM; do
265
log_action_msg "Shutting down VM: $VM ..."
266
$SU "$VBOXMANAGE controlvm "$VM" acpipowerbutton"
267
sleep 10
268
done
269
rm -f /var/lock/subsys/vboxcontrol
270
wait_for_closing_machines
271
;;
272
export)
273
# NOTE: this stops and exports the listed VMs
274
cat /etc/virtualbox/machines_enabled_export  | while read VM; do
275
  log_action_msg "Shutting down VM: $VM ..."
276
  $SU "$VBOXMANAGE controlvm "$VM" acpipowerbutton"
277
  /bin/echo -en "\a" > /dev/console
278
  sleep 10
279
done
280
wait_for_closing_machines
281
JKE_DATE=$(date +%F)
282
cat /etc/virtualbox/machines_enabled_export  | while read VM; do
283
  log_action_msg "Exporting VM: $VM ..."
284
  $SU "$VBOXMANAGE export "$VM" -o "$VM"_"$JKE_DATE"."ova" --manifest --vsys 0 --version $JKE_DATE"
285
done
286
rm -f /var/lock/subsys/vboxcontrol
287
;;
288
start-vm)
289
log_action_msg "Starting VM: $2 ..."
290
$SU "$VBOXMANAGE startvm "$2" --type headless"
291
;;
292
stop-vm)
293
log_action_msg "Stopping VM: $2 ..."
294
$SU "$VBOXMANAGE controlvm "$2" acpipowerbutton"
295
;;
296
poweroff-vm)
297
log_action_msg "Powering off VM: $2 ..."
298
$SU "$VBOXMANAGE controlvm "$2" poweroff"
299
;;
300
export-vm)
301
# NOTE: this exports the given VM
302
log_action_msg "Exporting VM: $2 ..."
303
JKE_DATE=$(date +%F)
304
$SU "$VBOXMANAGE export "$2" -o "$2"_"$JKE_DATE"."ova" --manifest --vsys 0 --version $JKE_DATE"
305
;;
306
status)
307
echo "The following virtual machines are currently running:"
308
$SU "$VBOXMANAGE list runningvms" | while read VM; do
309
echo -n "$VM ("
310
echo -n `$SU "VBoxManage showvminfo ${VM%% *}|grep Name:|sed -e 's/^Name:s*//g'"`
311
echo ')'
312
done
313
;;
314
315
*)
316
echo "Usage: $0 {start|stop|status|export|start-vm <VM
317
name>|stop-vm <VM name>|poweroff-vm <VM name>}|export-vm <VMname>"
318
exit 3
319
esac
320
321
exit 0
322
</pre>
323
324
To make the file executeable do
325
<pre><code class="bash">
326
chmod +x /etc/init.d/vboxcontrol
327
</code></pre>
328
Add vboxcontrol as service:
329
<pre><code class="bash">
330
cd /etc/init.d
331
chkconfig --add vboxcontrol
332
</code></pre>
333
Manually start the service
334
<pre><code class="bash">
335
service vboxcontrol start
336
</code></pre>
337
you can check the runlevels by
338
<pre><code class="bash">
339
chkconfig --list vboxcontrol
340
</code></pre>
341
you should get an output like:
342
<pre><code class="bash">
343
vboxcontrol     0:off   1:off   2:off   3:on   4:on   5:on   6:off
344
</code></pre>
345
346
With this setup, guest machines are also automatically shutdown cleanly in a host shutdown
347
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.
348
349
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.
350
351
h2. Problem
352
353
h3. KVM and Virtualbox side by side
354
355
VirtualBox might not work while KVM extensions are active
356
http://www.dedoimedo.com/computers/kvm-virtualbox.html may help