devstack_custom/tools/build_usb_boot.sh

122 lines
2.7 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:-/var/cache/devstack/pxe}
OPWD=`pwd`
PROGDIR=`dirname $0`
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 Boot Menu
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 $OPWD
$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
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