summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/vmchooser/XX_vmchooser.sh
blob: 4f656478291352e2116107dd08963375ecde5792 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (c) 2008, 2009 - RZ Uni Freiburg
# Copyright (c) 2008, 2009 - 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

# include default directories
. /etc/openslx.conf

CONFFILE="/initramfs/plugin-conf/vmchooser.conf"
PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/vmchooser
BINDIR=/mnt/${OPENSLX_DEFAULT_BINDIR}
PLUGINDIR=${OPENSLX_DEFAULT_DIR}/plugin-repo/vmchooser
VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR}

if [ -e $CONFFILE ]; then
  . $CONFFILE
  if [ $vmchooser_active -ne 0 ] ; then
    [ $DEBUGLEVEL -gt 0 ] \
        && echo "vmchooser: copying stage3 configuration file ..."
    testmkd ${PLUGINCONFDIR}/loopimg
    testmkd ${PLUGINCONFDIR}/fd-loop 1777
    cp $CONFFILE ${PLUGINCONFDIR}/vmchooser.conf
    # TODO: remove vmchooser-stage3.conf when vmchooser path adapted
    cp $CONFFILE /mnt/${OPENSLX_DEFAULT_CONFDIR}/vmchooser-stage3.conf
    ln -s ${PLUGINDIR}/run-virt.sh ${BINDIR}/run-virt.sh
    ln -s ${PLUGINDIR}/vmchooser ${BINDIR}/vmchooser

    # setup all generic virtualization / starting stuff like the floppy image
    # loop file for exchanging information between linux and vm guest
    if modprobe ${MODPRV} loop; then
      mdev -s
    else
      : #|| error "" nonfatal
    fi
    # mount a clean tempfs (bug in UnionFS prevents loopmount to work)
    grep -qE "unionfs |aufs " /proc/mounts && \
      mount -n -o size=1500k -t tmpfs vm-loopimg ${PLUGINCONFDIR}/loopimg
    # create an empty floppy image of 1.4MByte size
    dd if=/dev/zero of=${PLUGINCONFDIR}/loopimg/fd.img count=2880 bs=512 \
      2>/dev/null
    chmod 0777 ${PLUGINCONFDIR}/loopimg/fd.img
    # use dos formatter copied into stage3
    mkdosfs ${PLUGINCONFDIR}/loopimg/fd.img >/dev/null 2>&1 #|| error
    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
fi