blob: 546ac99cd9d7243c37ef88e3a398cc72134a7b40 [file] [log] [blame]
John Garbuttdaadf742012-04-27 18:28:28 +01001#!/bin/bash
2
3# This script is run by install_os_domU.sh
4#
5# Parameters:
6# - $GUEST_NAME - hostname for the DomU VM
7#
8# It modifies the ubuntu image created by install_os_domU.sh
9#
10# This script is responsible for cusomtizing the fresh ubuntu
11# image so on boot it runs the prepare_guest.sh script
12# that modifies the VM so it is ready to run stack.sh.
13# It does this by mounting the disk image of the VM.
14#
15# The resultant image is started by install_os_domU.sh,
16# and once the VM has shutdown, build_xva.sh is run
17
John Garbuttdaadf742012-04-27 18:28:28 +010018set -o errexit
Mate Lakat0b3804b2013-05-07 16:58:17 +010019set -o nounset
John Garbuttdaadf742012-04-27 18:28:28 +010020set -o xtrace
21
22# This directory
23TOP_DIR=$(cd $(dirname "$0") && pwd)
24
25# Include onexit commands
26. $TOP_DIR/scripts/on_exit.sh
27
28# Source params - override xenrc params in your localrc to suite your taste
29source xenrc
30
31#
32# Parameters
33#
34GUEST_NAME="$1"
35
36# Mount the VDI
37STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*")
38add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1"
39
40# Make sure we have a stage
41if [ ! -d $STAGING_DIR/etc ]; then
42 echo "Stage is not properly set up!"
43 exit 1
44fi
45
John Garbuttb6c87142012-08-02 12:34:03 +010046# Copy XenServer tools deb into the VM
47ISO_DIR="/opt/xensource/packages/iso"
48XS_TOOLS_FILE_NAME="xs-tools.deb"
49XS_TOOLS_PATH="/root/$XS_TOOLS_FILE_NAME"
50if [ -e "$ISO_DIR" ]; then
Andrew Melton98ab5002012-09-06 15:18:11 -040051 TOOLS_ISO=$(ls -1 $ISO_DIR/xs-tools-*.iso | head -1)
John Garbuttb6c87142012-08-02 12:34:03 +010052 TMP_DIR=/tmp/temp.$RANDOM
53 mkdir -p $TMP_DIR
54 mount -o loop $TOOLS_ISO $TMP_DIR
55 DEB_FILE=$(ls $TMP_DIR/Linux/*amd64.deb)
56 echo "Copying XenServer tools into VM from: $DEB_FILE"
57 cp $DEB_FILE "${STAGING_DIR}${XS_TOOLS_PATH}"
58 umount $TMP_DIR
59 rm -rf $TMP_DIR
60else
61 echo "WARNING: no XenServer tools found, falling back to 5.6 tools"
Mate Lakatda339822012-11-14 12:45:10 +000062 TOOLS_URL="https://github.com/downloads/citrix-openstack/warehouse/xe-guest-utilities_5.6.100-651_amd64.deb"
John Garbuttb6c87142012-08-02 12:34:03 +010063 wget $TOOLS_URL -O $XS_TOOLS_FILE_NAME
64 cp $XS_TOOLS_FILE_NAME "${STAGING_DIR}${XS_TOOLS_PATH}"
65 rm -rf $XS_TOOLS_FILE_NAME
66fi
67
John Garbuttdaadf742012-04-27 18:28:28 +010068# Copy prepare_guest.sh to VM
69mkdir -p $STAGING_DIR/opt/stack/
70cp $TOP_DIR/prepare_guest.sh $STAGING_DIR/opt/stack/prepare_guest.sh
71
72# backup rc.local
73cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.preparebackup
74
75# run prepare_guest.sh on boot
76cat <<EOF >$STAGING_DIR/etc/rc.local
Mate Lakat0b3804b2013-05-07 16:58:17 +010077#!/bin/sh -e
78bash /opt/stack/prepare_guest.sh \\
79 "$GUEST_PASSWORD" "$XS_TOOLS_PATH" "$STACK_USER" \\
80 > /opt/stack/prepare_guest.log 2>&1
John Garbuttdaadf742012-04-27 18:28:28 +010081EOF
Bob Ball60fcfb52013-12-23 17:23:47 +000082
83# Need to set barrier=0 to avoid a Xen bug
84# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/824089
85sed -i -e 's/errors=/barrier=0,errors=/' $STAGING_DIR/etc/fstab