summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/virtualbox/files/run-virt.include
diff options
context:
space:
mode:
authorMichael Janczyk2010-03-26 22:09:31 +0100
committerMichael Janczyk2010-03-26 22:09:31 +0100
commit3e8723555bb0a1be3e27330275c4d6b2da9945df (patch)
treebd85d3e02dda631f32f2c69ff3fae27836c13a71 /os-plugins/plugins/virtualbox/files/run-virt.include
parentadded support for rw disks and netboot (diff)
downloadcore-3e8723555bb0a1be3e27330275c4d6b2da9945df.tar.gz
core-3e8723555bb0a1be3e27330275c4d6b2da9945df.tar.xz
core-3e8723555bb0a1be3e27330275c4d6b2da9945df.zip
NAT TFTP boot with VBox.
rwimg support added
Diffstat (limited to 'os-plugins/plugins/virtualbox/files/run-virt.include')
-rw-r--r--os-plugins/plugins/virtualbox/files/run-virt.include98
1 files changed, 60 insertions, 38 deletions
diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include
index 11f8d0eb..6d300044 100644
--- a/os-plugins/plugins/virtualbox/files/run-virt.include
+++ b/os-plugins/plugins/virtualbox/files/run-virt.include
@@ -31,6 +31,7 @@ fi
################################################################################
PLUGINCONFVIRTUALBOX="${PLUGINCONFROOT}/${self}"
+PLUGINDIRVIRTUALBOX="${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}"
# create TMPDIR for all users
TMPDIR=/tmp/${self}
mkdir -m 1777 ${TMPDIR} 2>/dev/null
@@ -48,15 +49,14 @@ diskfolder="${confdir}/HardDisks"
snapshotdir=${machfolder}/${vm_shortname}/Snapshots
mkdir -p ${diskfolder} ${snapshotdir} 2>/dev/null
-# configure rwimg
-if [ "${imgmode}" = "rwimg" ] && ! [ -e "${vmpath}" ]; then
+# configure our own rwimg, empty image which we support
+if [ "${imgmode}" = "rwimg" ]; then
# what is our rwimg called?
- imgname="${imgname}.vdi"
+ imgname="${vm_shortname}.vdi"
vmpath=${imgpath}/${imgname}
- cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/rwimg.vdi.gz \
- | gunzip > "${vmpath}"
- # static rw share image uuid
- #rwimguuid="ab20cb01-2d08-4d73-a33c-5594c5d0b8cb"
+ if ! [ -e "${vmpath}" ]; then
+ cat ${PLUGINDIRVIRTUALBOX}/rwimg.vdi.gz | gunzip > "${vmpath}"
+ fi
fi
# link to image
@@ -65,9 +65,9 @@ ln -sf ${vmpath} ${diskfile}
# check the file type
if echo ${imgname} | grep -iE "vdi|vmdk|vhd" >/dev/null 2>&1; then
- imgtype=$(echo ${imgname##*.} | tr [a-z] [A-Z])
+ imgfmt=$(echo ${imgname##*.} | tr [a-z] [A-Z])
else
- writelog "${imgname} is not a valid image type (vdi|vmdk|vhd), exiting!"
+ writelog "${imgname} is not a valid image format (vdi|vmdk|vhd), exiting!"
exit 1
fi
@@ -105,11 +105,42 @@ macaddr=$(echo ${macaddr} | sed 's/://g')
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, only if rwimg.vdi not used
+# get UUID of VBox image
diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID \
| awk '{print $2}')
+# make disk immutable
+imgtype="Immutable"
# snapshot UUID is static
snapshotuuid="88bc8b6d-f248-468a-95fe-318084904f8b"
+# imageuuid in machine.include, dafault snapshotuuid
+imageuuid=${snapshotuuid}
+
+# check if rw image
+# remove disk and add rwimg if set
+if echo "${imgmode}" | grep -q rw; then
+ # lock existing?
+ if [ -e "${vmpath}.lock" ]; then
+ writelog "This rw image is already in use: ${vmpath}, exiting!"
+ writelog "Remove lock if you are shure that this is not the case"
+ exit 1
+ # image rw?
+ elif ! [ -w ${vmpath} ]; then
+ writelog "You defined mode rw, but image is not rw! \c"
+ writelog "Please correct, exiting!"
+ exit 1
+ fi
+ # add lock
+ touch "${vmpath}.lock"
+ # remove lock after VM stopped
+ RMDIRS="${RMDIRS} ${vmpath}.lock"
+ imgtype="Normal"
+ # replace image uuid in machine config
+ imageuuid=${diskuuid}
+else
+ # use temp disk as snapshot
+ cat ${PLUGINDIRVIRTUALBOX}/empty-diff.vdi.gz \
+ | gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi"
+fi
# TODO: MEM muss noch angepasst werden. Maschine crasht wenn nehr als 50% MEM
# memory part equal to vmware plugin
@@ -171,7 +202,6 @@ case "${network_kind}" in
;;
*)
network_kind="NAT"
- ;;
esac
# external GUI
@@ -207,6 +237,16 @@ if [ -n "${boot}" ]; then
case ${boot} in
n*) # usually support for a,c,d,n, stands for Floppy, HD, CD-ROM, Network
boot="Network"
+ if [ "${network_kind}" = "NAT" ] && [ -n "${virtualbox_tftpdir}" ]; then
+ # remove spaces from VM name to avoid Problems /w TFTP in NAT
+ vm_name=$(echo ${vm_name} | sed -e "s, ,-,g")
+ # link TFTP dir for NAT TFTP boots
+ mkdir -p ${confdir}/TFTP
+ cp ${virtualbox_tftpdir}/pxelinux.0 ${confdir}/TFTP/${vm_name}.pxe
+ for i in $(ls ${virtualbox_tftpdir}); do
+ ln -sf ${virtualbox_tftpdir}/${i} ${confdir}/TFTP/${i}
+ done
+ fi
;;
# later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM
*)
@@ -219,8 +259,9 @@ fi
writelog "\tSnapshots dir:\t\t$snapshotdir"
writelog "Diskimage:"
-writelog "\tDisk type:\t\t$imgtype"
writelog "\tDisk file:\t\t$diskfile"
+writelog "\tDisk format:\t\t$imgfmt"
+writelog "\tDisk type:\t\t$imgtype"
writelog "\tVMostype:\t\t$vmostype"
writelog "\tMachine UUID:\t\t$machineuuid"
writelog "\tDisk UUID:\t\t$diskuuid"
@@ -246,35 +287,19 @@ writelog "\tShared Folders '${sharename}':\t${sharepath}"
### Pepare and configure virtual machine and disk image
################################################################################
-# TODO: date wichtig?
-#date="$(date +%Y-%m-%dT%H:%M:%SZ)"
-. ${PLUGINCONFVIRTUALBOX}/virtualbox.include > "${confdir}/VirtualBox.xml"
+# create Virtualbox.xml
+. ${PLUGINCONFVIRTUALBOX}/virtualbox.include
-# remove disk and add rwimg if set
-if echo "${imgmode}" | grep -q rw; then
- if [ -e "${vmpath}.lock" ]; then
- writelog "This rw image is already in use: ${vmpath}, exiting!"
- writelog "Remove lock if you are shure that this is not the case"
- exit 1
- fi
- # add lock
- touch "${vmpath}.lock"
- # remove lock after VM stopped
- RMDIRS="${RMDIRS} ${vmpath}.lock"
- rwimghd="<HardDisk uuid=\"{${diskuuid}}\" location=\"${diskfile}\""
- rwimghd="${rwimghd} format=\"VDI\" type=\"Normal\"/>"
- sed -i "/<HardDisk uuid/d;s,</HardDisk>,${rwimghd}," \
- "${confdir}/VirtualBox.xml"
- # replace image uuid in machine config
- snapshotuuid=${diskuuid}
+# remove snapshot disk when using rw images
+if [ "${imgtype}" != "Immutable" ]; then
+ sed -i "/${snapshotuuid}/d" "${confdir}/VirtualBox.xml"
fi
# TODO: add rawdisk if requested
#"raw.vmdk" format="VMDK" type="Writethrough"/>
-# shortened date YYYY-MM-DD
-#date=${date%T*}
-. ${PLUGINCONFVIRTUALBOX}/machine.include > "${machconfig}"
+# create machine.xml
+. ${PLUGINCONFVIRTUALBOX}/machine.include
# add ssh port if linux and NAT
if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then
@@ -291,9 +316,6 @@ if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then
writelog "\tGuest SSH port:\t\t${vmsshport}"
fi
-cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/empty-diff.vdi.gz | \
- gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi"
-
################################################################################
### finally set env for run-virt.sh
################################################################################