summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/virtualbox/files/run-virt.include
diff options
context:
space:
mode:
authorMichael Janczyk2010-03-19 17:33:16 +0100
committerMichael Janczyk2010-03-19 17:33:16 +0100
commit85c3afe09fbdd38acc461aa7965409a1d3ffa858 (patch)
tree28b2d20a5575bf4f679f0ca5bf89784de7a1c4be /os-plugins/plugins/virtualbox/files/run-virt.include
parentAdding the runlevel linker again (having the upstart component for newer (diff)
downloadcore-85c3afe09fbdd38acc461aa7965409a1d3ffa858.tar.gz
core-85c3afe09fbdd38acc461aa7965409a1d3ffa858.tar.xz
core-85c3afe09fbdd38acc461aa7965409a1d3ffa858.zip
virtualbox, vmgrix und xen anpassungen
Diffstat (limited to 'os-plugins/plugins/virtualbox/files/run-virt.include')
-rw-r--r--os-plugins/plugins/virtualbox/files/run-virt.include352
1 files changed, 218 insertions, 134 deletions
diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include
index e16e2edf..44a749cb 100644
--- a/os-plugins/plugins/virtualbox/files/run-virt.include
+++ b/os-plugins/plugins/virtualbox/files/run-virt.include
@@ -1,6 +1,7 @@
-# run-virtualbox.include
-#
-# Copyright (c) 2009 - OpenSLX GmbH
+# run-virt.include
+# -----------------------------------------------------------------------------
+# Copyright (c) 2009..2010 - RZ Uni Freiburg
+# Copyright (c) 2009..2010 - OpenSLX GmbH
#
# This program/file is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
@@ -9,53 +10,158 @@
# 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.
+# -----------------------------------------------------------------------------
+# run-virt.include
+# - Include script for running the Virtual Box on an OpenSLX client via the
+# run-virt.sh or run-vmgrid.sh
+################################################################################
+
+################################################################################
+### Include general configuration
+################################################################################
+if [ -f ${OPENSLX_DEFAULT_CONFDIR}/plugins/${self}/${self}.conf ]; then
+ . ${OPENSLX_DEFAULT_CONFDIR}/plugins/${self}/${self}.conf
+else
+ writelog "Problems reading config file of ${self} plugin"
+ exit 1
+fi
+
+################################################################################
+### Declaration of default variables
+################################################################################
+
+PLUGINCONFVIRTUALBOX="${PLUGINCONFROOT}/${self}"
+# create TMPDIR for all users
+mkdir -m 1777 /tmp/${self} 2>/dev/null
+# dir for configs
+confdir="/tmp/${self}/${USER}/${VM_ID}"
+# use alternate configuration directory instead of $HOME/.VirtualBox
+export VBOX_USER_HOME=${confdir}
+rm -rf ${VBOX_USER_HOME}/* /tmp/.vbox-${USER}-ipc
+machfolder="${VBOX_USER_HOME}/Machines"
+# imgname is the name of the virtual image file
+# use vm_shortname since vm_name can be very long
+vm_shortname=$(echo ${imgname%.*} | sed -e "s, ,-,g")
+machconfig="${machfolder}/${vm_shortname}/${vm_shortname}.xml"
+diskfolder="${VBOX_USER_HOME}/HardDisks"
+snapshotdir=${machfolder}/${vm_shortname}/Snapshots
+# imgname is the name of the virtual image file
+diskfile="${diskfolder}/${imgname}"
+mkdir -p ${diskfolder} ${snapshotdir}
+ln -sf ${vmpath} ${diskfile}
+
+# check the file type
+if echo ${imgname} | grep -iE "vdi" >/dev/null 2>&1; then #vmdk|vhd
+ imgtype=$(echo ${imgname#*.} | tr [a-z] [A-Z])
+else
+ writelog "${imgname} is not a valid image type (vdi)" #vmdk|vhd
+fi
+
+# TODO: maybe rewrite, to reduce checks, merge it with network option,
+# so we can have a "compatibility to vmware config" section
+case "${vmostype}" in
+ winxp*)
+ vmostype="WindowsXP"
+ ;;
+ winvista*)
+ vmostype="WindowsVista"
+ ;;
+ Windows7*)
+ vmostype="Windows7"
+ ;;
+ linux*)
+ vmostype="Linux26"
+ ;;
+esac
+
+writelog "Directories:"
+writelog "\tConfig dir:\t\t$confdir"
+writelog "\tMachines dir:\t\t$machfolder"
+writelog "\tMachine config:\t\t$machconfig"
+writelog "\tHardDisks dir:\t\t$diskfolder"
+
+################################################################################
+### Hardware checks
+################################################################################
+
+# remove ':' from MAC addr for vbox
+macaddr=$(echo ${macaddr} | sed 's/://g')
-# include general configuration from vmchooser
-. /etc/opt/openslx/run-virt.include
+# machine UUID, MAC addr part of it
+machineuuid="00000000-0000-0000-0000-${macaddr}"
+# cosmetical, since UUID in lower case
+machineuuid=$(echo ${machineuuid} | tr [A-Z] [a-z])
+# get UUID of VBox image
+diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID | \
+ awk '{print $2}')
+# snapshot UUID is static
+snapshotuuid="88bc8b6d-f248-468a-95fe-318084904f8b"
# 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
+if [ -n "${forcemem}" ]; then
+ mem="${forcemem}"
+else
+ permem=30
+ if [ "${totalmem}" -ge "1600" ]; 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})
+ # 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
+ # TODO: makes this sense for vbox?
+ #if [ "${totalmem}" -ge "2500" ]; then
+ #permem=40
+ #rmdir ${snapshotdir}
+ #snapshotdirold=${snapshotdir}
+ #snapshotdir=/dev/shm/${self}/${USER}/${VM_ID}
+ #mkdir -p ${snapshotdir}
+ #ln -sf ${snapshotdir} ${snapshotdirold}
+ #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 "Memory out of range: ${mem} MB (guest) / ${memhost} MB (host)!"
+ writelog "Min. 256 MB for host and guest!"
+ exit 1
+ fi
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
+# translate network cards
+if [ "${network_card}" = "e1000" ]; then
+ vb_network_card="82540EM"
+else
+ network_card="pcnet"
+ vb_network_card="Am79C973"
fi
+# translate network kinds (nat, bridged, host-only)
+case "${network_kind}" in
+ bridged)
+ network_kind='BridgedInterface name="br0"'
+ ;;
+ host-only)
+ network_kind='HostOnlyInterface name="vboxnet0"'
+ ;;
+ *)
+ network_kind="NAT"
+ ;;
+esac
+vrdpport="590${VM_ID}"
-# most of the following does not make much sense yet ...
-#
+# TODO: 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=
@@ -79,114 +185,92 @@ cdrom1=${cdtest:-"FALSE"}
ide="TRUE"
hddrv="ide"
+writelog "\tSnapshots dir:\t\t$snapshotdir"
+writelog "Diskimage:"
+writelog "\tDisk type:\t\t$imgtype"
+writelog "\tDisk file:\t\t$diskfile"
+writelog "\tVMostype:\t\t$vmostype"
+writelog "\tMachine UUID:\t\t$machineuuid"
+writelog "\tDisk UUID:\t\t$diskuuid"
+writelog "\tSnapshot UUID:\t\t$snapshotuuid"
+writelog "Virtual Hardware:"
+writelog "\tGuest RAM:\t\t${mem} MB"
+# echo nur wenn memhost gesetzt
+[ -n "${memhost}" ] && writelog "\tHost RAM:\t\t${memhost} MB"
+writelog "\tMAC address:\t\t$macaddr"
+writelog "\tNetwork card:\t\t${vb_network_card}"
+writelog "\tNetwork kind:\t\t${network_kind}"
+#writelog "\tCD-ROM1:\t${cdrom0}"
+#writelog "\tCD-ROM2:\t${cdrom1}"
+#writelog "\tFloppy_A:\t${floppy0}"
################################################################################
-### 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 -nologo registerimage disk ${diskfile} -type immutable
-
-# Get ID of VBox Image...
-diskuid="$(VBoxManage -nologo showvdiinfo ${diskfile} |grep UUID|awk '{ print $2; }')"
-# Create Image and register it, so we are able to modify and start it
-VBoxManage -nologo createvm -name "${ID}" -register
-
-################################################################################
-###
-### Modify VM
-###
+### Pepare and configure virtual machine and disk image
################################################################################
-## Add harddisk
-VBoxManage -nologo modifyvm "${ID}" -hda ${diskuid}
-
-## Configure VM memory
-VBoxManage -nologo modifyvm "${ID}" -memory ${mem}
-
-## Add cddrives
-## TODO: merge to new version, where run-virt.include has our drives
-#VBoxManage -nologo modifyvm "${ID}" -dvd host:${cdrs}
-
-# Enable hardware virtualization
-# TODO: check if CPU supports hw virtualization
-#VBoxManage -nologo modifyvm "${ID}" -hwvirtex on
-
-# HDD as boot device
-VBoxManage -nologo modifyvm "${ID}" -boot1 disk
+# TODO: date wichtig?
+#date="$(date +%Y-%m-%dT%H:%M:%SZ)"
+. ${PLUGINCONFVIRTUALBOX}/virtualbox.include >"${VBOX_USER_HOME}/VirtualBox.xml"
-# enable audio (oss|null|none|alsa|pulse). OSS is backwardcompatible to v2.0
-VBoxManage -nologo modifyvm "${ID}" -audio oss
+# shortened date YYYY-MM-DD
+#date=${date%T*}
+. ${PLUGINCONFVIRTUALBOX}/machine.include >"${machconfig}"
-# supress License and Message
-# TODO: Not clear if we are allowed to do this
-VBoxManage -nologo setextradata global "GUI/LicenseAgreed" "7"
-VBoxManage -nologo setextradata global "GUI/SuppressMessages" ",remindAboutAutoCapture"
-VBoxManage -nologo 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 -nologo modifyvm "${ID}" -snapshotfolder "${snapshotdir}"
-fi
-
-# Operating system. Possible: VBoxManage -nologo 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 -nologo modifyvm "${ID}" -ostype "WindowsXP"
-elif [ "${vmostype}" = "winvista" -o "${vmostype}" = "WindowsVista" ]; then
- VBoxManage -nologo modifyvm "${ID}" -ostype "WindowsVista"
-elif [ "${vmostype}" = "Windows7" ]; then
- VBoxManage -nologo modifyvm "${ID}" -ostype "Windows7"
-elif [ "${vmostype}" = "linux" -o "${vmostype}" = "Linux26" ]; then
- VBoxManage -nologo modifyvm "${ID}" -ostype "Linux26"
-elif [ -n "${vmostype}" ]; then
- VBoxManage -nologo modifyvm "${ID}" -ostype "${vmostype}"
+# add ssh port if linux and NAT
+if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then
+ vmsshport="220${VM_ID}"
+ extradataitem='<ExtraDataItem name="VBoxInternal/Devices' \
+ extradataitem="${extradataitem}/${network_card}/0/LUN#0/Config/ssh/"
+ extradataguestport='GuestPort" value="22"/>'
+ extradatahostport="HostPort\" value=\"${vmsshport}\"/>"
+ extradataprotocol='Protocol" value="TCP"/>'
+ sed -i "s,</ExtraData>, ${extradataitem}${extradataguestport}\n\
+ ${extradataitem}${extradatahostport}\n\
+ ${extradataitem}${extradataprotocol}\n\
+ </ExtraData>," "${machconfig}"
+ writelog "\tGuest SSH port:\t\t${vmsshport}"
fi
+cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/virtualbox/empty-diff.vdi.gz | \
+ gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi"
-# Network Configuration
-# only bridge differes to vmware. Compatibility option
-if [ "${network_kind}" = "bridge" ]; then
- network_kind="bridged"
-fi
-VBoxManage -nologo modifyvm "${ID}" -nic1 "${network_kind}"
-if [ "${network_kind}" = "bridged" ]; then
- VBoxManage -nologo modifyvm "${ID}" -bridgeadapter1 "eth1"
-fi
-if [ "${network_kind}" = "hostonly" ]; then
- VBoxManage -nologo modifyvm "${ID}" -hostonlyadapter1 "vboxnet0"
-fi
-
-# modify macaddress
-mac=$(echo ${mac}|sed 's/://') # ${mac/:/}
-VBoxManage -nologo modifyvm "${ID}" -macaddress1 "0050560D${mac}"
+################################################################################
+# finally set env for run-virt.sh
+################################################################################
+# wait for a certain command to settle
+# get the PID of the right process
+# TODO: not very good! But seems to work
+# TODO: not needed? KILL!!!
+VBMANPID=$(pstree -p | grep VBoxXPCOMIPCD | grep -ivE "VirtualBox|VBoxHeadless"\
+ | sed -e "s/.*VBoxXPCOMIPCD(\(.*\)).*/\1/")
+for i in $(echo ${VBMANPID}); do
+ kill -9 ${VBMANPID} >/dev/null 2>&1
+done
+# TODO: OLD Version, NOW: KILL process
+#VBMANPID=$(pstree -p | grep VBoxXPCOMIPCD | grep -ivE "VirtualBox|VBoxHeadless"\
+# | sed -e "s/.*VBoxXPCOMIPCD(\(.*\)).*/\1/" | tail -n 1)
+#for i in {0..999}; do
+# ps aux | grep -v grep | grep VBoxXPCOMIPCD | grep -q " ${VBMANPID} " || break
+# if [ $i -eq 999 ]; then
+# kill -9 ${VBMANPID} >/dev/null 2>&1
+# writelog "Process ID ${VBMANPID} did not finish, killing!"
+# fi
+#done
-# usb configuration
-# not available in free -ose version
-#VBoxManage -nologo modifyvm "${ID}" -usb on
-#VBoxManage -nologo modifyvm "${ID}" -usbehci on
+# define dirs and files which can be removed after exit, be carefull!
+RMDIRS="${snapshotdir} ${confdir}"
+# set the variables appropriately (several interfaces with different names)
+VIRTCMD=$(which VirtualBox 2>/dev/null)
+VIRTCMDOPTS="--startvm ${machineuuid} --start-running"
-# finally set env for run-virt.sh
-################################################################################
+# SDL tests
+#VIRTCMDSDL=$(which VBoxSDL 2>/dev/null)
+#VIRTCMDOPTSSDL="--startvm ${machineuuid} --fullscreen --hwvirtex --memory 1024 \
+# --fixedmode 1680 1050 24 --hostkey 302 0"
-# set the variables appropriately (several interfaces with different names)
-#VIRTCMD=$(which virtualbox 2>/dev/null)
-VIRTCMD=$(which VBoxManage -nologo 2>/dev/null)
-VIRTCMDOPTS="startvm ${ID} -type gui"
+# set headless mode
+VIRTCMDHL=$(which VBoxHeadless 2>/dev/null)
+VIRTCMDOPTSHL="-s ${machineuuid}"
-# todo: for debugging purpose during development
-echo "\n export VBOX_USER_HOME=\"/tmp/vbox-${USER}-${ID}\""
-echo " VBoxManage -nologo $VIRTCMDOPTS\n\n"