summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/virtualbox/files/run-virt.include
blob: b4ecf2ff1f3686fe710325afd0896160500beaf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# run-virtualbox.include
#
# Copyright (c) 2009 - OpenSLX GmbH
#
# This program/file is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# Include script for running the Virtual Box on an OpenSLX client via the
# run-virt.sh. The stuff is copied to /etc/opt/openslx/run-virtualbox.include
# during stage3.

# include general configuration from vmchooser
. /etc/opt/openslx/run-virt.include

# memory part equal to vmware plugin
# percentage of memory to use for virtualbox in standard case
permem=30
if [ "${totalmem}" -ge "1600" ]; then
  permem=40
fi
# check if /tmp is on harddisk
if grep -qe "/dev/.* /tmp " /proc/mounts ; then
  permem=60
  id44="1"
  # Hack, if more than 2,5G RAM use 40% of Ram and write vmem into Ram as well
  # (40% vmware | 40% confdir(vmem...) | 20% host
  # VMplayer 2+ issue
  if [ "${totalmem}" -ge "2500" ]; then
    permem=40
    mkdir /dev/shm/vbox/${USER}
    snapshotdir=/dev/shm/vbox/$USER
  fi
fi
mem=$(expr ${totalmem} / 100 \* ${permem})
if [ "${id44}" = "1" ]; then
  memhost=$(expr ${totalmem} - ${mem})
else
  memhost=$(expr ${totalmem} - ${mem} - ${mem})
fi

#permem=40
#mem=$(expr ${totalmem} * ${permem})

if [ "${mem}" -lt "256" ] || [ "${memhost}" -lt "256" ]; then
  writelog "\tMemory out of range: ${mem} MB (guest) / ${memhost} MB (host)!"
  writelog "\tMin. 256 MB for host and guest!"
  exit 1
fi



# most of the following does not make much sense yet ...
#
# virtual fd/cd/dvd and drive devices, floppy b: for configuration
# if $floppy_0 from run-virt.include set then fdtest="TRUE"
fdtest=
fdtest=${floppy_0:+"TRUE"}
# if $fdtest not set floppy0="FALSE", else "TRUE"
floppy0=${fdtest:-"FALSE"}
floppy1="TRUE"
floppy1name="/var/lib/virt/vmchooser/loopimg/fd.img"
# if $cdrom_0 from run-virt.include set then cdtest="TRUE"
cdtest=
cdtest=${cdrom_0:+"TRUE"}
# if $cdtest not set cdrom0="FALSE", else "TRUE"
cdrom0=${cdtest:-"FALSE"}
# if $cdrom_1 from run-virt.include set then cdtest="TRUE"
cdtest=
cdtest=${cdrom_1:+"TRUE"}
# if $cdtest not set cdrom1="FALSE", else "TRUE"
cdrom1=${cdtest:-"FALSE"}
# ide is expected default, test for the virtual disk image type should
# be done while creating the runscripts ...
ide="TRUE"
hddrv="ide"


################################################################################
### Pepare env and and configure Image
################################################################################

# Current ID, to make sure it won't run into conflicts if started more
# as once at the same time, else delete would make the trick...
ID=$$
# Don't use $HOME/.VirtualBox!
export VBOX_USER_HOME="/tmp/vbox-${USER}-${ID}"

# Import Image to VirtualBox, which won't get changed
VBoxManage -q registerimage disk ${diskfile} -type immutable

# Get ID of VBox Image...
diskuid="$(VBoxManage -q showvdiinfo ${diskfile} |grep UUID|awk '{ print $2; }')"
# Create Image and register it, so we are able to modify and start it
VBoxManage createvm -name "${ID}" -register

################################################################################
###
### Modify VM
###
################################################################################

## Add harddisk
VBoxManage -q modifyvm "${ID}" -hda ${diskuid}

## Configure VM memory
VBoxManage -q modifyvm "${ID}" -memory ${mem}

## Add cddrives
## TODO: merge to new version, where run-virt.include has our drives
#VBoxManage -q modifyvm "${ID}" -dvd host:${cdrs}

# Enable hardware virtualization
# TODO: check if CPU supports hw virtualization
#VBoxManage -q modifyvm "${ID}" -hwvirtex on

# HDD as boot device
VBoxManage -q modifyvm "${ID}" -boot1 disk

# enable audio (oss|null|none|alsa|pulse). OSS is backwardcompatible to v2.0
VBoxManage -q modifyvm "${ID}" -audio oss

# supress License and Message
# TODO: Not clear if we are allowed to do this
VBoxManage -q setextradata global "GUI/LicenseAgreed" "7"
VBoxManage -q setextradata global "GUI/SuppressMessages" ",remindAboutAutoCapture"
VBoxManage -q setextradata global "GUI/RegistrationData" "triesLeft=0"

# if we have enough memory, we can put the snapshots (changes on immutable
# disk) there
if [ -n ${snapshotdir} ]; then
    VBoxManage -q modifyvm "${ID}" --snapshotfolder "${snapshotdir}"
fi

# Operating system. Possible: VBoxManage list ostypes
# WindowsXP, WindowsVista, Windows7, Linux26 etc.
# keep compatibility to VMware
# Todo: maybe rewrite, to reduce checks, merge it with network option,
# so we can have a "compatibility to vmware config" section. Or include
# it into vmchooser?
if [ "${vmostype}" = "winxppro" -o "${vmostype}" = "WindowsXP" ]; then
    VBoxManage -q modifyvm "${ID}" --ostype "WindowsXP"
elif [ "${vmostype}" = "winvista" -o "${vmostype}" = "WindowsVista" ]; then
    VBoxManage -q modifyvm "${ID}" --ostype "WindowsVista"
elif [ "${vmostype}" = "Windows7" ]; then
    VBoxManage -q modifyvm "${ID}" --ostype "Windows7"
elif [ "${vmostype}" = "linux" -o "${vmostype}" = "Linux26" ]; then
    VBoxManage -q modifyvm "${ID}" --ostype "Linux26"
elif [ -n "${vmostype}" ]; then
    VBoxManage -q modifyvm "${ID}" --ostype "${vmostype}"
fi


# Network Configuration
# only bridge differes to vmware
if [ "${network_kind}" = "bridge" ]; then
	network_kind="bridged"
fi
VBoxManage -q modifyvm "${ID}" --nic1 "${network_kind}"

# modify macaddress
mac=$(echo ${mac}|sed 's/://') # ${mac/:/}
VBoxManage -q modifyvm "${ID}" --macaddress1 "0050560D${mac}"

# finally set env for run-virt.sh
################################################################################

# set the variables appropriately (several interfaces with different names)
#VIRTCMD=$(which virtualbox 2>/dev/null)
VIRTCMD=$(which VBoxManage 2>/dev/null)
VIRTCMDOPTS="startvm ${ID} -type gui"

# todo: for debugging purpose during development
echo "\n  export VBOX_USER_HOME=\"/tmp/vbox-${USER}-${ID}\""
echo "  VBoxManage $VIRTCMDOPTS\n\n"