blob: 06e5857bd29e7c282356ff88c26eafb07b39bbad [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 Troyerdccd6b92011-11-01 15:46:14 -050013# Set up nbd
14modprobe nbd max_part=63
15
Dean Troyer2567c812011-11-01 12:36:59 -050016# Echo commands
17set -o xtrace
18
Dean Troyera6466e02011-10-25 17:53:24 -050019IMG_FILE=$1
20
Dean Troyer2567c812011-11-01 12:36:59 -050021# Keep track of the current directory
22TOOLS_DIR=$(cd $(dirname "$0") && pwd)
23TOP_DIR=`cd $TOOLS_DIR/..; pwd`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070024
Dean Troyer03412c82011-10-03 09:56:41 -050025# Store cwd
26CWD=`pwd`
27
Dean Troyer2567c812011-11-01 12:36:59 -050028cd $TOP_DIR
29
30# Source params
31source ./stackrc
32
33CACHEDIR=${CACHEDIR:-/var/cache/devstack}
34
Dean Troyer11e5e6f2011-10-03 09:40:32 -050035DEST=${DEST:-/opt/stack}
36
Dean Troyer2567c812011-11-01 12:36:59 -050037# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
38ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
39
40# Base image (natty by default)
41DIST_NAME=${DIST_NAME:-natty}
42
Dean Troyer8f851e72011-10-11 20:22:23 -050043# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
44STACKSH_PARAMS=${STACKSH_PARAMS:-}
45
Dean Troyera3379e02011-10-03 11:14:13 -050046# Option to use the version of devstack on which we are currently working
47USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
48
Dean Troyer2567c812011-11-01 12:36:59 -050049# clean install
50if [ ! -r $CACHEDIR/$DIST_NAME-base.img ]; then
51 $TOOLS_DIR/get_uec_image.sh $DIST_NAME $CACHEDIR/$DIST_NAME-base.img
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070052fi
53
Dean Troyerdccd6b92011-11-01 15:46:14 -050054# Finds the next available NBD device
55# Exits script if error connecting or none free
56# map_nbd image
57# returns full nbd device path
58function map_nbd {
59 for i in `seq 0 15`; do
60 if [ ! -e /sys/block/nbd$i/pid ]; then
61 NBD=/dev/nbd$i
62 # Connect to nbd and wait till it is ready
63 qemu-nbd -c $NBD $1
64 if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
65 echo "Couldn't connect $NBD"
66 exit 1
67 fi
68 break
69 fi
70 done
71 if [ -z "$NBD" ]; then
72 echo "No free NBD slots"
Dean Troyera6466e02011-10-25 17:53:24 -050073 exit 1
74 fi
Dean Troyerdccd6b92011-11-01 15:46:14 -050075 echo $NBD
76}
77
78# prime image with as many apt/pips as we can
79DEV_FILE=$CACHEDIR/$DIST_NAME-dev.img
80DEV_FILE_TMP=`mktemp $DEV_FILE.XXXXXX`
81if [ ! -r $DEV_FILE ]; then
82 cp -p $CACHEDIR/$DIST_NAME-base.img $DEV_FILE_TMP
83
84 NBD=`map_nbd $DEV_FILE_TMP`
Dean Troyera6466e02011-10-25 17:53:24 -050085 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
86 mount -t ext4 ${NBD}p1 $MNTDIR
87 cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
88
89 chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
90 chroot $MNTDIR pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070091
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070092 # Create a stack user that is a member of the libvirtd group so that stack
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070093 # is able to interact with libvirt.
Dean Troyera6466e02011-10-25 17:53:24 -050094 chroot $MNTDIR groupadd libvirtd
95 chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd
96 mkdir -p $MNTDIR/$DEST
97 chroot $MNTDIR chown stack $DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070098
99 # a simple password - pass
Dean Troyerdccd6b92011-11-01 15:46:14 -0500100 echo stack:pass | chroot $MNTDIR chpasswd
101 echo root:$ROOT_PASSWORD | chroot $MNTDIR chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700102
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700103 # and has sudo ability (in the future this should be limited to only what
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700104 # stack requires)
Dean Troyera6466e02011-10-25 17:53:24 -0500105 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
106
107 umount $MNTDIR
108 rmdir $MNTDIR
109 qemu-nbd -d $NBD
Dean Troyerdccd6b92011-11-01 15:46:14 -0500110 mv $DEV_FILE_TMP $DEV_FILE
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700111fi
Dean Troyerdccd6b92011-11-01 15:46:14 -0500112rm -f $DEV_FILE_TMP
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700113
114# clone git repositories onto the system
115# ======================================
116
Dean Troyerdccd6b92011-11-01 15:46:14 -0500117IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX`
118
Dean Troyera6466e02011-10-25 17:53:24 -0500119if [ ! -r $IMG_FILE ]; then
Dean Troyerdccd6b92011-11-01 15:46:14 -0500120 NBD=`map_nbd $DEV_FILE`
Dean Troyer61be9242011-10-25 22:35:23 -0500121
122 # Pre-create the image file
123 # FIXME(dt): This should really get the partition size to
124 # pre-create the image file
Dean Troyerdccd6b92011-11-01 15:46:14 -0500125 dd if=/dev/zero of=$IMG_FILE_TMP bs=1 count=1 seek=$((2*1024*1024*1024))
Dean Troyer61be9242011-10-25 22:35:23 -0500126 # Create filesystem image for RAM disk
Dean Troyerdccd6b92011-11-01 15:46:14 -0500127 dd if=${NBD}p1 of=$IMG_FILE_TMP bs=1M
Dean Troyer61be9242011-10-25 22:35:23 -0500128
129 qemu-nbd -d $NBD
Dean Troyerdccd6b92011-11-01 15:46:14 -0500130 mv $IMG_FILE_TMP $IMG_FILE
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700131fi
Dean Troyerdccd6b92011-11-01 15:46:14 -0500132rm -f $IMG_FILE_TMP
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700133
Dean Troyera6466e02011-10-25 17:53:24 -0500134MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
Dean Troyer61be9242011-10-25 22:35:23 -0500135mount -t ext4 -o loop $IMG_FILE $MNTDIR
Dean Troyera6466e02011-10-25 17:53:24 -0500136cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
137
Dean Troyerea442c12011-10-26 12:34:59 -0500138# We need to install a non-virtual kernel and modules to boot from
Dean Troyer7920b0f2011-10-26 15:10:46 -0500139if [ ! -r "`ls $MNTDIR/boot/vmlinuz-*-generic | head -1`" ]; then
Dean Troyerea442c12011-10-26 12:34:59 -0500140 chroot $MNTDIR apt-get install -y linux-generic
141fi
142
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700143# git clone only if directory doesn't exist already. Since ``DEST`` might not
144# be owned by the installation user, we create the directory and change the
145# ownership to the proper user.
146function git_clone {
147
148 # clone new copy or fetch latest changes
Dean Troyera6466e02011-10-25 17:53:24 -0500149 CHECKOUT=${MNTDIR}$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700150 if [ ! -d $CHECKOUT ]; then
151 mkdir -p $CHECKOUT
152 git clone $1 $CHECKOUT
153 else
154 pushd $CHECKOUT
155 git fetch
156 popd
157 fi
158
159 # FIXME(ja): checkout specified version (should works for branches and tags)
160
161 pushd $CHECKOUT
162 # checkout the proper branch/tag
163 git checkout $3
164 # force our local version to be the same as the remote version
165 git reset --hard origin/$3
166 popd
167
168 # give ownership to the stack user
Dean Troyera6466e02011-10-25 17:53:24 -0500169 chroot $MNTDIR chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700170}
171
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500172git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
173git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
174git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
175git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
Tres Henryca85b792011-10-28 14:00:21 -0700176git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500177git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
178git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700179
Dean Troyerb5da5192011-10-17 13:32:06 -0500180# Use this version of devstack
Dean Troyera6466e02011-10-25 17:53:24 -0500181rm -rf $MNTDIR/$DEST/devstack
182cp -pr $CWD $MNTDIR/$DEST/devstack
183chroot $MNTDIR chown -R stack $DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500184
Dean Troyercf9db8d2011-10-03 13:42:16 -0500185# Configure host network for DHCP
Dean Troyera6466e02011-10-25 17:53:24 -0500186mkdir -p $MNTDIR/etc/network
187cat > $MNTDIR/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500188auto lo
189iface lo inet loopback
190
191auto eth0
192iface eth0 inet dhcp
193EOF
194
Dean Troyer288f3bd2011-10-13 15:50:44 -0500195# Set hostname
Dean Troyera6466e02011-10-25 17:53:24 -0500196echo "ramstack" >$MNTDIR/etc/hostname
197echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
Dean Troyer288f3bd2011-10-13 15:50:44 -0500198
Dean Troyer8f851e72011-10-11 20:22:23 -0500199# Configure the runner
Dean Troyera6466e02011-10-25 17:53:24 -0500200RUN_SH=$MNTDIR/$DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500201cat > $RUN_SH <<EOF
202#!/usr/bin/env bash
203
Dean Troyer7c076ee2011-10-13 13:20:13 -0500204# Get IP range
205set \`ip addr show dev eth0 | grep inet\`
206PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
207export FLOATING_RANGE="\$PREFIX.224/27"
208
Dean Troyer8f851e72011-10-11 20:22:23 -0500209# Kill any existing screens
210killall screen
211
212# Run stack.sh
213cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
214echo >> $DEST/run.sh.log
215echo >> $DEST/run.sh.log
216echo "All done! Time to start clicking." >> $DEST/run.sh.log
217EOF
218
219# Make the run.sh executable
220chmod 755 $RUN_SH
Dean Troyera6466e02011-10-25 17:53:24 -0500221chroot $MNTDIR chown stack $DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500222
Dean Troyera6466e02011-10-25 17:53:24 -0500223umount $MNTDIR
224rmdir $MNTDIR