diff options
author | Michael Janczyk | 2010-04-08 21:07:44 +0200 |
---|---|---|
committer | Michael Janczyk | 2010-04-08 21:07:44 +0200 |
commit | 8ac3d72cd1ba2d9b76f6c201b6cb9f3389915cb6 (patch) | |
tree | 96242f130329608c1d97bec48576c802208635ed | |
parent | Merge branch 'master' into vmgrid (diff) | |
download | core-8ac3d72cd1ba2d9b76f6c201b6cb9f3389915cb6.tar.gz core-8ac3d72cd1ba2d9b76f6c201b6cb9f3389915cb6.tar.xz core-8ac3d72cd1ba2d9b76f6c201b6cb9f3389915cb6.zip |
virtualization plugin refurbished ;). booting 64bit guest on 32 bit hosts now possible /w virtualbox
-rw-r--r-- | boot-env/OpenSLX/MakeInitRamFS/Engine/Base.pm | 16 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/XX_virtualbox.sh | 6 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/machine.include | 2 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/run-virt.include | 44 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/virtualbox.include | 2 | ||||
-rw-r--r-- | os-plugins/plugins/vmchooser/XX_vmchooser.sh | 26 | ||||
-rw-r--r-- | os-plugins/plugins/vmchooser/files/run-virt.sh | 5 | ||||
-rw-r--r-- | os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh | 114 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/XX_vmgrid.sh | 24 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 17 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/vmgrid | 50 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh | 114 |
12 files changed, 296 insertions, 124 deletions
diff --git a/boot-env/OpenSLX/MakeInitRamFS/Engine/Base.pm b/boot-env/OpenSLX/MakeInitRamFS/Engine/Base.pm index cac92b37..6de0a4fe 100644 --- a/boot-env/OpenSLX/MakeInitRamFS/Engine/Base.pm +++ b/boot-env/OpenSLX/MakeInitRamFS/Engine/Base.pm @@ -383,17 +383,17 @@ sub _writeSlxSystemConf # check if default directories available and copy them to /etc my $defaultDirConfig = "$self->{'root-path'}/etc/opt/openslx/openslx.conf"; my $configTargetPath = "$self->{'build-path'}/etc"; - my $defaultConfVer = slurpFile("$defaultDirConfig"); - my $actConfVer = "Version 0.2"; + #my $defaultConfVer = slurpFile("$defaultDirConfig"); + #my $actConfVer = "Version 0.2"; if (-r $defaultDirConfig) { $self->addCMD("cp -p $defaultDirConfig $configTargetPath/"); - if ($defaultConfVer =~ m{$actConfVer}) { - warn _tr( - "Your version of default dir file (openslx.conf) is to old!\n". - "Eventually the system won't work.\n" . - "Please run install, update or clone of this system again!\n"); - } +# if ($defaultConfVer =~ m{$actConfVer}) { +# warn _tr( +# "Your version of default dir file (openslx.conf) is to old!\n". +# "Eventually the system won't work.\n" . +# "Please run install, update or clone of this system again!\n"); +# } } else { die _tr( "No default directories defined!\n" . diff --git a/os-plugins/plugins/virtualbox/XX_virtualbox.sh b/os-plugins/plugins/virtualbox/XX_virtualbox.sh index 07e58428..807ef0a8 100644 --- a/os-plugins/plugins/virtualbox/XX_virtualbox.sh +++ b/os-plugins/plugins/virtualbox/XX_virtualbox.sh @@ -87,7 +87,11 @@ if [ -e ${CONFFILE} ]; then mknod -m 0660 /dev/vboxdrv c 10 59 chown root:vboxusers /dev/vboxdrv + + # finished ... + [ $DEBUGLEVEL -gt 0 ] && echo "done with 'virtualbox' os-plugin ..." fi else - [ $DEBUGLEVEL -gt 0 ] && echo " * Configuration of virtualbox plugin failed" + [ $DEBUGLEVEL -gt 0 ] \ + && echo " * Configuration of 'virtualbox' plugin failed" fi diff --git a/os-plugins/plugins/virtualbox/files/machine.include b/os-plugins/plugins/virtualbox/files/machine.include index a76c7e6f..0482d03a 100644 --- a/os-plugins/plugins/virtualbox/files/machine.include +++ b/os-plugins/plugins/virtualbox/files/machine.include @@ -14,7 +14,7 @@ cat << EOF > "${machconfig}" <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/> </ExtraData> <Hardware version="2"> - <CPU count="1"> + <CPU count="${cpu_cores}"> <HardwareVirtEx enabled="true" exclusive="true"/> <HardwareVirtExNestedPaging enabled="false"/> <HardwareVirtExVPID enabled="false"/> diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include index 5fc0641a..af5595ee 100644 --- a/os-plugins/plugins/virtualbox/files/run-virt.include +++ b/os-plugins/plugins/virtualbox/files/run-virt.include @@ -66,7 +66,7 @@ diskfile="${diskfolder}/${imgname}" [ ${diskless} -eq 0 ] && ln -sf ${vmpath} ${diskfile} # check the file type -if echo ${imgname} | grep -iE "vdi|vmdk|vhd" && [ ${diskless} -eq 0 ]; then +if echo ${imgname} | grep -qiE "vdi|vmdk|vhd" && [ ${diskless} -eq 0 ]; then imgfmt=$(echo ${imgname##*.} | tr [a-z] [A-Z]) elif [ ${diskless} -eq 0 ]; then writelog "${imgname} is not a valid image format (vdi|vmdk|vhd), exiting!" @@ -76,17 +76,31 @@ 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*) + winxp*|windowsxp*) vmostype="WindowsXP" ;; - winvista*) + winvista*|windowsvista*) vmostype="WindowsVista" ;; - Windows7*) + windows7*) vmostype="Windows7" ;; - linux*) - vmostype="Linux26" + linux*|*ubuntu*|*suse*|debian*|*sci*) + if echo "${vmostype}" | grep -q "64"; then + vmostype="Linux26_64" + # check for vtflag + if [ ${vtflag} -ne 1 ]; then + writelog "You are trying to boot a 64 bit OS without a VT enabled CPU" + writelog "This is not supported, exiting!" + exit 1 + fi + # check if host is only 32 bit, then use only 1 cpu (only 1 supported) + if echo "${host_arch}" | grep -qE "i.86"; then + cpu_cores=1 + fi + else + vmostype="Linux26" + fi ;; esac @@ -123,7 +137,7 @@ 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" + writelog "Remove lock if you are sure that this is not the case" exit 1 # image rw? elif ! [ -w ${vmpath} ]; then @@ -144,6 +158,9 @@ elif [ ${diskless} -eq 0 ]; then | gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi" fi +# make sure cpu_cores is not empty +cpu_cores=${cpu_cores:-"1"} + # TODO: MEM muss noch angepasst werden. Maschine crasht wenn nehr als 50% MEM # memory part equal to vmware plugin # percentage of memory to use for virtualbox in standard case @@ -222,7 +239,13 @@ case ${boot} in 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 + if [ -e ${virtualbox_tftpdir}/pxelinux.0 ]; then + cp ${virtualbox_tftpdir}/pxelinux.0 ${confdir}/TFTP/${vm_name}.pxe + else + writelog "${virtualbox_tftpdir}/pxelinux.0 not found!" + writelog "Network boot won't work, exiting!" + exit 1 + fi for i in $(ls ${virtualbox_tftpdir}); do ln -sf ${virtualbox_tftpdir}/${i} ${confdir}/TFTP/${i} done @@ -271,6 +294,7 @@ writelog "Diskimage:" writelog "\tMachine UUID:\t\t$machineuuid" [ ${diskless} -eq 0 ] && writelog "\tDisk UUID:\t\t$diskuuid" writelog "Virtual Hardware:" +[ ${vtflag} -eq 1 ] && writelog "\tVT enabled CPU" writelog "\tGuest RAM:\t\t${mem} MB" # echo nur wenn memhost gesetzt [ -n "${memhost}" ] && writelog "\tHost RAM:\t\t${memhost} MB" @@ -315,8 +339,8 @@ if [ ${diskless} -eq 1 ]; then sed -i "/<!-- PLEASE DO NOT REMOVE THIS COMMENT!!! -->/d" ${machconfig} fi -# add ssh port if linux and NAT -if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then +# add ssh port if Linux26* and NAT +if echo "${vmostype}" | grep -q "Linux26" && [ "${network_kind}" = "NAT" ]; then vmsshport="220${VM_ID}" extradataitem='<ExtraDataItem name="VBoxInternal/Devices' \ extradataitem="${extradataitem}/${network_card}/0/LUN#0/Config/ssh/" diff --git a/os-plugins/plugins/virtualbox/files/virtualbox.include b/os-plugins/plugins/virtualbox/files/virtualbox.include index 09a2f33b..2a7af026 100644 --- a/os-plugins/plugins/virtualbox/files/virtualbox.include +++ b/os-plugins/plugins/virtualbox/files/virtualbox.include @@ -10,7 +10,7 @@ cat << EOF > "${confdir}/VirtualBox.xml" <ExtraDataItem name="GUI/LicenseAgreed" value="7"/> <ExtraDataItem name="GUI/MaxGuestResolution" value="any"/> <!-- auto, width,height --> <ExtraDataItem name="GUI/SUNOnlineData" value="triesLeft=0"/> - <ExtraDataItem name="GUI/SuppressMessages" value=",remindAboutAutoCapture,confirmInputCapture,remindAboutWrongColorDepth,confirmGoingFullscreen,remindAboutMouseIntegrationOn,remindAboutMouseIntegrationOff,showRuntimeError.warning.DevATA_DISKFULL,remindAboutPausedVMInput,confirmVMReset"/> + <ExtraDataItem name="GUI/SuppressMessages" value=",remindAboutAutoCapture,confirmInputCapture,remindAboutWrongColorDepth,confirmGoingFullscreen,remindAboutMouseIntegrationOn,remindAboutMouseIntegrationOff,showRuntimeError.warning.DevATA_DISKFULL,remindAboutPausedVMInput,confirmVMReset,showRuntimeError.warning.HostAudioNotResponding"/> <ExtraDataItem name="GUI/TrayIcon/Enabled" value="false"/> <ExtraDataItem name="GUI/UpdateCheckCount" value="2"/> <ExtraDataItem name="GUI/UpdateDate" value="never"/> diff --git a/os-plugins/plugins/vmchooser/XX_vmchooser.sh b/os-plugins/plugins/vmchooser/XX_vmchooser.sh index 35d17a2e..168bcda1 100644 --- a/os-plugins/plugins/vmchooser/XX_vmchooser.sh +++ b/os-plugins/plugins/vmchooser/XX_vmchooser.sh @@ -51,32 +51,6 @@ if [ -e $CONFFILE ]; then mount -n -t msdos -o loop,umask=000 ${PLUGINCONFDIR}/loopimg/fd.img \ ${PLUGINCONFDIR}/fd-loop - # create run-virt.include header (and fill in information on removable - # devices if present - echo -e "# run-virt.include created by $0 during stage3 plugin setup" \ - >${PLUGINCONFDIR}/run-virt.include - - waitfor /etc/hwinfo.cdrom - j=0 - for i in $(cat /etc/hwinfo.cdrom); do - echo "cdrom_$j=$i" >>${PLUGINCONFDIR}/run-virt.include - j=$(expr $j + 1) - done - - waitfor /etc/hwinfo.floppy - j=0 - for i in $(cat /etc/hwinfo.floppy); do - echo "floppy_$j=$i" >>${PLUGINCONFDIR}/run-virt.include - j=$(expr $j + 1) - done - - CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l) - if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then - echo "cpu_cores=\"${CPU_CORES}\"" >>${PLUGINCONFDIR}/run-virt.include - else - echo 'cpu_cores="1"' >>${PLUGINCONFDIR}/run-virt.include - fi - # finished ... [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmchooser' os-plugin ..." fi diff --git a/os-plugins/plugins/vmchooser/files/run-virt.sh b/os-plugins/plugins/vmchooser/files/run-virt.sh index 9bc31396..adfc737e 100644 --- a/os-plugins/plugins/vmchooser/files/run-virt.sh +++ b/os-plugins/plugins/vmchooser/files/run-virt.sh @@ -22,8 +22,9 @@ . /etc/opt/openslx/openslx.conf PLUGINCONFROOT=${OPENSLX_DEFAULT_CONFDIR}/plugins PLUGINCONFDIR=${PLUGINCONFROOT}/vmchooser -# include general configuration from vmchooser -. ${PLUGINCONFDIR}/run-virt.include +# load general virtualization information +[ -f ${PLUGINCONFROOT}/virtualization/virtualization.conf ] && \ + . ${PLUGINCONFROOT}/virtualization/virtualization.conf # Sanity checks ################################################################################ diff --git a/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh new file mode 100644 index 00000000..8c241b8b --- /dev/null +++ b/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh @@ -0,0 +1,114 @@ +# Copyright (c) 2008..2010 - RZ Uni Freiburg +# Copyright (c) 2008..2010 - 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 +# +# script is included from init via the "." load function - thus it has all +# variables and functions available + +# virtual virtualization plugin +# make sure that this file is the same in vmgrid and vmchooser plugin! + +# include default directories +. /etc/openslx.conf + +CONFFILEVMCHOOSER="/initramfs/plugin-conf/vmchooser.conf" +CONFFILEVMGRID="/initramfs/plugin-conf/vmgrid.conf" +PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization + +# check if plugins available +active=0 +[ -f ${CONFFILEVMCHOOSER} ] && . ${CONFFILEVMCHOOSER} +[ -n "${CONFFILEVMCHOOSER}" ] && active=1 +[ -f ${CONFFILEVMGRID} ] && . ${CONFFILEVMGRID} +[ -n "${CONFFILEVMGRID}" ] && active=1 + +[ $DEBUGLEVEL -gt 0 ] \ + && echo "Executing the virtual 'virtualization' plugin ..." + +if [ ${active} -ne 0 ] ; then + + # load general configuration + . /etc/initramfs-setup + # include functions + . /etc/functions + + testmkd ${PLUGINCONFDIR} + + # check if vmgrid active and change free mem + totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ + | awk '{print $2}') / 1024) + echo "totalmem=${totalmem}" >> ${PLUGINCONFDIR}/virtualization.conf + if [ ${vmgrid_active} -ne 0 ]; then + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + if [ ${totalmemtest} -le 100 2>/dev/null ]; then + # get hostmem + freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) + freemem=$(expr ${totalmem} \* ${freememper} / 100) + echo "freemem=${freemem}" \ + >> ${PLUGINCONFDIR}/virtualization.conf + else + # more than 100% memory assigned stupid! + # vmgrid will get this as well and exit! + # so we have theoretically 100% free + echo "freemem=${totalmem}" \ + >> ${PLUGINCONFDIR}/virtualization.conf + fi + else + echo "freemem=${totalmem}" \ + >> ${PLUGINCONFDIR}/virtualization.conf +fi + + # cpu cores + CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l) + if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then + echo "cpu_cores=${CPU_CORES}" \ + >> ${PLUGINCONFDIR}/virtualization.conf + else + echo 'cpu_cores=1' >> ${PLUGINCONFDIR}/virtualization.conf + fi + + # arch + echo "host_arch=$(uname -m)" >> ${PLUGINCONFDIR}/virtualization.conf + + # VT enabled cpu? + if grep -q ^flags.*\\\<vmx\\\> /proc/cpuinfo; then + echo "vtflag=1" >> ${PLUGINCONFDIR}/virtualization.conf + echo 'kvm_module="kvm_intel"' >> ${PLUGINCONFDIR}/virtualization.conf + elif grep -q ^flags.*\\\<svm\\\> /proc/cpuinfo; then + echo "vtflag=1" >> ${PLUGINCONFDIR}/virtualization.conf + echo 'kvm_module="kvm_amd"' >> ${PLUGINCONFDIR}/virtualization.conf + else + echo "vtflag=0" >> ${PLUGINCONFDIR}/virtualization.conf + fi + + # get further hw information + waitfor /etc/hwinfo.cdrom + j=0 + for i in $(cat /etc/hwinfo.cdrom); do + echo "cdrom_$j=$i" >> ${PLUGINCONFDIR}/virtualization.conf + j=$(expr $j + 1) + done + + waitfor /etc/hwinfo.floppy + j=0 + for i in $(cat /etc/hwinfo.floppy); do + echo "floppy_$j=$i" >> ${PLUGINCONFDIR}/virtualization.conf + j=$(expr $j + 1) + done + + # finished ... + [ $DEBUGLEVEL -gt 0 ] \ + && echo " ok" +else + [ $DEBUGLEVEL -gt 0 ] \ + && echo " failed" +fi diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh index d9e35dfb..1d0c76be 100644 --- a/os-plugins/plugins/vmgrid/XX_vmgrid.sh +++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh @@ -96,29 +96,9 @@ if [ -f $CONFFILE ]; then chmod 1777 ${RWSHARE} echo "vmgrid_rwmnt=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf - # virtual virtualization plugin - testmkd ${VIRTUALIZATIONPLUGIN} - totalmemtest=$(expr $(echo ${vmgrid_memratio} \ - | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) - totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ - | awk '{print $2}') / 1024) - if [ ${totalmemtest} -le 100 2>/dev/null ]; then - # get hostmem - freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ - | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) - freemem=$(expr ${totalmem} \* ${freememper} / 100) - echo "virt_freemem=${freemem}" \ - >> ${VIRTUALIZATIONPLUGIN}/virtualization.conf - else - # more than 100% memory assigned stupid! - # vmgrid will get this as well and exit! - # so we have theoretically 100% free - echo "virt_freemem=${totalmem}" \ - >> ${VIRTUALIZATIONPLUGIN}/virtualization.conf - fi - # finished ... [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmgrid' os-plugin ..." fi -[ $DEBUGLEVEL -gt 0 ] && echo " * configuration of 'vmgrid' os-plugin failed" +else + [ $DEBUGLEVEL -gt 0 ] && echo " * configuration of 'vmgrid' os-plugin failed" fi diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index 626dfcca..bf10dc36 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -27,8 +27,9 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share # include general configuration from vmgrid [ -f ${PLUGINCONFVMGRID}/vmgrid.conf ] && \ . ${PLUGINCONFVMGRID}/vmgrid.conf -#[ -f ${PLUGINCONFVMGRID}/vmgrid.include ] && \ -# . ${PLUGINCONFVMGRID}/vmgrid.include +# load general virtualization information +[ -f ${PLUGINCONFROOT}/virtualization/virtualization.conf ] && \ + . ${PLUGINCONFROOT}/virtualization/virtualization.conf # get the vmchooser_active var [ -f ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ] && \ . ${PLUGINCONFROOT}/vmchooser/vmchooser.conf @@ -64,7 +65,8 @@ while [ $# -gt 0 ]; do headless=0 ;; --forcemem) - forcemem=$2 + # get a result which can be divided through 4 + forcemem=$(expr $2 / 4 \* 4) shift ;; *) @@ -281,7 +283,8 @@ if [ "${vmgrid_virt}" != "${xmlvirt}" ]; then fi # definition of the client system -vmostype=$(grep -io '<os param=.*"' ${xmlfile} | awk -F '"' '{ print $2 }') +vmostype=$(grep -io '<os param=.*"' ${xmlfile} | awk -F '"' '{ print $2 }' \ + | tr [A-Z] [a-z]) # definition of the networking the client system is connected to network_kind=$(grep -io 'network param=.*"' ${xmlfile} \ @@ -305,9 +308,9 @@ writelog "\tVM short name:\t\t$vm_shortname" # check for CPU virtualization flags #vmgrid::hvm -# get total amount of memory installed in your machine -totalmem=$(expr $(grep -i "memtotal" /proc/meminfo | awk '{print $2}') / 1024) +# total amount of memory defined in stage 3 permem=60 +# get a result which can be divided through 4 mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4) #vmgrid::maxram #vmgrid::minram @@ -350,7 +353,7 @@ writelog "\tVM Hostname:\t\t$hostname" # Get all virtual machine specific stuff from the respective include file # TODO: rename to run-vuirt.include if [ -e ${PLUGINCONFROOT}/${vmgrid_virt}/run-virt.include ] ; then - writelog "Strating ${vmgrid_virt} specific part ..." + writelog "Starting ${vmgrid_virt} specific part ..." self=${vmgrid_virt} . ${PLUGINCONFROOT}/${vmgrid_virt}/run-virt.include else diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid index b75b5341..ef86cb5a 100644 --- a/os-plugins/plugins/vmgrid/files/vmgrid +++ b/os-plugins/plugins/vmgrid/files/vmgrid @@ -44,6 +44,9 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share # include general configuration from vmgrid [ -f ${PLUGINCONFDIR}/vmgrid.conf ] && \ . ${PLUGINCONFDIR}/vmgrid.conf +# load general virtualization information +[ -f ${PLUGINCONFROOT}/virtualization/virtualization.conf ] && \ + . ${PLUGINCONFROOT}/virtualization/virtualization.conf # get the vmchooser_active var [ -f ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ] && \ . ${PLUGINCONFROOT}/vmchooser/vmchooser.conf @@ -77,11 +80,7 @@ echo "Starting to log at $(date)" \ vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s, *,,g") vmgrid_startvms=$(echo ${vmgrid_startvms} | sed -e "s, *,,g") -# get total amount of memory installed in your machine -# TODO: stage 3? virtaulization plugin -totalmem=$(expr $(grep -i "memtotal" /proc/meminfo | awk '{print $2}') / 1024) - -# get hostmem +# get hostmem, totalmem from stage 3 hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) if [ ${hostmem} -lt 256 2>/dev/null ]; then @@ -165,44 +164,3 @@ for i in {1..4}; do done exit 0 - -################################################################################ -### old stuff with xml files -################################################################################ -# -#filter_autostart=$(grep -i "active param" ${vmgrid_xmlpath}/*.xml | \ -# grep -E "true|1" | awk -F ":" '{print $1}') -# -## wozu mehrere starten -> siehe cherkasova -# -#filter_virt= -#for i in ${filter_autostart}; do -# filter_temp= -# filter_temp=$(cat $i | grep -i "virtualmachine param.*${vmgrid_virt}" | \ -# wc -l) -# if [ ${filter_temp} -eq 1 ]; then -# filter_virt="${filter_virt} $i" -# fi -#done -# -## remove already started ${vmgrid_startvm} -#filter_virt=$(echo $filter_virt | \ -# sed -e "s,${vmgrid_xmlpath}/${vmgrid_startvm%.xml}.xml,,g") -# -#sort_virt=$(grep 'priority param' ${vmgrid_xmlpath}/*.xml | sort -n | \ -# awk -F ":" '{print $1}') -# -#for i in ${sort_virt}; do -# j=$(echo $filter_virt | grep $i | wc -l) -# if [ $j -eq 1 ]; then -# filter_virt=$(echo $filter_virt | sed -e "s,$i,,g") -# vmgrid ${i#${vmgrid_xmlpath}/} -# fi -#done -# -## start vms /wo priority -#for i in ${filter_virt}; do -# vmgrid ${i#${vmgrid_xmlpath}/} -#done -# -#exit 0 diff --git a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh new file mode 100644 index 00000000..8c241b8b --- /dev/null +++ b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh @@ -0,0 +1,114 @@ +# Copyright (c) 2008..2010 - RZ Uni Freiburg +# Copyright (c) 2008..2010 - 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 +# +# script is included from init via the "." load function - thus it has all +# variables and functions available + +# virtual virtualization plugin +# make sure that this file is the same in vmgrid and vmchooser plugin! + +# include default directories +. /etc/openslx.conf + +CONFFILEVMCHOOSER="/initramfs/plugin-conf/vmchooser.conf" +CONFFILEVMGRID="/initramfs/plugin-conf/vmgrid.conf" +PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization + +# check if plugins available +active=0 +[ -f ${CONFFILEVMCHOOSER} ] && . ${CONFFILEVMCHOOSER} +[ -n "${CONFFILEVMCHOOSER}" ] && active=1 +[ -f ${CONFFILEVMGRID} ] && . ${CONFFILEVMGRID} +[ -n "${CONFFILEVMGRID}" ] && active=1 + +[ $DEBUGLEVEL -gt 0 ] \ + && echo "Executing the virtual 'virtualization' plugin ..." + +if [ ${active} -ne 0 ] ; then + + # load general configuration + . /etc/initramfs-setup + # include functions + . /etc/functions + + testmkd ${PLUGINCONFDIR} + + # check if vmgrid active and change free mem + totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ + | awk '{print $2}') / 1024) + echo "totalmem=${totalmem}" >> ${PLUGINCONFDIR}/virtualization.conf + if [ ${vmgrid_active} -ne 0 ]; then + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + if [ ${totalmemtest} -le 100 2>/dev/null ]; then + # get hostmem + freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) + freemem=$(expr ${totalmem} \* ${freememper} / 100) + echo "freemem=${freemem}" \ + >> ${PLUGINCONFDIR}/virtualization.conf + else + # more than 100% memory assigned stupid! + # vmgrid will get this as well and exit! + # so we have theoretically 100% free + echo "freemem=${totalmem}" \ + >> ${PLUGINCONFDIR}/virtualization.conf + fi + else + echo "freemem=${totalmem}" \ + >> ${PLUGINCONFDIR}/virtualization.conf +fi + + # cpu cores + CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l) + if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then + echo "cpu_cores=${CPU_CORES}" \ + >> ${PLUGINCONFDIR}/virtualization.conf + else + echo 'cpu_cores=1' >> ${PLUGINCONFDIR}/virtualization.conf + fi + + # arch + echo "host_arch=$(uname -m)" >> ${PLUGINCONFDIR}/virtualization.conf + + # VT enabled cpu? + if grep -q ^flags.*\\\<vmx\\\> /proc/cpuinfo; then + echo "vtflag=1" >> ${PLUGINCONFDIR}/virtualization.conf + echo 'kvm_module="kvm_intel"' >> ${PLUGINCONFDIR}/virtualization.conf + elif grep -q ^flags.*\\\<svm\\\> /proc/cpuinfo; then + echo "vtflag=1" >> ${PLUGINCONFDIR}/virtualization.conf + echo 'kvm_module="kvm_amd"' >> ${PLUGINCONFDIR}/virtualization.conf + else + echo "vtflag=0" >> ${PLUGINCONFDIR}/virtualization.conf + fi + + # get further hw information + waitfor /etc/hwinfo.cdrom + j=0 + for i in $(cat /etc/hwinfo.cdrom); do + echo "cdrom_$j=$i" >> ${PLUGINCONFDIR}/virtualization.conf + j=$(expr $j + 1) + done + + waitfor /etc/hwinfo.floppy + j=0 + for i in $(cat /etc/hwinfo.floppy); do + echo "floppy_$j=$i" >> ${PLUGINCONFDIR}/virtualization.conf + j=$(expr $j + 1) + done + + # finished ... + [ $DEBUGLEVEL -gt 0 ] \ + && echo " ok" +else + [ $DEBUGLEVEL -gt 0 ] \ + && echo " failed" +fi |