2011-09-30 02:30:27 +00:00
|
|
|
#!/bin/bash -e
|
2011-11-11 21:51:55 +00:00
|
|
|
# build_pxe_env.sh - Create a PXE boot environment
|
2011-09-27 22:53:11 +00:00
|
|
|
#
|
2011-11-11 21:51:55 +00:00
|
|
|
# build_pxe_env.sh destdir
|
|
|
|
#
|
|
|
|
# Requires Ubuntu Oneiric
|
2011-09-27 22:53:11 +00:00
|
|
|
#
|
2011-09-28 19:14:33 +00:00
|
|
|
# Only needs to run as root if the destdir permissions require it
|
2011-09-27 22:53:11 +00:00
|
|
|
|
2011-11-11 21:51:55 +00:00
|
|
|
dpkg -l syslinux || apt-get install -y syslinux
|
|
|
|
|
2011-09-28 03:19:32 +00:00
|
|
|
DEST_DIR=${1:-/tmp}/tftpboot
|
2011-11-20 18:02:26 +00:00
|
|
|
PXEDIR=${PXEDIR:-/opt/ramstack/pxe}
|
2011-09-29 21:15:23 +00:00
|
|
|
PROGDIR=`dirname $0`
|
2011-09-27 22:53:11 +00:00
|
|
|
|
2011-11-01 22:44:03 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
# Kill ourselves to signal any calling process
|
|
|
|
trap 2; kill -2 $$
|
|
|
|
}
|
|
|
|
|
2011-11-20 18:02:26 +00:00
|
|
|
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
|
|
|
|
|
|
|
|
# Keep track of the current directory
|
|
|
|
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
|
|
|
|
TOP_DIR=`cd $TOOLS_DIR/..; pwd`
|
2011-11-01 22:44:03 +00:00
|
|
|
|
2011-09-28 03:19:32 +00:00
|
|
|
mkdir -p $DEST_DIR/pxelinux.cfg
|
|
|
|
cd $DEST_DIR
|
|
|
|
for i in memdisk menu.c32 pxelinux.0; do
|
2011-10-26 21:05:28 +00:00
|
|
|
cp -pu /usr/lib/syslinux/$i $DEST_DIR
|
2011-09-28 03:19:32 +00:00
|
|
|
done
|
|
|
|
|
2011-10-12 01:28:39 +00:00
|
|
|
CFG=$DEST_DIR/pxelinux.cfg/default
|
|
|
|
cat >$CFG <<EOF
|
2011-09-27 22:53:11 +00:00
|
|
|
default menu.c32
|
|
|
|
prompt 0
|
2011-09-28 19:14:33 +00:00
|
|
|
timeout 0
|
2011-09-27 22:53:11 +00:00
|
|
|
|
2011-11-20 18:02:26 +00:00
|
|
|
MENU TITLE devstack PXE Boot Menu
|
2011-09-27 22:53:11 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2011-09-29 21:15:23 +00:00
|
|
|
# Setup devstack boot
|
2011-09-27 22:53:11 +00:00
|
|
|
mkdir -p $DEST_DIR/ubuntu
|
2011-10-03 16:43:28 +00:00
|
|
|
if [ ! -d $PXEDIR ]; then
|
|
|
|
mkdir -p $PXEDIR
|
2011-09-29 21:15:23 +00:00
|
|
|
fi
|
2011-10-26 21:05:28 +00:00
|
|
|
|
|
|
|
# Get image into place
|
|
|
|
if [ ! -r $PXEDIR/stack-initrd.img ]; then
|
2011-11-20 18:02:26 +00:00
|
|
|
cd $TOP_DIR
|
2011-10-26 21:05:28 +00:00
|
|
|
$PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img
|
|
|
|
fi
|
|
|
|
if [ ! -r $PXEDIR/stack-initrd.gz ]; then
|
|
|
|
gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz
|
|
|
|
fi
|
|
|
|
cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
|
|
|
|
|
|
|
|
if [ ! -r $PXEDIR/vmlinuz-*-generic ]; then
|
|
|
|
MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
|
|
|
|
mount -t ext4 -o loop $PXEDIR/stack-initrd.img $MNTDIR
|
|
|
|
|
|
|
|
if [ ! -r $MNTDIR/boot/vmlinuz-*-generic ]; then
|
2011-09-29 21:15:23 +00:00
|
|
|
echo "No kernel found"
|
2011-10-26 21:05:28 +00:00
|
|
|
umount $MNTDIR
|
|
|
|
rmdir $MNTDIR
|
|
|
|
exit 1
|
2011-09-29 21:15:23 +00:00
|
|
|
else
|
2011-10-26 21:05:28 +00:00
|
|
|
cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR
|
2011-09-29 21:15:23 +00:00
|
|
|
fi
|
2011-10-26 21:05:28 +00:00
|
|
|
umount $MNTDIR
|
|
|
|
rmdir $MNTDIR
|
2011-09-29 21:15:23 +00:00
|
|
|
fi
|
2011-10-26 21:05:28 +00:00
|
|
|
|
|
|
|
# Get generic kernel version
|
|
|
|
KNAME=`basename $PXEDIR/vmlinuz-*-generic`
|
|
|
|
KVER=${KNAME#vmlinuz-}
|
|
|
|
cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu
|
2011-10-12 01:28:39 +00:00
|
|
|
cat >>$CFG <<EOF
|
2011-09-29 21:15:23 +00:00
|
|
|
|
|
|
|
LABEL devstack
|
|
|
|
MENU LABEL ^devstack
|
|
|
|
MENU DEFAULT
|
2011-09-30 14:22:23 +00:00
|
|
|
KERNEL ubuntu/vmlinuz-$KVER
|
2011-09-29 21:15:23 +00:00
|
|
|
APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Get Ubuntu
|
2011-10-12 01:28:39 +00:00
|
|
|
if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
|
2011-10-26 21:05:28 +00:00
|
|
|
cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
|
2011-10-12 01:28:39 +00:00
|
|
|
cat >>$CFG <<EOF
|
2011-09-27 22:53:11 +00:00
|
|
|
|
|
|
|
LABEL ubuntu
|
2011-09-29 21:15:23 +00:00
|
|
|
MENU LABEL ^Ubuntu Natty
|
2011-09-30 14:22:23 +00:00
|
|
|
KERNEL ubuntu/vmlinuz-$KVER
|
2011-09-29 21:15:23 +00:00
|
|
|
APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
|
2011-09-27 22:53:11 +00:00
|
|
|
EOF
|
2011-09-28 03:19:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Local disk boot
|
2011-10-12 01:28:39 +00:00
|
|
|
cat >>$CFG <<EOF
|
2011-09-28 03:19:32 +00:00
|
|
|
|
|
|
|
LABEL local
|
2011-09-29 21:15:23 +00:00
|
|
|
MENU LABEL ^Local disk
|
2011-09-28 03:19:32 +00:00
|
|
|
LOCALBOOT 0
|
|
|
|
EOF
|
2011-11-20 18:02:26 +00:00
|
|
|
|
|
|
|
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
|