blob: e57aa0335b569a0787d579cec26e5982831af890 [file] [log] [blame]
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07001#!/bin/bash
Dean Troyer56119512011-10-11 19:39:34 -05002# build_ramdisk.sh - Build RAM disk images
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07003
Dean Troyer2567c812011-11-01 12:36:59 -05004# exit on error to stop unexpected errors
5set -o errexit
6
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07007if [ ! "$#" -eq "1" ]; then
Dean Troyer2567c812011-11-01 12:36:59 -05008 echo "$0 builds a gziped Ubuntu OpenStack install"
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07009 echo "usage: $0 dest"
10 exit 1
11fi
12
Dean Troyer2567c812011-11-01 12:36:59 -050013# Echo commands
14set -o xtrace
15
Dean Troyera6466e02011-10-25 17:53:24 -050016IMG_FILE=$1
17
Dean Troyer2567c812011-11-01 12:36:59 -050018# Keep track of the current directory
19TOOLS_DIR=$(cd $(dirname "$0") && pwd)
20TOP_DIR=`cd $TOOLS_DIR/..; pwd`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070021
Dean Troyer03412c82011-10-03 09:56:41 -050022# Store cwd
23CWD=`pwd`
24
Dean Troyer2567c812011-11-01 12:36:59 -050025cd $TOP_DIR
26
27# Source params
28source ./stackrc
29
30CACHEDIR=${CACHEDIR:-/var/cache/devstack}
31
Dean Troyer11e5e6f2011-10-03 09:40:32 -050032DEST=${DEST:-/opt/stack}
33
Dean Troyer2567c812011-11-01 12:36:59 -050034# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
35ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
36
37# Base image (natty by default)
38DIST_NAME=${DIST_NAME:-natty}
39
Dean Troyer8f851e72011-10-11 20:22:23 -050040# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
41STACKSH_PARAMS=${STACKSH_PARAMS:-}
42
Dean Troyera3379e02011-10-03 11:14:13 -050043# Option to use the version of devstack on which we are currently working
44USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
45
Dean Troyera6466e02011-10-25 17:53:24 -050046# Set up nbd
47modprobe nbd max_part=63
48NBD=${NBD:-/dev/nbd9}
49NBD_DEV=`basename $NBD`
50
Dean Troyer2567c812011-11-01 12:36:59 -050051# clean install
52if [ ! -r $CACHEDIR/$DIST_NAME-base.img ]; then
53 $TOOLS_DIR/get_uec_image.sh $DIST_NAME $CACHEDIR/$DIST_NAME-base.img
Dean Troyera6466e02011-10-25 17:53:24 -050054# # copy kernel modules...
55# # NOTE(ja): is there a better way to do this?
Dean Troyer2567c812011-11-01 12:36:59 -050056# cp -pr /lib/modules/`uname -r` $CACHEDIR/$DIST_NAME-base/lib/modules
Dean Troyera6466e02011-10-25 17:53:24 -050057# # a simple password - pass
Dean Troyer2567c812011-11-01 12:36:59 -050058# echo root:pass | chroot $CACHEDIR/$DIST_NAME-base chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070059fi
60
Dean Troyer2567c812011-11-01 12:36:59 -050061# prime image with as many apt/pips as we can
62if [ ! -r $CACHEDIR/$DIST_NAME-dev.img ]; then
63 cp -p $CACHEDIR/$DIST_NAME-base.img $CACHEDIR/$DIST_NAME-dev.img
Dean Troyera6466e02011-10-25 17:53:24 -050064
Dean Troyer2567c812011-11-01 12:36:59 -050065 qemu-nbd -c $NBD $CACHEDIR/$DIST_NAME-dev.img
Dean Troyera6466e02011-10-25 17:53:24 -050066 if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
67 echo "Couldn't connect $NBD"
68 exit 1
69 fi
70 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
71 mount -t ext4 ${NBD}p1 $MNTDIR
72 cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
73
74 chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
75 chroot $MNTDIR pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070076
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070077 # Create a stack user that is a member of the libvirtd group so that stack
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070078 # is able to interact with libvirt.
Dean Troyera6466e02011-10-25 17:53:24 -050079 chroot $MNTDIR groupadd libvirtd
80 chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd
81 mkdir -p $MNTDIR/$DEST
82 chroot $MNTDIR chown stack $DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070083
84 # a simple password - pass
Dean Troyer2567c812011-11-01 12:36:59 -050085 echo stack:$ROOT_PASSWORD | chroot $MNTDIR chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070086
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070087 # and has sudo ability (in the future this should be limited to only what
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070088 # stack requires)
Dean Troyera6466e02011-10-25 17:53:24 -050089 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
90
91 umount $MNTDIR
92 rmdir $MNTDIR
93 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070094fi
95
96# clone git repositories onto the system
97# ======================================
98
Dean Troyera6466e02011-10-25 17:53:24 -050099if [ ! -r $IMG_FILE ]; then
Dean Troyer2567c812011-11-01 12:36:59 -0500100 qemu-nbd -c $NBD $CACHEDIR/$DIST_NAME-dev.img
Dean Troyer7920b0f2011-10-26 15:10:46 -0500101 if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
Dean Troyer61be9242011-10-25 22:35:23 -0500102 echo "Couldn't connect $NBD"
103 exit 1
104 fi
105
106 # Pre-create the image file
107 # FIXME(dt): This should really get the partition size to
108 # pre-create the image file
109 dd if=/dev/zero of=$IMG_FILE bs=1 count=1 seek=$((2*1024*1024*1024))
110 # Create filesystem image for RAM disk
111 dd if=${NBD}p1 of=$IMG_FILE bs=1M
112
113 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700114fi
115
Dean Troyera6466e02011-10-25 17:53:24 -0500116MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
Dean Troyer61be9242011-10-25 22:35:23 -0500117mount -t ext4 -o loop $IMG_FILE $MNTDIR
Dean Troyera6466e02011-10-25 17:53:24 -0500118cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
119
Dean Troyerea442c12011-10-26 12:34:59 -0500120# We need to install a non-virtual kernel and modules to boot from
Dean Troyer7920b0f2011-10-26 15:10:46 -0500121if [ ! -r "`ls $MNTDIR/boot/vmlinuz-*-generic | head -1`" ]; then
Dean Troyerea442c12011-10-26 12:34:59 -0500122 chroot $MNTDIR apt-get install -y linux-generic
123fi
124
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700125# git clone only if directory doesn't exist already. Since ``DEST`` might not
126# be owned by the installation user, we create the directory and change the
127# ownership to the proper user.
128function git_clone {
129
130 # clone new copy or fetch latest changes
Dean Troyera6466e02011-10-25 17:53:24 -0500131 CHECKOUT=${MNTDIR}$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700132 if [ ! -d $CHECKOUT ]; then
133 mkdir -p $CHECKOUT
134 git clone $1 $CHECKOUT
135 else
136 pushd $CHECKOUT
137 git fetch
138 popd
139 fi
140
141 # FIXME(ja): checkout specified version (should works for branches and tags)
142
143 pushd $CHECKOUT
144 # checkout the proper branch/tag
145 git checkout $3
146 # force our local version to be the same as the remote version
147 git reset --hard origin/$3
148 popd
149
150 # give ownership to the stack user
Dean Troyera6466e02011-10-25 17:53:24 -0500151 chroot $MNTDIR chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700152}
153
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500154git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
155git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
156git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
157git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
Tres Henryca85b792011-10-28 14:00:21 -0700158git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500159git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
160git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700161
Dean Troyerb5da5192011-10-17 13:32:06 -0500162# Use this version of devstack
Dean Troyera6466e02011-10-25 17:53:24 -0500163rm -rf $MNTDIR/$DEST/devstack
164cp -pr $CWD $MNTDIR/$DEST/devstack
165chroot $MNTDIR chown -R stack $DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500166
Dean Troyercf9db8d2011-10-03 13:42:16 -0500167# Configure host network for DHCP
Dean Troyera6466e02011-10-25 17:53:24 -0500168mkdir -p $MNTDIR/etc/network
169cat > $MNTDIR/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500170auto lo
171iface lo inet loopback
172
173auto eth0
174iface eth0 inet dhcp
175EOF
176
Dean Troyer288f3bd2011-10-13 15:50:44 -0500177# Set hostname
Dean Troyera6466e02011-10-25 17:53:24 -0500178echo "ramstack" >$MNTDIR/etc/hostname
179echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
Dean Troyer288f3bd2011-10-13 15:50:44 -0500180
Dean Troyer8f851e72011-10-11 20:22:23 -0500181# Configure the runner
Dean Troyera6466e02011-10-25 17:53:24 -0500182RUN_SH=$MNTDIR/$DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500183cat > $RUN_SH <<EOF
184#!/usr/bin/env bash
185
Dean Troyer7c076ee2011-10-13 13:20:13 -0500186# Get IP range
187set \`ip addr show dev eth0 | grep inet\`
188PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
189export FLOATING_RANGE="\$PREFIX.224/27"
190
Dean Troyer8f851e72011-10-11 20:22:23 -0500191# Kill any existing screens
192killall screen
193
194# Run stack.sh
195cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
196echo >> $DEST/run.sh.log
197echo >> $DEST/run.sh.log
198echo "All done! Time to start clicking." >> $DEST/run.sh.log
199EOF
200
201# Make the run.sh executable
202chmod 755 $RUN_SH
Dean Troyera6466e02011-10-25 17:53:24 -0500203chroot $MNTDIR chown stack $DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500204
Dean Troyera6466e02011-10-25 17:53:24 -0500205umount $MNTDIR
206rmdir $MNTDIR