devstack_custom/tools/build_usb_boot.sh

147 lines
3.3 KiB
Bash
Raw Normal View History

2011-10-12 01:32:07 +00:00
#!/bin/bash -e
# build_usb_boot.sh - Create a syslinux boot environment
#
2011-10-26 20:13:00 +00:00
# build_usb_boot.sh destdev
2011-10-12 01:32:07 +00:00
#
# Assumes syslinux is installed
# Needs to run as root
DEST_DIR=${1:-/tmp/syslinux-boot}
PXEDIR=${PXEDIR:-/opt/ramstack/pxe}
2011-10-12 01:32:07 +00:00
PROGDIR=`dirname $0`
# Clean up any resources that may be in use
cleanup() {
set +o errexit
# Mop up temporary files
if [ -n "$DEST_DEV" ]; then
umount $DEST_DIR
rmdir $DEST_DIR
fi
if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then
umount $MNTDIR
rmdir $MNTDIR
fi
# Kill ourselves to signal any calling process
trap 2; kill -2 $$
}
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-10-12 01:32:07 +00:00
if [ -b $DEST_DIR ]; then
# We have a block device, install syslinux and mount it
DEST_DEV=$DEST_DIR
2011-10-26 20:13:00 +00:00
DEST_DIR=`mktemp -d --tmpdir mntXXXXXX`
2011-10-17 19:55:10 +00:00
mount $DEST_DEV $DEST_DIR
if [ ! -d $DEST_DIR/syslinux ]; then
mkdir -p $DEST_DIR/syslinux
fi
2011-10-12 01:32:07 +00:00
# Install syslinux on the device
syslinux --install --directory syslinux $DEST_DEV
else
# We have a directory (for sanity checking output)
2011-10-17 19:55:10 +00:00
DEST_DEV=""
if [ ! -d $DEST_DIR/syslinux ]; then
mkdir -p $DEST_DIR/syslinux
fi
2011-10-12 01:32:07 +00:00
fi
# Get some more stuff from syslinux
for i in memdisk menu.c32; do
2011-10-26 20:52:34 +00:00
cp -pu /usr/lib/syslinux/$i $DEST_DIR/syslinux
2011-10-12 01:32:07 +00:00
done
CFG=$DEST_DIR/syslinux/syslinux.cfg
cat >$CFG <<EOF
default /syslinux/menu.c32
prompt 0
timeout 0
MENU TITLE devstack Boot Menu
2011-10-12 01:32:07 +00:00
EOF
# Setup devstack boot
mkdir -p $DEST_DIR/ubuntu
if [ ! -d $PXEDIR ]; then
mkdir -p $PXEDIR
fi
2011-10-26 20:13:00 +00:00
# Get image into place
if [ ! -r $PXEDIR/stack-initrd.img ]; then
cd $TOP_DIR
$PROGDIR/build_uec_ramdisk.sh $PXEDIR/stack-initrd.img
2011-10-26 20:13:00 +00:00
fi
if [ ! -r $PXEDIR/stack-initrd.gz ]; then
gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz
fi
2011-10-26 20:52:34 +00:00
cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
2011-10-26 20:13:00 +00:00
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-10-12 01:32:07 +00:00
echo "No kernel found"
2011-10-26 20:13:00 +00:00
umount $MNTDIR
rmdir $MNTDIR
if [ -n "$DEST_DEV" ]; then
umount $DEST_DIR
rmdir $DEST_DIR
fi
exit 1
2011-10-12 01:32:07 +00:00
else
2011-10-26 20:52:34 +00:00
cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR
2011-10-12 01:32:07 +00:00
fi
2011-10-26 20:13:00 +00:00
umount $MNTDIR
rmdir $MNTDIR
2011-10-12 01:32:07 +00:00
fi
2011-10-26 20:13:00 +00:00
# Get generic kernel version
KNAME=`basename $PXEDIR/vmlinuz-*-generic`
KVER=${KNAME#vmlinuz-}
2011-10-26 20:52:34 +00:00
cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu
2011-10-12 01:32:07 +00:00
cat >>$CFG <<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 $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
2011-10-26 20:52:34 +00:00
cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
2011-10-12 01:32:07 +00:00
cat >>$CFG <<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
fi
# Local disk boot
cat >>$CFG <<EOF
LABEL local
MENU LABEL ^Local disk
LOCALBOOT 0
EOF
if [ -n "$DEST_DEV" ]; then
umount $DEST_DIR
rmdir $DEST_DIR
fi
trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT