Projekt

Allgemein

Profil

Setup virtualboxhost60 » Historie » Version 4

Jeremias Keihsler, 14.01.2019 11:15

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