#!/bin/ksh # Define the MKBOOT_ISOLINUX and/or MKBOOT_MENUC32 environment variables to override their default # locations. ISOLINUX=${MKBOOT_ISOLINUX:-/usr/share/syslinux/isolinux.bin} MENUC32=${MKBOOT_MENUC32:-/usr/share/syslinux/menu.c32} #### END of configuration section. export TARGET="/tmp/makebootcd.$$" function cleanup { rm -rf $TARGET exit 1 } function execute { $* if [[ $? -ne 0 ]] then echo "Command '$*' ended in an error" 1>&2 cleanup fi } trap "cleanup" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 function printHelp { ( echo $* echo "" echo "Usage: makebootiso " echo "" echo " Takes an xml specification of one or more systems to boot" echo " and creates an output ISO image that can be put onto a USB or CD/DVD" echo " for booting a system using isolinux." echo "" echo " Example: " echo " # create the iso" echo " makebootiso example/boot.xml boot.iso" echo " # copy to USB " echo " dd if=boot.iso of=/dev/sda bs=10M " echo "" echo " The XML file consists of two parts:" echo " Part 1 describes a number of kernel/initrd pairs identified " echo " by symbolic short names for use by isolinux." echo " Part 2 describes the systems to boot. For each system to boot" echo " a short label and longer one line description are specified," echo " together with a reference to kernel/initrd pair from part 1" echo " in addition, the root directory and kernel options are specified" echo "" echo " The benefits of this tool over direct isolinux use are: " echo " - allows use of long names in the input making it easier to " echo " maintain the iso images. The short names required by isolinux" echo " are a maintenance problem" echo " - reduction of duplication. In many cases the same kernel/initrd" echo " pair is used for different setups. This avoids duplication that" echo " would occur in a isolinux.cfg file" echo " - reduction of errors. It is almost foolproof. If you have the " echo " kernel, initrd image, root diractory, and kernel options then" echo " you can boot a system. Much less error prone than direct isolinux" echo " use." echo "" echo " Cavaets:" echo " This tool only exposes the bare minimum of what isolinux can do." echo " However, it is really helpful for solving technical problems by" echo " making it very easy to create a bootable USB or CD/DVD." echo "" echo " Credits:" echo " Thanks to the isolinux community for providing the excellent" echo " isolinux tools" ) 1>&2 exit 1 } if [[ $# -ne 2 ]] then printHelp fi XML="$1" if [[ ! -f "$XML" || ! -r "$XML" ]] then printHelp "'$XML' not found or not readable" fi OUTPUT="$2" # validate the input XSD_DIR=$( dirname $0 )/../xsd XSD_BOOT=$XSD_DIR/bootspec.xsd execute xmllint --noout --schema $XSD_BOOT $XML #TARGET=target export CONTENT=$TARGET/content rm -rf $TARGET mkdir -p $TARGET mkdir -p $CONTENT XSLDIR=$( dirname $0 )/../xsl XSL_ISOLINUX=$XSLDIR/isolinux.xsl XSL_GENKERNELS=$XSLDIR/genkernels.xsl # copy isolinux files. execute cp $ISOLINUX $CONTENT execute cp $MENUC32 $CONTENT # generate isolinux.cfg execute xsltproc $XSL_ISOLINUX $XML > $CONTENT/isolinux.cfg # generate the script to ciopy kernel and initrd execute xsltproc --stringparam curdir $( dirname $XML ) $XSL_GENKERNELS $XML > $TARGET/genkernel.sh execute chmod 755 $TARGET/genkernel.sh execute $TARGET/genkernel.sh ( cd "$CONTENT" execute mkisofs -o ../boot.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table $( find . -type f ) isohybrid ../boot.iso ) execute cp $TARGET/boot.iso "$OUTPUT" echo "Image is on '$OUTPUT'" rm -rf $TARGET