From 05d263fe3e313bde1c3da2fa67237df894971d43 Mon Sep 17 00:00:00 2001 From: Michael Janczyk Date: Thu, 25 Mar 2010 18:33:20 +0100 Subject: added support for rw disks and netboot --- .../plugins/virtualbox/files/run-virt.include | 86 ++++++++++++++++------ 1 file changed, 65 insertions(+), 21 deletions(-) (limited to 'os-plugins/plugins/virtualbox/files/run-virt.include') diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include index e3650ebd..11f8d0eb 100644 --- a/os-plugins/plugins/virtualbox/files/run-virt.include +++ b/os-plugins/plugins/virtualbox/files/run-virt.include @@ -32,21 +32,35 @@ fi PLUGINCONFVIRTUALBOX="${PLUGINCONFROOT}/${self}" # create TMPDIR for all users -mkdir -m 1777 /tmp/${self} 2>/dev/null +TMPDIR=/tmp/${self} +mkdir -m 1777 ${TMPDIR} 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} # define dirs and files which can be removed after exit, be carefull! -RMDIRS="${snapshotdir} ${confdir} /tmp/.vbox-${USER}-ipc" 2>/dev/null +RMDIRS="${snapshotdir} ${confdir} /tmp/.vbox-${USER}-ipc" rm -rf ${RMDIRS} 2>/dev/null -machfolder="${VBOX_USER_HOME}/Machines" +machfolder="${confdir}/Machines" # use vm_shortname for VM name since vm_name can be very long machconfig="${machfolder}/${vm_shortname}/${vm_shortname}.xml" -diskfolder="${VBOX_USER_HOME}/HardDisks" +diskfolder="${confdir}/HardDisks" snapshotdir=${machfolder}/${vm_shortname}/Snapshots -diskfile="${diskfolder}/${imgname}" mkdir -p ${diskfolder} ${snapshotdir} 2>/dev/null + +# configure rwimg +if [ "${imgmode}" = "rwimg" ] && ! [ -e "${vmpath}" ]; then + # what is our rwimg called? + imgname="${imgname}.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" +fi + +# link to image +diskfile="${diskfolder}/${imgname}" ln -sf ${vmpath} ${diskfile} # check the file type @@ -91,9 +105,9 @@ 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 -diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID | \ - awk '{print $2}') +# get UUID of VBox image, only if rwimg.vdi not used +diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID \ + | awk '{print $2}') # snapshot UUID is static snapshotuuid="88bc8b6d-f248-468a-95fe-318084904f8b" @@ -188,6 +202,21 @@ cdrom1=${cdtest:-"FALSE"} ide="TRUE" hddrv="ide" +# translate boot, use if set else set to HardDisk +if [ -n "${boot}" ]; then + case ${boot} in + n*) # usually support for a,c,d,n, stands for Floppy, HD, CD-ROM, Network + boot="Network" + ;; + # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM + *) + boot="HardDisk" + ;; + esac +else + boot="HardDisk" +fi + writelog "\tSnapshots dir:\t\t$snapshotdir" writelog "Diskimage:" writelog "\tDisk type:\t\t$imgtype" @@ -203,13 +232,15 @@ writelog "\tGuest RAM:\t\t${mem} MB" writelog "\tMAC address:\t\t$macaddr" writelog "\tNetwork card:\t\t${vb_network_card}" writelog "\tNetwork kind:\t\t${network_kind}" +writelog "\tBooting from:\t\t${boot}" # TODO: server start activate via xml, etc... #writelog "\tGuest VRDP port:\t${vrdpport}" #writelog "\tCD-ROM1:\t${cdrom0}" #writelog "\tCD-ROM2:\t${cdrom1}" #writelog "\tFloppy_A:\t${floppy0}" #writelog "\tFloppy_B:\t${floppy1}" -writelog "\tShared Folders 'home':\t/home/${USER}" +# defined in run-virt.sh and run-vmgrid.sh +writelog "\tShared Folders '${sharename}':\t${sharepath}" ################################################################################ ### Pepare and configure virtual machine and disk image @@ -217,20 +248,33 @@ writelog "\tShared Folders 'home':\t/home/${USER}" # TODO: date wichtig? #date="$(date +%Y-%m-%dT%H:%M:%SZ)" -. ${PLUGINCONFVIRTUALBOX}/virtualbox.include >"${VBOX_USER_HOME}/VirtualBox.xml" +. ${PLUGINCONFVIRTUALBOX}/virtualbox.include > "${confdir}/VirtualBox.xml" + +# 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="" + sed -i "/,${rwimghd}," \ + "${confdir}/VirtualBox.xml" + # replace image uuid in machine config + snapshotuuid=${diskuuid} +fi + +# TODO: add rawdisk if requested +#"raw.vmdk" format="VMDK" type="Writethrough"/> # shortened date YYYY-MM-DD #date=${date%T*} -. ${PLUGINCONFVIRTUALBOX}/machine.include >"${machconfig}" - -# add rw share to vm, if existing -if [ -n "${rwshare}" ]; then - sharedf='" - sed -i "s,, ${sharedf}\n ," \ - "${machconfig}" - writelog "\tShared Folders 'share':\t${rwshare}" -fi +. ${PLUGINCONFVIRTUALBOX}/machine.include > "${machconfig}" # add ssh port if linux and NAT if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then @@ -247,7 +291,7 @@ if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then writelog "\tGuest SSH port:\t\t${vmsshport}" fi -cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/virtualbox/empty-diff.vdi.gz | \ +cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/empty-diff.vdi.gz | \ gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi" ################################################################################ -- cgit v1.2.3-55-g7522