blob: 43f8999cfc34db8956ed43879b53ac6f9637846e [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
4if [ ! "$#" -eq "1" ]; then
5 echo "$0 builds a gziped natty openstack install"
6 echo "usage: $0 dest"
7 exit 1
8fi
9
Dean Troyera6466e02011-10-25 17:53:24 -050010IMG_FILE=$1
11
Dean Troyer407ee7e2011-09-29 16:38:59 -050012PROGDIR=`dirname $0`
Dean Troyerd4a3bac2011-10-03 21:16:27 -050013CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
Dean Troyer407ee7e2011-09-29 16:38:59 -050014
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070015# Source params
16source ./stackrc
17
Dean Troyer03412c82011-10-03 09:56:41 -050018# Store cwd
19CWD=`pwd`
20
Dean Troyer11e5e6f2011-10-03 09:40:32 -050021DEST=${DEST:-/opt/stack}
22
Dean Troyer8f851e72011-10-11 20:22:23 -050023# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
24STACKSH_PARAMS=${STACKSH_PARAMS:-}
25
Dean Troyera3379e02011-10-03 11:14:13 -050026# Option to use the version of devstack on which we are currently working
27USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
28
Dean Troyera6466e02011-10-25 17:53:24 -050029# Set up nbd
30modprobe nbd max_part=63
31NBD=${NBD:-/dev/nbd9}
32NBD_DEV=`basename $NBD`
33
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070034# clean install of natty
Dean Troyera6466e02011-10-25 17:53:24 -050035if [ ! -r $CHROOTCACHE/natty-base.img ]; then
36 $PROGDIR/get_uec_image.sh natty $CHROOTCACHE/natty-base.img
37# # copy kernel modules...
38# # NOTE(ja): is there a better way to do this?
39# cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
40# # a simple password - pass
41# echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070042fi
43
44# prime natty with as many apt/pips as we can
Dean Troyera6466e02011-10-25 17:53:24 -050045if [ ! -r $CHROOTCACHE/natty-dev.img ]; then
46 cp -p $CHROOTCACHE/natty-base.img $CHROOTCACHE/natty-dev.img
47
48 qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
49 if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
50 echo "Couldn't connect $NBD"
51 exit 1
52 fi
53 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
54 mount -t ext4 ${NBD}p1 $MNTDIR
55 cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
56
57 chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
58 chroot $MNTDIR pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070059
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070060 # Create a stack user that is a member of the libvirtd group so that stack
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070061 # is able to interact with libvirt.
Dean Troyera6466e02011-10-25 17:53:24 -050062 chroot $MNTDIR groupadd libvirtd
63 chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd
64 mkdir -p $MNTDIR/$DEST
65 chroot $MNTDIR chown stack $DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070066
67 # a simple password - pass
Dean Troyera6466e02011-10-25 17:53:24 -050068 echo stack:pass | chroot $MNTDIR chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070069
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070070 # and has sudo ability (in the future this should be limited to only what
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070071 # stack requires)
Dean Troyera6466e02011-10-25 17:53:24 -050072 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
73
74 umount $MNTDIR
75 rmdir $MNTDIR
76 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070077fi
78
79# clone git repositories onto the system
80# ======================================
81
Dean Troyera6466e02011-10-25 17:53:24 -050082if [ ! -r $IMG_FILE ]; then
Dean Troyer61be9242011-10-25 22:35:23 -050083 qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
Dean Troyer7920b0f2011-10-26 15:10:46 -050084 if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
Dean Troyer61be9242011-10-25 22:35:23 -050085 echo "Couldn't connect $NBD"
86 exit 1
87 fi
88
89 # Pre-create the image file
90 # FIXME(dt): This should really get the partition size to
91 # pre-create the image file
92 dd if=/dev/zero of=$IMG_FILE bs=1 count=1 seek=$((2*1024*1024*1024))
93 # Create filesystem image for RAM disk
94 dd if=${NBD}p1 of=$IMG_FILE bs=1M
95
96 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070097fi
98
Dean Troyera6466e02011-10-25 17:53:24 -050099MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
Dean Troyer61be9242011-10-25 22:35:23 -0500100mount -t ext4 -o loop $IMG_FILE $MNTDIR
Dean Troyera6466e02011-10-25 17:53:24 -0500101cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
102
Dean Troyerea442c12011-10-26 12:34:59 -0500103# We need to install a non-virtual kernel and modules to boot from
Dean Troyer7920b0f2011-10-26 15:10:46 -0500104if [ ! -r "`ls $MNTDIR/boot/vmlinuz-*-generic | head -1`" ]; then
Dean Troyerea442c12011-10-26 12:34:59 -0500105 chroot $MNTDIR apt-get install -y linux-generic
106fi
107
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700108# git clone only if directory doesn't exist already. Since ``DEST`` might not
109# be owned by the installation user, we create the directory and change the
110# ownership to the proper user.
111function git_clone {
112
113 # clone new copy or fetch latest changes
Dean Troyera6466e02011-10-25 17:53:24 -0500114 CHECKOUT=${MNTDIR}$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700115 if [ ! -d $CHECKOUT ]; then
116 mkdir -p $CHECKOUT
117 git clone $1 $CHECKOUT
118 else
119 pushd $CHECKOUT
120 git fetch
121 popd
122 fi
123
124 # FIXME(ja): checkout specified version (should works for branches and tags)
125
126 pushd $CHECKOUT
127 # checkout the proper branch/tag
128 git checkout $3
129 # force our local version to be the same as the remote version
130 git reset --hard origin/$3
131 popd
132
133 # give ownership to the stack user
Dean Troyera6466e02011-10-25 17:53:24 -0500134 chroot $MNTDIR chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700135}
136
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500137git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
138git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
139git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
140git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
Tres Henryca85b792011-10-28 14:00:21 -0700141git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500142git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
143git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700144
Dean Troyerb5da5192011-10-17 13:32:06 -0500145# Use this version of devstack
Dean Troyera6466e02011-10-25 17:53:24 -0500146rm -rf $MNTDIR/$DEST/devstack
147cp -pr $CWD $MNTDIR/$DEST/devstack
148chroot $MNTDIR chown -R stack $DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500149
Dean Troyercf9db8d2011-10-03 13:42:16 -0500150# Configure host network for DHCP
Dean Troyera6466e02011-10-25 17:53:24 -0500151mkdir -p $MNTDIR/etc/network
152cat > $MNTDIR/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500153auto lo
154iface lo inet loopback
155
156auto eth0
157iface eth0 inet dhcp
158EOF
159
Dean Troyer288f3bd2011-10-13 15:50:44 -0500160# Set hostname
Dean Troyera6466e02011-10-25 17:53:24 -0500161echo "ramstack" >$MNTDIR/etc/hostname
162echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
Dean Troyer288f3bd2011-10-13 15:50:44 -0500163
Dean Troyer8f851e72011-10-11 20:22:23 -0500164# Configure the runner
Dean Troyera6466e02011-10-25 17:53:24 -0500165RUN_SH=$MNTDIR/$DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500166cat > $RUN_SH <<EOF
167#!/usr/bin/env bash
168
Dean Troyer7c076ee2011-10-13 13:20:13 -0500169# Get IP range
170set \`ip addr show dev eth0 | grep inet\`
171PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
172export FLOATING_RANGE="\$PREFIX.224/27"
173
Dean Troyer8f851e72011-10-11 20:22:23 -0500174# Kill any existing screens
175killall screen
176
177# Run stack.sh
178cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
179echo >> $DEST/run.sh.log
180echo >> $DEST/run.sh.log
181echo "All done! Time to start clicking." >> $DEST/run.sh.log
182EOF
183
184# Make the run.sh executable
185chmod 755 $RUN_SH
Dean Troyera6466e02011-10-25 17:53:24 -0500186chroot $MNTDIR chown stack $DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500187
Dean Troyera6466e02011-10-25 17:53:24 -0500188umount $MNTDIR
189rmdir $MNTDIR