2 # XEN specific functions
4 ################################################################
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 ################################################################
24 vm_verify_options_xen() {
25 vm_kernel=/boot/vmlinuz
26 vm_initrd=/boot/initrd
27 test -e /boot/vmlinuz-xen && vm_kernel=/boot/vmlinuz-xen
28 test -e /boot/initrd-xen && vm_initrd=/boot/initrd-xen
29 test -n "$VM_KERNEL" && vm_kernel="$VM_KERNEL"
30 test -n "$VM_INITRD" && vm_initrd="$VM_INITRD"
35 test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
36 XMROOT="file:$(readlink -f $VM_IMAGE)"
37 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
38 XMROOT="disk=$XMROOT,hda1,w"
40 if test -n "$VM_SWAP" ; then
41 XMSWAP="file:$(readlink -f $VM_SWAP)"
42 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
43 XMSWAP="disk=$XMSWAP,hda2,w"
45 XENID="${VM_IMAGE%/root}"
46 XENID="${XENID%/tmpfs}"
48 XENID="${XENID#root_}"
50 if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
51 echo "Instance already exists, something really went wrong..."
52 echo "Please report to your server admin, there might be multiple services running for same domain"
55 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
57 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
58 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
59 echo "memory = ${VM_MEMSIZE:-64}" >> $XEN_CONF_FILE
60 test -n "$BUILD_JOBS" && echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
61 echo "root = \"/dev/hda1 ro\"" >> $XEN_CONF_FILE
62 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
63 echo "on_poweroff = \"destroy\"" >> $XEN_CONF_FILE
64 echo "on_reboot = \"destroy\"" >> $XEN_CONF_FILE
65 echo "on_crash = \"destroy\"" >> $XEN_CONF_FILE
66 if test "$XMCMD" = xm ; then
67 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="panic=1 quiet init="$vm_init_script" rd.driver.pre=binfmt_misc elevator=noop console=ttyS0"
70 XLDISK="\"${XMROOT#disk=}\""
71 test -n "$XMSWAP" && XLDISK="$XLDISK, \"${XMSWAP#disk=}\""
72 set -- xl create -c $XEN_CONF_FILE name="\"build_$XENID\"" "disk=[ $XLDISK ]" extra=\""panic=1 quiet init="$vm_init_script" rd.driver.pre=binfmt_misc elevator=noop console=ttyS0"\"
74 if test "$PERSONALITY" != 0 ; then
75 # have to switch back to PER_LINUX to make xm work
79 "$@" || cleanup_and_exit 3
80 rm -f "$XEN_CONF_FILE"
85 test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
86 XENID="${VM_IMAGE%/root}"
87 XENID="${XENID%/tmpfs}"
89 XENID="${XENID#root_}"
90 if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
91 if ! $XMCMD destroy "build_$XENID" ; then
92 echo "could not kill xen build $XENID"
100 # this should not be needed, but sometimes a xen instance gets lost
102 test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
103 XENID="${VM_IMAGE%/root}"
104 XENID="${XENID%/tmpfs}"
106 XENID="${XENID#root_}"
107 $XMCMD destroy "build_$XENID" >/dev/null 2>&1
114 vm_attach_root_xen() {
118 vm_attach_swap_xen() {
122 vm_detach_root_xen() {
126 vm_detach_swap_xen() {