summaryrefslogblamecommitdiffstats
path: root/src/os-plugins/plugins/vmware/XX_vmware.sh
blob: 191d92dbdca685262708e9553fa2e797f5753f45 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                            
                                         








                                                                         

                                                                          
 



                                              
                       

                                                                           
 



                                      


                                                        

                                       
                                              
                                                  
 

                                      
 

                                                                     
                                   
 
                                                                         

                                
 
                                     
                                
                                    
                            
                                  
 
                                                 
                                                                  


                                                                        
                                                 
                                                                             
                                            
                                      
                                                        
      
 

                                                            

                                                                       
                                                         

                                                                          

                                                                              




                                                                                 
                                                         

                                                               
                                                                    
                                                             
                                     

                                    
      
 
                                        
                                     
                                        
                                    




                                                                                
                                                                 





                                                                                 



                                                
                                   




                                      
                       
                                   
                              




                                   

                                                                 
                                                                  
                                                                               
                                                                    
                                        
                              
 
                                                                                


                                                                   
 


                                                                   

                                                      
      
                                                                         
                                 




                                                                              

      
                                                                                
                                                          


                                                    
 

                                                                

                                                            

              
                          
 

                                                      
                                                              



                                                                  
                                                               
                                                                  

                               
 

                                                     
                                  


                                                              
      
 

                                                                   
                                                                   
                                    
                                                              

                                                                              
 
                                                                              

                                                  

                                                                    

                                                 
       
                                                                    
 
    

                                                                           
  
# Copyright (c) 2007..2009 - RZ Uni Freiburg
# Copyright (c) 2008..2012 - 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

# TODO:
# configs nach /etc/opt/openslx/plugins/vmware
# cp nach run-virt.include

# TODO: nvram,functions
# write /etc/vmware/config (if a non-standard location of vmware basedir is
# to be configured), /etc/init.d/vmware

# include default directories
. /etc/openslx.conf

ETCDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}
PLUGINCONFDIR=${ETCDIR}/plugins/vmware
BINDIR=/mnt/${OPENSLX_DEFAULT_BINDIR}
PLUGINDIR=/mnt/${OPENSLX_DEFAULT_DIR}/plugin-repo/vmware
VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR}

# check if the configuration file is available
if [ -e /initramfs/plugin-conf/vmware.conf ]; then

  # load needed variables
  . /initramfs/plugin-conf/vmware.conf

  # Test if this plugin is activated... more or less useless with the
  # new plugin system
  if [ $vmware_active -ne 0 ]; then

    [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'vmware' os-plugin ...";
    # Load general configuration
    . /initramfs/machine-setup

    testmkd /mnt/tmp/virt/vmware 1777
    testmkd /dev/shm/vmware 1777
    testmkd /mnt/var/run/vmware 1777
    testmkd ${PLUGINCONFDIR}
    testmkd /mnt/etc/vmware/udhcpd

    # write the ${PLUGINCONFDIR}/vmware.conf file
    # check for the several variables and write the several files:
    #   dhcpd.conf for vmnet* interfaces
    #   nat.conf for the NAT configuration of vmnet8
    # TODO: vmnet-natd-8.mac not clear if really needed and which mac it
    # should contain (seems to be an average one)
    echo -e "# configuration file for vmware background services written in \
stage3 setup" > ${PLUGINCONFDIR}/vmware.conf
    if [ "$vmware_bridge" = 1 ] ; then
      echo "vmnet0=true" >> ${PLUGINCONFDIR}/vmware.conf
    fi

    # variable might contain ",NAT" which is to be taken off
    if [ -n "$vmware_vmnet1" ] ; then
      local vmnet1=${vmware_vmnet1%,*} # x.x.x.x/yy,NAT => 'x.x.x.x/yy'
      local vmnat=${vmware_vmnet1#$vmnet1*} # x.x.x.x/yy,NAT => ',NAT'
      local vmip=${vmnet1%/*} # x.x.x.x/yy => 'x.x.x.x'">
      local vmpx=${vmnet1#*/} # x.x.x.x/yy => 'yy'
      local vmsub=$(echo $vmip |sed 's,\(.*\)\..*,\1,') # x.x.x.x => x.x.x
      echo -e "vmnet1=$vmnet1" >> ${PLUGINCONFDIR}/vmware.conf
      [ -n "$vmnat" ] && echo "vmnet1nat=true" >> ${PLUGINCONFDIR}/vmware.conf
      # setting up the udhcpd configuration
      sed -e "s,NWIF,vmnet1,;s,/misc/,/vmware/," \
          -e "s,CNETWORK,$vmsub,;s,PIDFILE,/var/run/vmware/udhcpd-vmnet1.pid," \
          -e "s,LEASEFILE,/var/run/vmware/udhcpd-vmnet1.leases," \
      /mnt/etc/opt/openslx/udhcpd.conf >/mnt/etc/vmware/udhcpd/udhcpd-vmnet1.conf
      # setting the base samba configuration if available
      if [ -f /mnt/opt/openslx/plugin-repo/vmchooser/smb.conf \
        -a -f /mnt/usr/sbin/smbd ] ; then
          sed -e "s#NWIF#vmnet1,vmnet8#;s,PIDDIR,/var/run/vmware," \
            /mnt/opt/openslx/plugin-repo/vmchooser/smb.conf \
            >/mnt/etc/vmware/smb.conf
          testmkd /mnt/var/log/samba
      fi
    fi

    # vmware nat interface configuration
    if [ -n "$vmware_vmnet8" ] ; then
      local vmnet8ip=${vmware_vmnet8%/*}
      local vmpx=${vmware_vmnet8#*/}
      local vmsub=$(echo $vmnet8ip |sed 's,\(.*\)\..*,\1,') # x.x.x.x => x.x.x">
      # vmip is user for vmnet8 device
      # vmnet is user for config files nat.conf/dhcp
      local vmip="${vmsub}.1"
      local vmnet="${vmsub}.2"
      echo -e "vmnet8=$vmip/$vmpx" >>${PLUGINCONFDIR}/vmware.conf
      # setting up the udhcpd configuration
      sed -e "s,NWIF,vmnet8,;s,/misc/,/vmware/," \
          -e "s,CNETWORK,$vmsub,;s,PIDFILE,/var/run/vmware/udhcpd-vmnet8.pid," \
          -e "s,LEASEFILE,/var/run/vmware/udhcpd-vmnet8.leases," \
      /mnt/etc/opt/openslx/udhcpd.conf >/mnt/etc/vmware/udhcpd/udhcpd-vmnet8.conf
      # might be not needed any more ...
      echo -e "# Linux NAT configuration file" \
        > /mnt/etc/vmware/nat.conf
      echo -e "[host]" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "ip = $vmnet/$vmpx" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "device = /dev/vmnet8" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "activeFTP = 1" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "[udp]" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "timeout = 60" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "[incomingtcp]" \
        >> /mnt/etc/vmware/nat.conf
      echo -e "[incomingudp]" \
        >> /mnt/etc/vmware/nat.conf
      echo "00:50:56:F1:30:50" > /mnt/etc/vmware/vmnet-natd-8.mac
    fi
    # copy the runlevel script to the proper place and activate it
    sed "s/eth0/$nwif/g" ${PLUGINDIR}/vmware-slx > /mnt/etc/init.d/vmware-env \
      || echo "  * Error copying runlevel script. Shouldn't happen."
    chmod a+x /mnt/etc/init.d/vmware-env
    rllinker "vmware-env" 20 2

    ############################################################################
    # vmware stuff first part: two scenarios
    # * VM images in /usr/share/vmware - then simply link
    # * VM images via additional mount (mount source NFS, NBD, ...)

    # get source of vmware image server (get type, server and path)
    if strinstr "/" "${vmware_imagesrc}" ; then
      vmimgprot=$(uri_token ${vmware_imagesrc} prot)
      vmimgserv=$(uri_token ${vmware_imagesrc} server)
      vmimgpath="$(uri_token ${vmware_imagesrc} path)"
    fi
    if [ -n "${vmimgserv}" -a -n ${vmimgpath} -a -n ${vmimgprot} ] ; then
      mnttarget=${VIRTDIR}/vmware
      # mount the vmware image source readonly (ro)
      fsmount ${vmimgprot} ${vmimgserv} ${vmimgpath} ${mnttarget} ro
    else
      [ $DEBUGLEVEL -gt 1 ] && error "  * Incomplete information in variable \
${vmware_imagesrc}." nonfatal
    fi
    
    ############################################################################
    # vmware stuff second part: setting up the environment
    # make udhcpd more silent
    touch /mnt/var/run/vmware/udhcpd-vmnet1.leases \
          /mnt/var/run/vmware/udhcpd-vmnet8.leases

    # create the needed devices which effects all vmware options
    # they are not created automatically via module load
    for i in "/dev/vmnet0 c 119 0" "/dev/vmnet1 c 119 1" \
             "/dev/vmnet8 c 119 8" "/dev/vmmon c 10 165"; do
      mknod $i
    done
    chmod 0700 /dev/vmnet*

    # allow VMware swapping if RamZSWAP is enabled
    if grep -E "^ramzswap.*1 -.*" /proc/modules ; then
      echo -e '.encoding = "UTF-8"\nprefvmx.minVmMemPct = "75"
prefvmx.useRecommendedLockedMemSize = "TRUE"' | sed -e "s/^ *//" \
        >/mnt/etc/vmware/config
    else
    # disable VMware swapping else
      echo -e '.encoding = "UTF-8"\nprefvmx.minVmMemPct = "100"
prefvmx.useRecommendedLockedMemSize = "TRUE"' | sed -e "s/^ *//" \
        >/mnt/etc/vmware/config
    fi

    # copy virtualization include files to config dir
    cp ${PLUGINDIR}/run-virt.include ${PLUGINCONFDIR}
    # copy version depending files
    cp ${PLUGINDIR}/${vmware_kind}/vmplayer ${BINDIR}/vmplayer
    if [ -e ${PLUGINDIR}/${vmware_kind}/vmware ]; then
      cp ${PLUGINDIR}/${vmware_kind}/vmware ${BINDIR}/vmware
    fi

    # affects only kernel and config depending configuration of not
    # local installed versions
    cat ${PLUGINDIR}/${vmware_kind}/config >>/mnt/etc/vmware/config
    chmod 644 /mnt/etc/vmware/config
    echo "# stage1 variables produced during plugin install" \
      >>${PLUGINCONFDIR}/vmware.conf
    cat ${PLUGINDIR}/${vmware_kind}/vmware.conf >>${PLUGINCONFDIR}/vmware.conf

    # if /tmp resides on nfs: create an empty container file for vmware *.vmem
    # it does not like to live on NFS exports
    # stuff moved more generic to vmchooser plugin
    #if [ cat /proc/mounts|grep -qe "^/tmp "|grep -qe "nfs" ] ; then
    #  dd if=/dev/zero of=/mnt/tmp/vm-container count=1 seek=2048000
    #  diskfm /mnt/tmp/vm-container /mnt/tmp/virt
    #  chmod a+rwxt /mnt/tmp/virt
    #fi
    [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmware' os-plugin ..."

  fi
else
  [ $DEBUGLEVEL -gt 0 ] && echo "  * Configuration of vmware plugin failed"
fi