Projekt

Allgemein

Profil

Setup virtualboxhost60 » Historie » Version 2

Jeremias Keihsler, 25.12.2018 23:27

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