Projekt

Allgemein

Profil

Setup virtualboxhost60 » Historie » Version 6

Jeremias Keihsler, 14.01.2019 11:17

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