summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/qemukvm/XX_qemukvm.sh
blob: 6ecec75bc3fcfa5d61e7c6cd9cbc1371f14bba6e (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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

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

  # check for the virtualization CPU features
  if grep -q "svm" /proc/cpuinfo && modprobe ${MODPRV} kvm_amd ; then
    [ $DEBUGLEVEL -gt 0 ] && echo "  * Loaded kvm_amd module"
  elif grep -q "vmx" /proc/cpuinfo &&  modprobe  ${MODPRV} kvm_intel ; then
    [ $DEBUGLEVEL -gt 0 ] && echo "  * Loaded kvm_intel module"
  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
    exit 1
  fi
  # load the tunnel device module
  modprobe tun 2>/dev/null
    
  # load needed variables
  . /initramfs/plugin-conf/qemukvm.conf

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

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

    # get source of qemukvm image server (get type, server and path)
    if strinstr "/" "${qemukvm_imagesrc}" ; then
      qkimgprot=$(uri_token ${qemukvm_imagesrc} prot)
      qkimgserv=$(uri_token ${qemukvm_imagesrc} server)
      qkimgpath="$(uri_token ${qemukvm_imagesrc} path)"
    fi
    if [ -n "${qkimgserv}" ] ; then
      # directory where qemu images are expected in
      mnttarget=/mnt/var/lib/virt/qemukvm
      # mount the qemukvm image source readonly (ro)
      fsmount ${qkimgprot} ${qkimgserv} ${qkimgpath} ${mnttarget} ro
    else
      [ $DEBUGLEVEL -gt 1 ] && error "  * Incomplete information in variable \
${qemukvm_imagesrc}." nonfatal
    fi
    # copy version depending files - the vmchooser expects for every virtua-
    # lization plugin a file named after it (here run-qemukvm.include)
    testmkd /mnt/etc/opt/openslx
    cp /mnt/opt/openslx/plugin-repo/qemukvm/run-virt.include \
      /mnt/etc/opt/openslx/plugins/qemukvm/run-qemukvm.include
    # create a network configuration template (variables should be setable in
    # the future, see vmware plugin)
    natnetwork="192.168.101"
    honetwork="192.168.102"
    echo -e "nataddress=${natnetwork}.254/24\nhoaddress=${honetwork}.254/24" \
      >/mnt/etc/opt/openslx/network.qemukvm

    # copy the runlevel script (proper place for all distros??)
    cp /mnt/opt/openslx/plugin-repo/qemukvm/qemukvm /mnt/etc/init.d
    chmod 0755 /mnt/etc/init.d/qemukvm
    rllinker "qemukvm" 22 2

    # copy the /etc/qemu-ifup script and enable extended rights for running
    # the emulator and certain network commands via sudo
    ln -sf /opt/openslx/plugin-repo/qemukvm/qemu-ifup /mnt/etc/qemu-ifup
    ln -sf /opt/openslx/plugin-repo/qemukvm/qemu-ifdown /mnt/etc/qemu-ifdown
    ln -sf /opt/openslx/plugin-repo/qemukvm/qemu-ifup /mnt/etc/kvm-ifup
    ln -sf /opt/openslx/plugin-repo/qemukvm/qemu-ifdown /mnt/etc/kvm-ifdown

    for qemubin in qemu kvm ; do
      qemu="$(binfinder ${qemubin})"
      [ -n "${qemu}" ] && \
        echo "ALL ALL=NOPASSWD: ${qemu}" >>/mnt/etc/sudoers
    done
    echo -e "#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/sbin/tunctl -t tap*\n\
#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/sbin/ip addr add * dev tap*\n\
#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tap*\n\
ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/udhcpd -S /tmp/qemu*\n\
ALL ALL=NOPASSWD: killall udhcpd" >>/mnt/etc/sudoers
  fi
else
  [ $DEBUGLEVEL -gt 0 ] && echo "  * Configuration of qemukvm plugin failed"
fi