Merge branch 'master' of github.com:cloudbuilders/devstack
This commit is contained in:
commit
0b5f29c70d
4 changed files with 228 additions and 26 deletions
115
build_pxe_boot.sh
Executable file
115
build_pxe_boot.sh
Executable 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
|
|
@ -6,17 +6,19 @@ if [ ! "$#" -eq "1" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
PROGDIR=`dirname $0`
|
||||||
|
|
||||||
# Source params
|
# Source params
|
||||||
source ./stackrc
|
source ./stackrc
|
||||||
|
|
||||||
# clean install of natty
|
# clean install of natty
|
||||||
if [ ! -d natty-base ]; then
|
if [ ! -d natty-base ]; then
|
||||||
debootstrap natty natty-base
|
$PROGDIR/make_image.sh -C natty natty-base
|
||||||
# copy kernel modules...
|
# copy kernel modules...
|
||||||
# NOTE(ja): is there a better way to do this?
|
# NOTE(ja): is there a better way to do this?
|
||||||
cp -pr /lib/modules/`uname -r` natty-base/lib/modules
|
cp -pr /lib/modules/`uname -r` natty-base/lib/modules
|
||||||
cp files/sources.list natty-base/etc/apt/sources.list
|
# a simple password - pass
|
||||||
chroot natty-base apt-get update
|
echo root:pass | chroot natty-base chpasswd
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# prime natty with as many apt/pips as we can
|
# prime natty with as many apt/pips as we can
|
||||||
|
|
103
make_image.sh
103
make_image.sh
|
@ -1,27 +1,40 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# make_image.sh - Create Ubuntu images in various formats
|
# 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
|
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
|
||||||
#
|
#
|
||||||
# Requires sudo to root
|
# Requires sudo to root
|
||||||
|
|
||||||
ROOTSIZE=${ROOTSIZE:-8192}
|
ROOTSIZE=${ROOTSIZE:-8192}
|
||||||
SWAPSIZE=${SWAPSIZE:-1024}
|
SWAPSIZE=${SWAPSIZE:-1024}
|
||||||
|
MIN_PKGS=${MIN_PKGS:-"apt-utils gpgv openssh-server"}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "$0 - Create Ubuntu images"
|
echo "Usage: $0 - Create Ubuntu images"
|
||||||
echo ""
|
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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts hm:r:s: c; do
|
while getopts CIhmr:s: c; do
|
||||||
case $c in
|
case $c in
|
||||||
|
C) CHROOTONLY=1
|
||||||
|
;;
|
||||||
|
I) IMAGEONLY=1
|
||||||
|
;;
|
||||||
h) usage
|
h) usage
|
||||||
;;
|
;;
|
||||||
m) MIRROR=$OPTARG
|
m) MINIMAL=1
|
||||||
;;
|
;;
|
||||||
r) ROOTSIZE=$OPTARG
|
r) ROOTSIZE=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
@ -31,8 +44,26 @@ while getopts hm:r:s: c; do
|
||||||
done
|
done
|
||||||
shift `expr $OPTIND - 1`
|
shift `expr $OPTIND - 1`
|
||||||
|
|
||||||
|
if [ ! "$#" -eq "2" -o -n "$CHROOTONLY" -a -n "$IMAGEONLY" ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Default args
|
||||||
RELEASE=$1
|
RELEASE=$1
|
||||||
FORMAT=$2
|
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
|
case $FORMAT in
|
||||||
kvm|qcow2) FORMAT=qcow2
|
kvm|qcow2) FORMAT=qcow2
|
||||||
|
@ -60,6 +91,7 @@ case $FORMAT in
|
||||||
QFORMAT=raw
|
QFORMAT=raw
|
||||||
HYPER=kvm
|
HYPER=kvm
|
||||||
;;
|
;;
|
||||||
|
pass) ;;
|
||||||
*) echo "Unknown format: $FORMAT"
|
*) echo "Unknown format: $FORMAT"
|
||||||
usage
|
usage
|
||||||
esac
|
esac
|
||||||
|
@ -70,6 +102,7 @@ case $RELEASE in
|
||||||
lucid) ;;
|
lucid) ;;
|
||||||
karmic) ;;
|
karmic) ;;
|
||||||
jaunty) ;;
|
jaunty) ;;
|
||||||
|
pass) ;;
|
||||||
*) echo "Unknown release: $RELEASE"
|
*) echo "Unknown release: $RELEASE"
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
@ -80,17 +113,59 @@ if [ -z `which vmbuilder` ]; then
|
||||||
sudo apt-get install ubuntu-vm-builder
|
sudo apt-get install ubuntu-vm-builder
|
||||||
fi
|
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
|
# Build the image
|
||||||
|
TMPDIR=tmp
|
||||||
TMPDISK=`mktemp imgXXXXXXXX`
|
TMPDISK=`mktemp imgXXXXXXXX`
|
||||||
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
|
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
|
||||||
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE
|
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE count=1
|
||||||
sudo vmbuilder $HYPER ubuntu --suite $RELEASE \
|
|
||||||
-o \
|
if [ -n "$IMAGEONLY" ]; then
|
||||||
--rootsize=$ROOTSIZE \
|
# Build image from chroot
|
||||||
--swapsize=$SWAPSIZE \
|
sudo vmbuilder $HYPER ubuntu $ARGS \
|
||||||
--tmpfs - \
|
--existing-chroot=$CHR \
|
||||||
--addpkg=openssh-server \
|
--overwrite \
|
||||||
--raw=$TMPDISK \
|
--rootsize=$ROOTSIZE \
|
||||||
|
--swapsize=$SWAPSIZE \
|
||||||
|
--tmpfs - \
|
||||||
|
--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
|
if [ "$FORMAT" = "raw" ]; then
|
||||||
# Get image
|
# Get image
|
||||||
|
|
28
stack.sh
28
stack.sh
|
@ -26,10 +26,6 @@ if ! grep -q natty /etc/lsb-release; then
|
||||||
fi
|
fi
|
||||||
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
|
# 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
|
# 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
|
# in the ``files`` directory (next to this script). We will reference this
|
||||||
|
@ -40,12 +36,26 @@ if [ ! -d $FILES ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
if [[ $EUID -eq 0 ]]; then
|
||||||
echo "This script cannot be run as root." 1>&2
|
echo "You are running this script as root."
|
||||||
echo "You should run this script as the user you wish openstack to run as" 1>&2
|
apt-get update
|
||||||
echo "The user will need to be a sudoer (without password)" 1>&2
|
apt-get install -y sudo
|
||||||
exit 1
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue