devstack/tools/build_ramdisk.sh

232 lines
5.9 KiB
Bash
Raw Normal View History

#!/bin/bash
# **build_ramdisk.sh**
# Build RAM disk images
# Exit on error to stop unexpected errors
2011-11-01 12:36:59 -05:00
set -o errexit
if [ ! "$#" -eq "1" ]; then
2011-11-01 12:36:59 -05:00
echo "$0 builds a gziped Ubuntu OpenStack install"
echo "usage: $0 dest"
exit 1
fi
# Clean up any resources that may be in use
cleanup() {
set +o errexit
# Mop up temporary files
if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then
umount $MNTDIR
rmdir $MNTDIR
fi
if [ -n "$DEV_FILE_TMP" -a -e "$DEV_FILE_TMP "]; then
rm -f $DEV_FILE_TMP
fi
if [ -n "$IMG_FILE_TMP" -a -e "$IMG_FILE_TMP" ]; then
rm -f $IMG_FILE_TMP
fi
# Release NBD devices
if [ -n "$NBD" ]; then
qemu-nbd -d $NBD
fi
# Kill ourselves to signal any calling process
trap 2; kill -2 $$
}
trap cleanup SIGHUP SIGINT SIGTERM
2011-11-01 15:46:14 -05:00
# Set up nbd
modprobe nbd max_part=63
2011-11-01 12:36:59 -05:00
# Echo commands
set -o xtrace
2011-10-25 17:53:24 -05:00
IMG_FILE=$1
2011-11-01 12:36:59 -05:00
# Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
# Import common functions
. $TOP_DIR/functions
2011-11-01 12:36:59 -05:00
# Store cwd
CWD=`pwd`
cd $TOP_DIR
# Source params
source ./stackrc
CACHEDIR=${CACHEDIR:-/opt/stack/cache}
2011-10-03 09:56:41 -05:00
2011-10-03 09:40:32 -05:00
DEST=${DEST:-/opt/stack}
2011-11-01 12:36:59 -05:00
# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
# Base image (natty by default)
DIST_NAME=${DIST_NAME:-natty}
2011-10-11 20:22:23 -05:00
# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
STACKSH_PARAMS=${STACKSH_PARAMS:-}
2011-10-03 11:14:13 -05:00
# Option to use the version of devstack on which we are currently working
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
2011-11-01 12:36:59 -05:00
# clean install
if [ ! -r $CACHEDIR/$DIST_NAME-base.img ]; then
$TOOLS_DIR/get_uec_image.sh $DIST_NAME $CACHEDIR/$DIST_NAME-base.img
fi
2011-11-01 15:46:14 -05:00
# Finds the next available NBD device
# Exits script if error connecting or none free
# map_nbd image
# Returns full nbd device path
2011-11-01 15:46:14 -05:00
function map_nbd {
for i in `seq 0 15`; do
if [ ! -e /sys/block/nbd$i/pid ]; then
NBD=/dev/nbd$i
# Connect to nbd and wait till it is ready
qemu-nbd -c $NBD $1
if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
echo "Couldn't connect $NBD"
exit 1
fi
break
fi
done
if [ -z "$NBD" ]; then
echo "No free NBD slots"
2011-10-25 17:53:24 -05:00
exit 1
fi
2011-11-01 15:46:14 -05:00
echo $NBD
}
# Prime image with as many apt as we can
2011-11-01 15:46:14 -05:00
DEV_FILE=$CACHEDIR/$DIST_NAME-dev.img
DEV_FILE_TMP=`mktemp $DEV_FILE.XXXXXX`
if [ ! -r $DEV_FILE ]; then
cp -p $CACHEDIR/$DIST_NAME-base.img $DEV_FILE_TMP
NBD=`map_nbd $DEV_FILE_TMP`
2011-10-25 17:53:24 -05:00
MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
mount -t ext4 ${NBD}p1 $MNTDIR
cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
chroot $MNTDIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1`
chroot $MNTDIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1`
2011-10-20 10:07:10 -07:00
# Create a stack user that is a member of the libvirtd group so that stack
# is able to interact with libvirt.
2011-10-25 17:53:24 -05:00
chroot $MNTDIR groupadd libvirtd
chroot $MNTDIR useradd $STACK_USER -s /bin/bash -d $DEST -G libvirtd
2011-10-25 17:53:24 -05:00
mkdir -p $MNTDIR/$DEST
chroot $MNTDIR chown $STACK_USER $DEST
# A simple password - pass
echo $STACK_USER:pass | chroot $MNTDIR chpasswd
2011-11-01 15:46:14 -05:00
echo root:$ROOT_PASSWORD | chroot $MNTDIR chpasswd
# And has sudo ability (in the future this should be limited to only what
# stack requires)
echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
2011-10-25 17:53:24 -05:00
umount $MNTDIR
rmdir $MNTDIR
qemu-nbd -d $NBD
NBD=""
2011-11-01 15:46:14 -05:00
mv $DEV_FILE_TMP $DEV_FILE
fi
2011-11-01 15:46:14 -05:00
rm -f $DEV_FILE_TMP
# Clone git repositories onto the system
# ======================================
2011-11-01 15:46:14 -05:00
IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX`
2011-10-25 17:53:24 -05:00
if [ ! -r $IMG_FILE ]; then
2011-11-01 15:46:14 -05:00
NBD=`map_nbd $DEV_FILE`
# Pre-create the image file
# FIXME(dt): This should really get the partition size to
# pre-create the image file
2011-11-01 15:46:14 -05:00
dd if=/dev/zero of=$IMG_FILE_TMP bs=1 count=1 seek=$((2*1024*1024*1024))
# Create filesystem image for RAM disk
2011-11-01 15:46:14 -05:00
dd if=${NBD}p1 of=$IMG_FILE_TMP bs=1M
qemu-nbd -d $NBD
NBD=""
2011-11-01 15:46:14 -05:00
mv $IMG_FILE_TMP $IMG_FILE
2011-10-25 17:53:24 -05:00
fi
2011-11-01 15:46:14 -05:00
rm -f $IMG_FILE_TMP
2011-10-25 17:53:24 -05:00
MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
mount -t ext4 -o loop $IMG_FILE $MNTDIR
2011-10-25 17:53:24 -05:00
cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
# We need to install a non-virtual kernel and modules to boot from
2011-10-26 15:10:46 -05:00
if [ ! -r "`ls $MNTDIR/boot/vmlinuz-*-generic | head -1`" ]; then
chroot $MNTDIR apt-get install -y linux-generic
fi
2011-10-03 09:40:32 -05:00
git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
2011-10-28 14:00:21 -07:00
git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
2011-10-03 09:40:32 -05:00
git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
2011-10-17 13:32:06 -05:00
# Use this version of devstack
2011-10-25 17:53:24 -05:00
rm -rf $MNTDIR/$DEST/devstack
cp -pr $CWD $MNTDIR/$DEST/devstack
chroot $MNTDIR chown -R $STACK_USER $DEST/devstack
2011-10-03 09:56:41 -05:00
2011-10-03 13:42:16 -05:00
# Configure host network for DHCP
2011-10-25 17:53:24 -05:00
mkdir -p $MNTDIR/etc/network
cat > $MNTDIR/etc/network/interfaces <<EOF
2011-10-03 13:42:16 -05:00
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
2011-10-13 15:50:44 -05:00
# Set hostname
2011-10-25 17:53:24 -05:00
echo "ramstack" >$MNTDIR/etc/hostname
echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
2011-10-13 15:50:44 -05:00
2011-10-11 20:22:23 -05:00
# Configure the runner
2011-10-25 17:53:24 -05:00
RUN_SH=$MNTDIR/$DEST/run.sh
2011-10-11 20:22:23 -05:00
cat > $RUN_SH <<EOF
#!/usr/bin/env bash
2011-10-13 13:20:13 -05:00
# Get IP range
set \`ip addr show dev eth0 | grep inet\`
PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
export FLOATING_RANGE="\$PREFIX.224/27"
2011-10-11 20:22:23 -05:00
# Kill any existing screens
killall screen
# Run stack.sh
cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
echo >> $DEST/run.sh.log
echo >> $DEST/run.sh.log
echo "All done! Time to start clicking." >> $DEST/run.sh.log
EOF
# Make the run.sh executable
chmod 755 $RUN_SH
chroot $MNTDIR chown $STACK_USER $DEST/run.sh
2011-10-25 17:53:24 -05:00
umount $MNTDIR
rmdir $MNTDIR