From 1f031fbafab207fe0879217ae9215caea783ed00 Mon Sep 17 00:00:00 2001 From: Michael Janczyk Date: Wed, 24 Mar 2010 20:01:46 +0100 Subject: new run-virt.include for xen plugin. qemukvm modules now loaded via runlevelscript qemukvm, script added to sudoers as well. better ideas? --- .../plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm | 27 +- os-plugins/plugins/qemukvm/XX_qemukvm.sh | 42 +-- .../plugins/virtualbox/files/run-virt.include | 4 +- os-plugins/plugins/vmchooser/files/run-virt.sh | 2 + os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 36 ++- os-plugins/plugins/xen/XX_xen.sh | 5 +- os-plugins/plugins/xen/files/hvm.include | 209 ++++++++++++++ os-plugins/plugins/xen/files/machine.include | 114 +++----- os-plugins/plugins/xen/files/run-virt.include | 318 +++++---------------- 9 files changed, 403 insertions(+), 354 deletions(-) create mode 100644 os-plugins/plugins/xen/files/hvm.include diff --git a/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm b/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm index 8029102c..203a7ed3 100644 --- a/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm +++ b/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm @@ -133,11 +133,6 @@ sub installationPhase copyFile("$pluginBasePath/$file", "$pluginRepoPath/"); } chmod 0755, "$pluginRepoPath/ifup", "$pluginRepoPath/ifdown"; -# # Create kvm link -# my $kvmPath = pathOf('qemu-kvm') || pathOf('kvm') || pathOf('qemu'); -# if (defined $kvmPath) { -# linkFile($kvmPath, "$pluginRepoPath/qemukvm") -# } my $initFile = newInitFile(); $initFile->setName("qemukvm"); @@ -146,7 +141,24 @@ sub installationPhase # TODO: default dirs als globale funktion anbieten $initFile-> addToBlock('head','. /etc/opt/openslx/plugins/qemukvm/network.conf'); + + # TODO: remove all runlevel links for qemu-kvm or kvm + my $kvm_module = unshiftHereDoc(<<' End-of-Here'); + # Figure out which module we need. + if grep -q ^flags.*\\\ /proc/cpuinfo; then + module=kvm_intel + elif grep -q ^flags.*\\\ /proc/cpuinfo; then + module=kvm_amd + else + unset module + fi + End-of-Here + my $do_start = unshiftHereDoc(<<' End-of-Here'); + # loading kvm module + [ -n "${module}" ] && modprobe -q ${module} + # load the tunnel device module + modprobe -q tun # configuring the tap0 interface to the existing bridge configured in stage3 for i in 0 1 2; do /opt/openslx/uclib-rootfs/sbin/tunctl -t tap${i} >/dev/null 2>&1 @@ -157,10 +169,14 @@ sub installationPhase ip addr add ${hoaddress} dev tap2 echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding echo "1" >/proc/sys/net/ipv4/conf/tap0/forwarding + # make /dev/fb0 writable for all # TODO: maybe solve via group or udev, etc... chmod 766 /dev/fb* End-of-Here + my $do_stop = unshiftHereDoc(<<' End-of-Here'); + [ -n "${module}" ] && modprobe -q -r ${module} + modprobe -q -r tun /opt/openslx/uclib-rootfs/usr/sbin/brctl delif br0 tap0 ip addr del ${nataddress} dev tap1 ip addr del ${hoaddress} dev tap2 @@ -168,6 +184,7 @@ sub installationPhase echo "0" >/proc/sys/net/ipv4/conf/tap0/forwarding chmod 760 /dev/fb* End-of-Here + my $do_restart = unshiftHereDoc(<<' End-of-Here'); do_stop && do_start End-of-Here diff --git a/os-plugins/plugins/qemukvm/XX_qemukvm.sh b/os-plugins/plugins/qemukvm/XX_qemukvm.sh index b3c4ccf0..2a907861 100644 --- a/os-plugins/plugins/qemukvm/XX_qemukvm.sh +++ b/os-plugins/plugins/qemukvm/XX_qemukvm.sh @@ -39,27 +39,27 @@ if [ -e ${CONFFILE} ]; then cp /mnt/${PLUGINDIR}/run-virt.include ${PLUGINCONFDIR} cp ${CONFFILE} ${PLUGINCONFDIR} - # check for the virtualization CPU features - if grep -q "vmx" /proc/cpuinfo && modprobe ${MODPRV} kvm_intel ; then - [ $DEBUGLEVEL -gt 0 ] && echo " * Loaded kvm_intel module" - echo "kvm=intel" >> ${PLUGINCONFDIR}/qemukvm.conf - elif grep -q "svm" /proc/cpuinfo && modprobe ${MODPRV} kvm_amd ; then - [ $DEBUGLEVEL -gt 0 ] && echo " * Loaded kvm_amd module" - echo "kvm=amd" >> ${PLUGINCONFDIR}/qemukvm.conf - elif modprobe ${MODPRV} kqemu ; then - [ $DEBUGLEVEL -gt 0 ] && \ - error " * Successfully loaded the kqemu module, but loading of kvm_amd \ -or kvm_intel\n failed, because no virtualization extenstion found in this \ -CPU. Please\n enable the extension within your machines BIOS or get another \ -CPU." nonfatal - else - error " * All module loading failed including the kqemu module, which \ -was either\n not found or couldn't be loaded for other reasons. Thus using \ -qemu(-kvm)\n makes not much sense." nonfatal - fi +# # check for the virtualization CPU features +# if grep -q "vmx" /proc/cpuinfo && modprobe ${MODPRV} kvm_intel ; then +# [ $DEBUGLEVEL -gt 0 ] && echo " * Loaded kvm_intel module" +# echo "kvm=intel" >> ${PLUGINCONFDIR}/qemukvm.conf +# elif grep -q "svm" /proc/cpuinfo && modprobe ${MODPRV} kvm_amd ; then +# [ $DEBUGLEVEL -gt 0 ] && echo " * Loaded kvm_amd module" +# echo "kvm=amd" >> ${PLUGINCONFDIR}/qemukvm.conf +# elif modprobe ${MODPRV} kqemu ; then +# [ $DEBUGLEVEL -gt 0 ] && \ +# error " * Successfully loaded the kqemu module, but loading of kvm_amd \ +#or kvm_intel\n failed, because no virtualization extenstion found in this \ +#CPU. Please\n enable the extension within your machines BIOS or get another \ +#CPU." nonfatal +# else +# error " * All module loading failed including the kqemu module, which \ +#was either\n not found or couldn't be loaded for other reasons. Thus using \ +#qemu(-kvm)\n makes not much sense." nonfatal +# fi - # load the tunnel device module - modprobe tun 2>/dev/null +# # load the tunnel device module +# modprobe tun 2>/dev/null # get source of qemukvm image server (get type, server and path) if strinstr "/" "${qemukvm_imagesrc}" ; then @@ -100,6 +100,8 @@ ${qemukvm_imagesrc}." nonfatal done #killall=$(binfinder killall) cat >> /mnt/etc/sudoers << EOF +# allow to start and stop kvm services / load-/unload kvm modules +ALL ALL=NOPASSWD: /etc/init.d/qemukvm # TODO: check if kvm / qemu sufficient #ALL ALL=NOPASSWD: ${killall} udhcpd #ALL ALL=NOPASSWD: ${PLUGINDIR}/ifup diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include index 27289b41..e3650ebd 100644 --- a/os-plugins/plugins/virtualbox/files/run-virt.include +++ b/os-plugins/plugins/virtualbox/files/run-virt.include @@ -41,9 +41,7 @@ export VBOX_USER_HOME=${confdir} RMDIRS="${snapshotdir} ${confdir} /tmp/.vbox-${USER}-ipc" 2>/dev/null rm -rf ${RMDIRS} 2>/dev/null 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") +# 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" snapshotdir=${machfolder}/${vm_shortname}/Snapshots diff --git a/os-plugins/plugins/vmchooser/files/run-virt.sh b/os-plugins/plugins/vmchooser/files/run-virt.sh index 6df6bf84..38dd5ac6 100644 --- a/os-plugins/plugins/vmchooser/files/run-virt.sh +++ b/os-plugins/plugins/vmchooser/files/run-virt.sh @@ -69,6 +69,8 @@ vm_name=$(grep -o "short_description param=.*\"" ${xml} | \ # If ${short_description} not defined use ${image_name} # if ${vm_name} not defined use ${imgname} vm_name=${vm_name:-"${imgname%.*}"} +# define vm_shortname since vm_name can be very long +vm_shortname=$(echo ${imgname%.*} | sed -e "s, ,-,g") displayname=${vm_name} # remove blanks vm_name=$(echo ${vm_name} | sed -e "s, ,-,g") diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index 8d199ccf..ce707830 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -131,10 +131,10 @@ writelog "Starting configuration..." writelog "\tVM-ID:\t\t\t${VM_ID}" writelog "\tLogfile:\t\t${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log" writelog "\t$(df -h | grep " /tmp$" | awk '{print $2}') \c" -writelog "/tmp info:\t\t$(grep "/tmp " /proc/mounts | sed -e "s,/tmp ,,")" +writelog "\t/tmp info:\t\t$(grep "/tmp " /proc/mounts) $(df -h | \ + grep " /tmp$" | awk '{print $2}')" writelog "\tVM XML dir:\t\t${vmgrid_xmlpath}" writelog "\tVM Image dir:\t\t${vmgrid_imgpath}" -writelog "VM config:" if ! grep '/dev/null 2>&1; then writelog \ @@ -143,13 +143,18 @@ if ! grep '/dev/null 2>&1; then fi writelog "\tXML file:\t\t$xmlfile" +writelog "VM config:" -imgpath=${vmgrid_imgpath} - -# name of the virt image of dir -imgname=$(grep -io 'image_name param=.*"' ${xmlfile} | sed -e "s/&.*;/; /g" | \ - awk -F '"' '{ print $2 }') -# full path +# name of the virt image or dir +imgname=$(grep -io '/dev/null | grep '/' >/dev/null 2>&1; then + imgpath=$(dirname ${imgname}) + imgname=$(basename ${imgname}) +else + imgpath=${vmgrid_imgpath} +fi +# set default v path vmpath=${imgpath}/${imgname} # check if virtual machine container file exists @@ -163,16 +168,17 @@ writelog "\tVM file/dir:\t\t$vmpath" # name of the virt machine, sed because of Windows formatting vm_name=$(grep -o 'short_description param=.*"' ${xmlfile} | \ sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') +# if ${vm_name} not defined use ${imgname} +vm_name=${vm_name:-"${imgname%.*}"} +# define vm_shortname since vm_name can be very long +vm_shortname=$(echo ${imgname%.*} | sed -e "s, ,-,g") +# vm_name = displayname, define for old scripts +displayname=${vm_name} # is there an additional configuration provided? additional_config=$(grep -o 'additional_config param=.*"' ${xmlfile} | \ sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') -# if ${vm_name} not defined use ${imgname} -vm_name=${vm_name:-"${imgname%.*}"} -displayname=${vm_name} -# remove blanks - # image is for the following virtual machine xmlvirt=$(grep -o 'virtualmachine param=.*"' ${xmlfile} | \ sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') @@ -231,8 +237,8 @@ network_card=$(grep -io 'netcard param=.*"' ${xmlfile} | \ awk -F '"' '{ print $2 }') writelog "\tVirtualization:\t\t$xmlvirt" -writelog "\tVM Name:\t\t$vm_name" -writelog "\tVM Displayname:\t\t$displayname" +writelog "\tVM name:\t\t$vm_name" +writelog "\tVM short name:\t\t$vm_shortname" ############################################################################### ### Declaration of default variables diff --git a/os-plugins/plugins/xen/XX_xen.sh b/os-plugins/plugins/xen/XX_xen.sh index 82142a61..d3620c76 100644 --- a/os-plugins/plugins/xen/XX_xen.sh +++ b/os-plugins/plugins/xen/XX_xen.sh @@ -26,8 +26,9 @@ if [ -e ${CONFFILE} ]; then testmkd /mnt/var/run/xend testmkd /mnt/var/run/xenstored - rllinker "xendomains" 14 8 - rllinker "xend" 13 9 +# TODO: disable for testing purposes. suse 11.0 kills network +# rllinker "xendomains" 14 8 +# rllinker "xend" 13 9 modprobe loop max_loop=64 fi diff --git a/os-plugins/plugins/xen/files/hvm.include b/os-plugins/plugins/xen/files/hvm.include new file mode 100644 index 00000000..beb9315a --- /dev/null +++ b/os-plugins/plugins/xen/files/hvm.include @@ -0,0 +1,209 @@ +# This is an machine template for run-virt.include of the Xen plugin. +# This template was taken from an example in openSUSE 11.2 +# HVM template + +cat < 1 +#apic=1 + +# Enable/disable extended power management support within HVM guest, i.e., beyond +# S3, S4, S5 within guest like exposing battery meter. +# 0 (default option, extended power management support disabled) +# 1 (pass-through mode; uses pass-through as needed; efficient but limited in scope) +# 2 (non pass-through mode; extended scope, likely to work on all applicable environment +# but comparitively less efficient than pass-through mode) +# xen_extended_power_mgmt=0 + +# List of which CPUS this domain is allowed to use, default Xen picks +#cpus = "" # leave to Xen to pick +#cpus = "0" # all vcpus run on CPU0 +#cpus = "0-3,5,^1" # all vcpus run on cpus 0,2,3,5 +#cpus = ["2", "3"] # VCPU0 runs on CPU2, VCPU1 runs on CPU3 + +#---------------------------------------------------------------------------- +# Optionally define mac and/or bridge for the network interfaces. +# Random MACs are assigned if not given. +#vif = [ 'type=ioemu, mac=00:16:3e:00:00:11, bridge=xenbr0, model=ne2k_pci' ] +# type=ioemu specify the NIC is an ioemu device not netfront +#vif = [ 'type=ioemu, bridge=xenbr0' ] +vif = [ '${xen_vif}' ] + +#---------------------------------------------------------------------------- +# Define the disk devices you want the domain to have access to, and +# what you want them accessible as. +# Each disk entry is of the form phy:UNAME,DEV,MODE +# where UNAME is the device, DEV is the device name the domain will see, +# and MODE is r for read-only, w for read-write. +#disk = [ 'phy:hda1,hda1,r' ] +#disk = [ 'file:/var/lib/xen/images/disk.img,ioemu:hda,w', ',hdc:cdrom,r' ] +disk = [ '${xen_disk}' ] + +#---------------------------------------------------------------------------- +# Configure the behaviour when a domain exits. There are three 'reasons' +# for a domain to stop: poweroff, reboot, and crash. For each of these you +# may specify: +# "destroy", meaning that the domain is cleaned up as normal; +# "restart", meaning that a new domain is started in place of the old +# one; +# "preserve", meaning that no clean-up is done until the domain is +# manually destroyed (using xm destroy, for example); or +# "rename-restart", meaning that the old domain is not cleaned up, but is +# renamed and a new domain started in its place. +# In the event a domain stops due to a crash, you have the additional options: +# "coredump-destroy", meaning dump the crashed domain's core and then destroy; +# "coredump-restart', meaning dump the crashed domain's core and the restart. +# The default is +# on_poweroff = 'destroy' +# on_reboot = 'restart' +# on_crash = 'restart' +#on_poweroff = 'destroy' +#on_reboot = 'restart' +#on_crash = 'restart' + +#============================================================================ +# HVM specific +#============================================================================ +# Device Model to be used +device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm' + +#----------------------------------------------------------------------------- +# boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d) +# default: hard disk, cd-rom, floppy +#boot="cda" + +#----------------------------------------------------------------------------- +# write to temporary files instead of disk image files +#snapshot=1 + +#---------------------------------------------------------------------------- +# enable SDL library for graphics, default = 0 +sdl=0 + +#---------------------------------------------------------------------------- +# enable OpenGL for texture rendering inside the SDL window, default = 1 +# valid only if sdl is enabled. +opengl=1 + +#---------------------------------------------------------------------------- +# enable VNC library for graphics, default = 1 +vnc=1 + +#---------------------------------------------------------------------------- +# address that should be listened on for the VNC server if vnc is set. +# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp +#vnclisten="127.0.0.1" + +#---------------------------------------------------------------------------- +# set VNC display number, default = domid +#vncdisplay=1 + +#---------------------------------------------------------------------------- +# try to find an unused port for the VNC server, default = 1 +#vncunused=1 + +#---------------------------------------------------------------------------- +# set password for domain's VNC console +# default is depents on vncpasswd in xend-config.sxp +vncpasswd='' + +#---------------------------------------------------------------------------- +# no graphics, use serial port +#nographic=0 + +#---------------------------------------------------------------------------- +# enable stdvga, default = 0 (use cirrus logic device model) +stdvga=0 + +#----------------------------------------------------------------------------- +# serial port re-direct to pty deivce, /dev/pts/n +# then xm console or minicom can connect +serial='pty' + + +#----------------------------------------------------------------------------- +# Qemu Monitor, default is disable +# Use ctrl-alt-2 to connect +#monitor=1 + + +#----------------------------------------------------------------------------- +# enable sound card support, [sb16|es1370|all|..,..], default none +#soundhw='sb16' + + +#----------------------------------------------------------------------------- +# set the real time clock to local time [default=0 i.e. set to utc] +#localtime=1 + + +#----------------------------------------------------------------------------- +# set the real time clock offset in seconds [default=0 i.e. same as dom0] +#rtc_timeoffset=3600 + +#----------------------------------------------------------------------------- +# start in full screen +#full-screen=1 + + +#----------------------------------------------------------------------------- +# Enable USB support (specific devices specified at runtime through the +# monitor window) +#usb=1 +# Enable USB mouse support (only enable one of the following, `mouse' for +# PS/2 protocol relative mouse, `tablet' for +# absolute mouse) +#usbdevice='mouse' +#usbdevice='tablet' + +#----------------------------------------------------------------------------- +# Set keyboard layout, default is en-us keyboard. +#keymap='de' + +#----------------------------------------------------------------------------- +# Enable/disable xen platform PCI device, default=1 (enabled) +#xen_platform_pci=1 + +#============================================================================ +EOF diff --git a/os-plugins/plugins/xen/files/machine.include b/os-plugins/plugins/xen/files/machine.include index 93adca75..a1573578 100644 --- a/os-plugins/plugins/xen/files/machine.include +++ b/os-plugins/plugins/xen/files/machine.include @@ -1,62 +1,55 @@ +# This is an machine template for run-virt.include of the Xen plugin. +# This template was taken from an example in openSUSE 11.2 + +cat </dev/null +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} +confdir="/tmp/${self}/${USER}/${VM_ID}" +# use vm_shortname for VM name since vm_name can be very long +vm_name=${vm_shortname} +conffile=${confdir}/${vm_name} # define dirs and files which can be removed after exit, be carefull! -#RMDIRS="${snapshotdir} ${confdir} /tmp/.vbox-${USER}-ipc" 2>/dev/null -#rm -rf ${RMDIRS} 2>/dev/null -#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 -#diskfile="${diskfolder}/${imgname}" -#mkdir -p ${diskfolder} ${snapshotdir} 2>/dev/null -#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), exiting!" #vmdk|vhd -# exit 1 -#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" -# +RMDIRS="${confdir}" 2>/dev/null +rm -rf ${RMDIRS} 2>/dev/null + +# TODO: read from XML file +xen_kernel=/boot/vmlinuz-xen +xen_ramdisk=/initrd-xen +xen_root=/dev/sda1 +xen_extra=3 +xen_disk="file:${vmpath},sda1,r" +xen_vif="mac=$macaddr, bridge=xenbr0" +xen_dhcp="dhcp" # off + +writelog "Directories:" +writelog "\tConfig dir:\t\t$confdir" + ################################################################################ ### Hardware checks ################################################################################ -# -# remove ':' from MAC addr for vbox -#macaddr=$(echo ${macaddr} | sed 's/://g') -# -# 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 -#if [ -n "${forcemem}" ]; then -# mem="${forcemem}" -#else -# 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 -# # 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 -# -# 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"' -# ;; -# hostonly|host-only) -# network_kind='HostOnlyInterface name="vboxnet0"' -# ;; -# *) -# network_kind="NAT" -# ;; -#esac -# -# external GUI -#vrdpport="590${VM_ID}" -# -# TODO: nur bei vmchooser -# 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= -#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" -# -#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" +if [ -n "${forcemem}" ]; then + mem="${forcemem}" +else + 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 + # 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 + +writelog "Diskimage:" +writelog "\tMachine diskfile:\t\t$vmpath" +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}" -# 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}" -# +[ -n "${memhost}" ] && writelog "\tHost RAM:\t\t${memhost} MB" +writelog "\tMAC address:\t\t$macaddr" + ################################################################################ ### Pepare and configure virtual machine and disk image ################################################################################ -# -# TODO: date wichtig? -#date="$(date +%Y-%m-%dT%H:%M:%SZ)" -#. ${PLUGINCONFVIRTUALBOX}/virtualbox.include >"${VBOX_USER_HOME}/VirtualBox.xml" -# -# 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 -# -# add ssh port if linux and NAT -#if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then -# vmsshport="220${VM_ID}" -# extradataitem='" -# extradataprotocol='Protocol" value="TCP"/>' -# sed -i "s,, ${extradataitem}${extradataguestport}\n\ -# ${extradataitem}${extradatahostport}\n\ -# ${extradataitem}${extradataprotocol}\n\ -# ," "${machconfig}" -# writelog "\tGuest SSH port:\t\t${vmsshport}" -#fi -# -#cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/virtualbox/empty-diff.vdi.gz | \ -# gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi" -# + +. ${PLUGINCONFXEN}/machine.include > ${conffile} + ################################################################################ ### 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 -# + # set the variables appropriately (several interfaces with different names) -#VIRTCMD=$(which VirtualBox 2>/dev/null) -#VIRTCMDOPTS="--startvm ${machineuuid} --start-running" -# -# SDL tests -#VIRTCMDSDL=$(which VBoxSDL 2>/dev/null) -#VIRTCMDOPTSSDL="--startvm ${machineuuid} --fullscreen --hwvirtex --memory 1024 \ -# --fixedmode 1680 1050 24 --hostkey 302 0" -# +VIRTCMD=$(which xm 2>/dev/null) +VIRTCMDOPTS="create ${conffile}" + # set headless mode -#VIRTCMDHL=$(which VBoxHeadless 2>/dev/null) -#VIRTCMDOPTSHL="-s ${machineuuid}" +VIRTCMDHL=$(which xm 2>/dev/null) +VIRTCMDOPTSHL="create ${conffile}" -- cgit v1.2.3-55-g7522