Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 3 | # **build_ramdisk.sh** |
| 4 | |
| 5 | # Build RAM disk images |
| 6 | |
| 7 | # Exit on error to stop unexpected errors |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 8 | set -o errexit |
| 9 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 10 | if [ ! "$#" -eq "1" ]; then |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 11 | echo "$0 builds a gziped Ubuntu OpenStack install" |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 12 | echo "usage: $0 dest" |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 16 | # Clean up any resources that may be in use |
| 17 | cleanup() { |
| 18 | set +o errexit |
| 19 | |
| 20 | # Mop up temporary files |
| 21 | if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then |
| 22 | umount $MNTDIR |
| 23 | rmdir $MNTDIR |
| 24 | fi |
Attila Fazekas | 237225d | 2013-11-06 15:41:04 +0100 | [diff] [blame] | 25 | if [ -n "$DEV_FILE_TMP" -a -e "$DEV_FILE_TMP" ]; then |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 26 | rm -f $DEV_FILE_TMP |
| 27 | fi |
| 28 | if [ -n "$IMG_FILE_TMP" -a -e "$IMG_FILE_TMP" ]; then |
| 29 | rm -f $IMG_FILE_TMP |
| 30 | fi |
| 31 | |
| 32 | # Release NBD devices |
| 33 | if [ -n "$NBD" ]; then |
| 34 | qemu-nbd -d $NBD |
| 35 | fi |
| 36 | |
| 37 | # Kill ourselves to signal any calling process |
| 38 | trap 2; kill -2 $$ |
| 39 | } |
| 40 | |
| 41 | trap cleanup SIGHUP SIGINT SIGTERM |
| 42 | |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 43 | # Set up nbd |
| 44 | modprobe nbd max_part=63 |
| 45 | |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 46 | # Echo commands |
| 47 | set -o xtrace |
| 48 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 49 | IMG_FILE=$1 |
| 50 | |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 51 | # Keep track of the current directory |
| 52 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 53 | TOP_DIR=$(cd $TOOLS_DIR/..; pwd) |
| 54 | |
| 55 | # Import common functions |
| 56 | . $TOP_DIR/functions |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 57 | |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 58 | # Store cwd |
| 59 | CWD=`pwd` |
| 60 | |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 61 | cd $TOP_DIR |
| 62 | |
| 63 | # Source params |
| 64 | source ./stackrc |
| 65 | |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 66 | CACHEDIR=${CACHEDIR:-/opt/stack/cache} |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 67 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 68 | DEST=${DEST:-/opt/stack} |
| 69 | |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 70 | # Configure the root password of the vm to be the same as ``ADMIN_PASSWORD`` |
| 71 | ROOT_PASSWORD=${ADMIN_PASSWORD:-password} |
| 72 | |
| 73 | # Base image (natty by default) |
| 74 | DIST_NAME=${DIST_NAME:-natty} |
| 75 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 76 | # Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" |
| 77 | STACKSH_PARAMS=${STACKSH_PARAMS:-} |
| 78 | |
Dean Troyer | a3379e0 | 2011-10-03 11:14:13 -0500 | [diff] [blame] | 79 | # Option to use the version of devstack on which we are currently working |
| 80 | USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} |
| 81 | |
Dean Troyer | 2567c81 | 2011-11-01 12:36:59 -0500 | [diff] [blame] | 82 | # clean install |
| 83 | if [ ! -r $CACHEDIR/$DIST_NAME-base.img ]; then |
| 84 | $TOOLS_DIR/get_uec_image.sh $DIST_NAME $CACHEDIR/$DIST_NAME-base.img |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 85 | fi |
| 86 | |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 87 | # Finds and returns full device path for the next available NBD device. |
| 88 | # Exits script if error connecting or none free. |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 89 | # map_nbd image |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 90 | function map_nbd() { |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 91 | for i in `seq 0 15`; do |
| 92 | if [ ! -e /sys/block/nbd$i/pid ]; then |
| 93 | NBD=/dev/nbd$i |
| 94 | # Connect to nbd and wait till it is ready |
| 95 | qemu-nbd -c $NBD $1 |
| 96 | if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then |
| 97 | echo "Couldn't connect $NBD" |
| 98 | exit 1 |
| 99 | fi |
| 100 | break |
| 101 | fi |
| 102 | done |
| 103 | if [ -z "$NBD" ]; then |
| 104 | echo "No free NBD slots" |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 105 | exit 1 |
| 106 | fi |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 107 | echo $NBD |
| 108 | } |
| 109 | |
Vincent Untz | 7c3053d | 2012-11-29 09:19:16 +0100 | [diff] [blame] | 110 | # Prime image with as many apt as we can |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 111 | DEV_FILE=$CACHEDIR/$DIST_NAME-dev.img |
| 112 | DEV_FILE_TMP=`mktemp $DEV_FILE.XXXXXX` |
| 113 | if [ ! -r $DEV_FILE ]; then |
| 114 | cp -p $CACHEDIR/$DIST_NAME-base.img $DEV_FILE_TMP |
| 115 | |
| 116 | NBD=`map_nbd $DEV_FILE_TMP` |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 117 | MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` |
| 118 | mount -t ext4 ${NBD}p1 $MNTDIR |
| 119 | cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf |
| 120 | |
Anthony Young | ca2c047 | 2011-11-03 16:29:32 -0700 | [diff] [blame] | 121 | chroot $MNTDIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1` |
| 122 | chroot $MNTDIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1` |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 123 | |
Vishvananda Ishaya | 9b35367 | 2011-10-20 10:07:10 -0700 | [diff] [blame] | 124 | # Create a stack user that is a member of the libvirtd group so that stack |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 125 | # is able to interact with libvirt. |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 126 | chroot $MNTDIR groupadd libvirtd |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 127 | chroot $MNTDIR useradd $STACK_USER -s /bin/bash -d $DEST -G libvirtd |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 128 | mkdir -p $MNTDIR/$DEST |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 129 | chroot $MNTDIR chown $STACK_USER $DEST |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 130 | |
Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 131 | # A simple password - pass |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 132 | echo $STACK_USER:pass | chroot $MNTDIR chpasswd |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 133 | echo root:$ROOT_PASSWORD | chroot $MNTDIR chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 134 | |
Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 135 | # And has sudo ability (in the future this should be limited to only what |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 136 | # stack requires) |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 137 | echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 138 | |
| 139 | umount $MNTDIR |
| 140 | rmdir $MNTDIR |
| 141 | qemu-nbd -d $NBD |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 142 | NBD="" |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 143 | mv $DEV_FILE_TMP $DEV_FILE |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 144 | fi |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 145 | rm -f $DEV_FILE_TMP |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 146 | |
Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 147 | |
| 148 | # Clone git repositories onto the system |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 149 | # ====================================== |
| 150 | |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 151 | IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX` |
| 152 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 153 | if [ ! -r $IMG_FILE ]; then |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 154 | NBD=`map_nbd $DEV_FILE` |
Dean Troyer | 61be924 | 2011-10-25 22:35:23 -0500 | [diff] [blame] | 155 | |
| 156 | # Pre-create the image file |
| 157 | # FIXME(dt): This should really get the partition size to |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 158 | # pre-create the image file |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 159 | dd if=/dev/zero of=$IMG_FILE_TMP bs=1 count=1 seek=$((2*1024*1024*1024)) |
Dean Troyer | 61be924 | 2011-10-25 22:35:23 -0500 | [diff] [blame] | 160 | # Create filesystem image for RAM disk |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 161 | dd if=${NBD}p1 of=$IMG_FILE_TMP bs=1M |
Dean Troyer | 61be924 | 2011-10-25 22:35:23 -0500 | [diff] [blame] | 162 | |
| 163 | qemu-nbd -d $NBD |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 164 | NBD="" |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 165 | mv $IMG_FILE_TMP $IMG_FILE |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 166 | fi |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 167 | rm -f $IMG_FILE_TMP |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 168 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 169 | MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` |
Dean Troyer | 61be924 | 2011-10-25 22:35:23 -0500 | [diff] [blame] | 170 | mount -t ext4 -o loop $IMG_FILE $MNTDIR |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 171 | cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf |
| 172 | |
Dean Troyer | ea442c1 | 2011-10-26 12:34:59 -0500 | [diff] [blame] | 173 | # We need to install a non-virtual kernel and modules to boot from |
Dean Troyer | 7920b0f | 2011-10-26 15:10:46 -0500 | [diff] [blame] | 174 | if [ ! -r "`ls $MNTDIR/boot/vmlinuz-*-generic | head -1`" ]; then |
Dean Troyer | ea442c1 | 2011-10-26 12:34:59 -0500 | [diff] [blame] | 175 | chroot $MNTDIR apt-get install -y linux-generic |
| 176 | fi |
| 177 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 178 | git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH |
| 179 | git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH |
| 180 | git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH |
| 181 | git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH |
Tres Henry | ca85b79 | 2011-10-28 14:00:21 -0700 | [diff] [blame] | 182 | git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 183 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH |
| 184 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 185 | |
Dean Troyer | b5da519 | 2011-10-17 13:32:06 -0500 | [diff] [blame] | 186 | # Use this version of devstack |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 187 | rm -rf $MNTDIR/$DEST/devstack |
| 188 | cp -pr $CWD $MNTDIR/$DEST/devstack |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 189 | chroot $MNTDIR chown -R $STACK_USER $DEST/devstack |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 190 | |
Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 191 | # Configure host network for DHCP |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 192 | mkdir -p $MNTDIR/etc/network |
| 193 | cat > $MNTDIR/etc/network/interfaces <<EOF |
Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 194 | auto lo |
| 195 | iface lo inet loopback |
| 196 | |
| 197 | auto eth0 |
| 198 | iface eth0 inet dhcp |
| 199 | EOF |
| 200 | |
Dean Troyer | 288f3bd | 2011-10-13 15:50:44 -0500 | [diff] [blame] | 201 | # Set hostname |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 202 | echo "ramstack" >$MNTDIR/etc/hostname |
| 203 | echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts |
Dean Troyer | 288f3bd | 2011-10-13 15:50:44 -0500 | [diff] [blame] | 204 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 205 | # Configure the runner |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 206 | RUN_SH=$MNTDIR/$DEST/run.sh |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 207 | cat > $RUN_SH <<EOF |
| 208 | #!/usr/bin/env bash |
| 209 | |
Dean Troyer | 7c076ee | 2011-10-13 13:20:13 -0500 | [diff] [blame] | 210 | # Get IP range |
| 211 | set \`ip addr show dev eth0 | grep inet\` |
| 212 | PREFIX=\`echo \$2 | cut -d. -f1,2,3\` |
| 213 | export FLOATING_RANGE="\$PREFIX.224/27" |
| 214 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 215 | # Kill any existing screens |
| 216 | killall screen |
| 217 | |
| 218 | # Run stack.sh |
| 219 | cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log |
| 220 | echo >> $DEST/run.sh.log |
| 221 | echo >> $DEST/run.sh.log |
| 222 | echo "All done! Time to start clicking." >> $DEST/run.sh.log |
| 223 | EOF |
| 224 | |
| 225 | # Make the run.sh executable |
| 226 | chmod 755 $RUN_SH |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 227 | chroot $MNTDIR chown $STACK_USER $DEST/run.sh |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 228 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 229 | umount $MNTDIR |
| 230 | rmdir $MNTDIR |