Merge branch 'master' of github.com:cloudbuilders/devstack

This commit is contained in:
Anthony Young 2011-09-30 15:52:43 -07:00
commit 0b5f29c70d
4 changed files with 228 additions and 26 deletions

115
build_pxe_boot.sh Executable file
View file

@ -0,0 +1,115 @@
#!/bin/bash -e
# build_pxe_boot.sh - Create a PXE boot environment
#
# build_pxe_boot.sh [-k kernel-version] destdir
#
# Assumes syslinux is installed
# Assumes devstack files are in `pwd`/pxe
# Only needs to run as root if the destdir permissions require it
UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
MEMTEST_VER=4.10
MEMTEST_BIN=memtest86+-${MEMTEST_VER}.bin
MEMTEST_URL=http://www.memtest.org/download/${MEMTEST_VER}/
KVER=`uname -r`
if [ "$1" = "-k" ]; then
KVER=$2
shift;shift
fi
DEST_DIR=${1:-/tmp}/tftpboot
OPWD=`pwd`
PROGDIR=`dirname $0`
mkdir -p $DEST_DIR/pxelinux.cfg
cd $DEST_DIR
for i in memdisk menu.c32 pxelinux.0; do
cp -p /usr/lib/syslinux/$i $DEST_DIR
done
DEFAULT=$DEST_DIR/pxelinux.cfg/default
cat >$DEFAULT <<EOF
default menu.c32
prompt 0
timeout 0
MENU TITLE PXE Boot Menu
EOF
# Setup devstack boot
mkdir -p $DEST_DIR/ubuntu
if [ ! -d $OPWD/pxe ]; then
mkdir -p $OPWD/pxe
fi
if [ ! -r $OPWD/pxe/vmlinuz-${KVER} ]; then
sudo chmod 644 /boot/vmlinuz-${KVER}
if [ ! -r /boot/vmlinuz-${KVER} ]; then
echo "No kernel found"
else
cp -p /boot/vmlinuz-${KVER} $OPWD/pxe
fi
fi
cp -p $OPWD/pxe/vmlinuz-${KVER} $DEST_DIR/ubuntu
if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then
cd $OPWD
sudo $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz
fi
cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu
cat >>$DEFAULT <<EOF
LABEL devstack
MENU LABEL ^devstack
MENU DEFAULT
KERNEL ubuntu/vmlinuz-$KVER
APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
EOF
# Get Ubuntu
if [ -d $OPWD/pxe ]; then
cp -p $OPWD/pxe/natty-base-initrd.gz $DEST_DIR/ubuntu
fi
cat >>$DEFAULT <<EOF
LABEL ubuntu
MENU LABEL ^Ubuntu Natty
KERNEL ubuntu/vmlinuz-$KVER
APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
EOF
# Get Memtest
cd $DEST_DIR
if [ ! -r $MEMTEST_BIN ]; then
wget -N --quiet ${MEMTEST_URL}/${MEMTEST_BIN}.gz
gunzip $MEMTEST_BIN
fi
cat >>$DEFAULT <<EOF
LABEL memtest
MENU LABEL ^Memtest86+
KERNEL $MEMTEST_BIN
EOF
# Get FreeDOS
mkdir -p $DEST_DIR/freedos
cd $DEST_DIR/freedos
wget -N --quiet http://www.fdos.org/bootdisks/autogen/FDSTD.288.gz
gunzip -f FDSTD.288.gz
cat >>$DEFAULT <<EOF
LABEL freedos
MENU LABEL ^FreeDOS bootdisk
KERNEL memdisk
APPEND initrd=freedos/FDSTD.288
EOF
# Local disk boot
cat >>$DEFAULT <<EOF
LABEL local
MENU LABEL ^Local disk
MENU DEFAULT
LOCALBOOT 0
EOF

View file

@ -6,17 +6,19 @@ if [ ! "$#" -eq "1" ]; then
exit 1
fi
PROGDIR=`dirname $0`
# Source params
source ./stackrc
# clean install of natty
if [ ! -d natty-base ]; then
debootstrap natty natty-base
$PROGDIR/make_image.sh -C natty natty-base
# copy kernel modules...
# NOTE(ja): is there a better way to do this?
cp -pr /lib/modules/`uname -r` natty-base/lib/modules
cp files/sources.list natty-base/etc/apt/sources.list
chroot natty-base apt-get update
# a simple password - pass
echo root:pass | chroot natty-base chpasswd
fi
# prime natty with as many apt/pips as we can

View file

@ -1,27 +1,40 @@
#!/bin/bash
# make_image.sh - Create Ubuntu images in various formats
#
# make_image.sh release format
#
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
#
# Requires sudo to root
ROOTSIZE=${ROOTSIZE:-8192}
SWAPSIZE=${SWAPSIZE:-1024}
MIN_PKGS=${MIN_PKGS:-"apt-utils gpgv openssh-server"}
usage() {
echo "$0 - Create Ubuntu images"
echo "Usage: $0 - Create Ubuntu images"
echo ""
echo "$0 [-r rootsize] [-s swapsize] release format"
echo "$0 [-m] [-r rootsize] [-s swapsize] release format"
echo "$0 -C [-m] release chrootdir"
echo "$0 -I [-r rootsize] [-s swapsize] chrootdir format"
echo ""
echo "-C - Create the initial chroot dir"
echo "-I - Create the final image from a chroot"
echo "-m - minimal installation"
echo "-r size - root fs size in MB"
echo "-s size - swap fs size in MB"
echo "release - Ubuntu release: jaunty - oneric"
echo "format - image format: qcow2, vmdk, vdi, vhd, xen, raw, fs"
exit 1
}
while getopts hm:r:s: c; do
while getopts CIhmr:s: c; do
case $c in
C) CHROOTONLY=1
;;
I) IMAGEONLY=1
;;
h) usage
;;
m) MIRROR=$OPTARG
m) MINIMAL=1
;;
r) ROOTSIZE=$OPTARG
;;
@ -31,8 +44,26 @@ while getopts hm:r:s: c; do
done
shift `expr $OPTIND - 1`
if [ ! "$#" -eq "2" -o -n "$CHROOTONLY" -a -n "$IMAGEONLY" ]; then
usage
fi
# Default args
RELEASE=$1
FORMAT=$2
CHROOTDIR=""
if [ -n "$CHROOTONLY" ]; then
RELEASE=$1
CHROOTDIR=$2
FORMAT="pass"
fi
if [ -n "$IMAGEONLY" ]; then
CHROOTDIR=$1
FORMAT=$2
RELEASE="pass"
fi
case $FORMAT in
kvm|qcow2) FORMAT=qcow2
@ -60,6 +91,7 @@ case $FORMAT in
QFORMAT=raw
HYPER=kvm
;;
pass) ;;
*) echo "Unknown format: $FORMAT"
usage
esac
@ -70,6 +102,7 @@ case $RELEASE in
lucid) ;;
karmic) ;;
jaunty) ;;
pass) ;;
*) echo "Unknown release: $RELEASE"
usage
;;
@ -80,18 +113,60 @@ if [ -z `which vmbuilder` ]; then
sudo apt-get install ubuntu-vm-builder
fi
if [ -n "$CHROOTONLY" ]; then
# Build a chroot directory
HYPER=kvm
if [ "$MINIMAL" = 1 ]; then
ARGS="--variant=minbase"
for i in $MIN_PKGS; do
ARGS="$ARGS --addpkg=$i"
done
fi
sudo vmbuilder $HYPER ubuntu $ARGS \
--suite $RELEASE \
--only-chroot \
--chroot-dir=$CHROOTDIR \
--overwrite \
--addpkg=$MIN_PKGS \
sudo cp -p files/sources.list $CHROOTDIR/etc/apt/sources.list
sudo chroot $CHROOTDIR apt-get update
exit 0
fi
# Build the image
TMPDIR=tmp
TMPDISK=`mktemp imgXXXXXXXX`
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE
sudo vmbuilder $HYPER ubuntu --suite $RELEASE \
-o \
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE count=1
if [ -n "$IMAGEONLY" ]; then
# Build image from chroot
sudo vmbuilder $HYPER ubuntu $ARGS \
--existing-chroot=$CHR \
--overwrite \
--rootsize=$ROOTSIZE \
--swapsize=$SWAPSIZE \
--tmpfs - \
--addpkg=openssh-server \
--raw=$TMPDISK \
else
# Do the whole shebang in one pass
ARGS="--variant=minbase"
for i in $MIN_PKGS; do
ARGS="$ARGS --addpkg=$i"
done
sudo vmbuilder $HYPER ubuntu $ARGS \
--suite $RELEASE \
--overwrite \
--rootsize=$ROOTSIZE \
--swapsize=$SWAPSIZE \
--tmpfs - \
--raw=$TMPDISK \
fi
if [ "$FORMAT" = "raw" ]; then
# Get image
mv $TMPDISK $RELEASE.$FORMAT

View file

@ -26,10 +26,6 @@ if ! grep -q natty /etc/lsb-release; then
fi
fi
#The following makes fresh mininmal installs (i.e. LXCs) happy
apt-get update
apt-get install -y sudo
# stack.sh keeps the list of **apt** and **pip** dependencies in external
# files, along with config templates and other useful files. You can find these
# in the ``files`` directory (next to this script). We will reference this
@ -40,12 +36,26 @@ if [ ! -d $FILES ]; then
exit 1
fi
# you need to run this as a regular user with sudo priviledges
# If stack.sh is run as root, it automatically creates a stack user with
# sudo privileges and runs as that user.
if [[ $EUID -eq 0 ]]; then
echo "This script cannot be run as root." 1>&2
echo "You should run this script as the user you wish openstack to run as" 1>&2
echo "The user will need to be a sudoer (without password)" 1>&2
exit 1
echo "You are running this script as root."
apt-get update
apt-get install -y sudo
if ! getent passwd | grep -q stack; then
echo "Creating a user called stack"
useradd -g sudo -s /bin/bash -m stack
fi
echo "Making sure stack has passwordless sudo"
sed -i "/^%sudo/ { / ALL/ { s/ ALL/ NOPASSWD:ALL/ }}" /etc/sudoers
echo "Copying files to stack user"
cp -r -f `pwd` /home/stack/
THIS_DIR=$(basename $(dirname $(readlink -f $0)))
chown -R stack:sudo /home/stack/$THIS_DIR
echo "Running the script as stack in 3 seconds..."
sleep 3
exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
exit 0
fi