#!/bin/bash -e # **build_usb_boot.sh** # Create a syslinux boot environment # # build_usb_boot.sh destdev # # Assumes syslinux is installed # Needs to run as root DEST_DIR=${1:-/tmp/syslinux-boot} PXEDIR=${PXEDIR:-/opt/ramstack/pxe} # 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` if [ -b $DEST_DIR ]; then # We have a block device, install syslinux and mount it DEST_DEV=$DEST_DIR DEST_DIR=`mktemp -d --tmpdir mntXXXXXX` mount $DEST_DEV $DEST_DIR if [ ! -d $DEST_DIR/syslinux ]; then mkdir -p $DEST_DIR/syslinux fi # Install syslinux on the device syslinux --install --directory syslinux $DEST_DEV else # We have a directory (for sanity checking output) DEST_DEV="" if [ ! -d $DEST_DIR/syslinux ]; then mkdir -p $DEST_DIR/syslinux fi fi # Get some more stuff from syslinux for i in memdisk menu.c32; do cp -pu /usr/lib/syslinux/$i $DEST_DIR/syslinux done CFG=$DEST_DIR/syslinux/syslinux.cfg cat >$CFG <$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 echo "No kernel found" umount $MNTDIR rmdir $MNTDIR if [ -n "$DEST_DEV" ]; then umount $DEST_DIR rmdir $DEST_DIR fi exit 1 else cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR fi umount $MNTDIR rmdir $MNTDIR fi # Get generic kernel version KNAME=`basename $PXEDIR/vmlinuz-*-generic` KVER=${KNAME#vmlinuz-} cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu cat >>$CFG <>$CFG <>$CFG <