3 # Purpose: create a multiboot grml ISO using grml2usb
4 # Authors: Michael Prokop <mika@grml.org>,
5 # Thorsten Glaser <tg@mirbsd.org>
6 # Bug-Reports: see http://grml.org/bugs/
7 # License: This file is licensed under the GPL v2 or any later version.
8 ################################################################################
10 # * support isolinux as bootloader on the ISO
11 # * support setting grml2usb options (e.g. --bootoptions=...)
12 ################################################################################
14 # define function getfilesize before "set -e" {{{
15 if stat --help >/dev/null 2>&1; then
16 getfilesize='stat -c %s' # GNU stat
18 getfilesize='stat -f %z' # BSD stat
22 # adjust variables if necessary through environment {{{
23 # path to the grml2usb script you'd like to use
24 [ -n "$GRML2USB" ] || GRML2USB='grml2usb'
25 # work directory for creating the filesystem
26 [ -n "$WRKDIR" ] || WRKDIR='/tmp/grml2iso.tmp'
33 echo >&2 "Usage: $0 -o target.iso source1.iso [source2.iso ...]"
34 [ -n "$1" ] && exit $1 || exit 1
38 # command line handling {{{
39 [[ $# -gt 2 ]] || usage 1
42 while getopts ao: name; do
44 o) ISOFILE="$OPTARG";;
49 # make sure -o is specified
50 [ -n "$ISOFILE" ] || usage 1
52 # we don't to override any files by accident
53 if [ -e "$ISOFILE" ]; then
54 echo "Error: target file $ISOFILE exists already." >&2
58 shift $(($OPTIND - 1))
61 # we need root permissions for executing grml2usb {{{
62 if [[ $(id -u) != 0 ]]; then
63 echo >&2 "Error: please run $0 as root."
70 # note: grub-pc_1.96+20090603-1 seems to be b0rken
71 GRUB_VERSION="grub-pc_1.96+20080724-16"
76 *) ISOFILE=$ORIG_DIR/$ISOFILE ;;
80 # create necessary stuff under WRKDIR {{{
81 [ -d "$WRKDIR" ] && WRKDIR_EXISTED='true' || WRKDIR_EXISTED='false'
82 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
83 mkdir -p "$WRKDIR/cddir"
86 # execute grml2usb with all ISOs you'd like to install {{{
87 $GRML2USB "$@" "$WRKDIR/cddir"
90 # move syslinux to isolinux {{{
91 mv "$WRKDIR"/cddir/boot/syslinux "$WRKDIR"/cddir/boot/isolinux
94 echo "menu label ^Isolinux prompt" > boot/isolinux/promptname.cfg
95 echo "include hd.cfg" >> boot/isolinux/grmlmain.cfg
98 # generate the CD/DVD ISO {{{
99 mkisofs -V 'grml-multiboot' -l -r -J -no-pad \
100 -no-emul-boot -boot-load-size 4 -boot-info-table \
101 -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
105 # pad the output ISO to multiples of 256 KiB for partition table support {{{
106 siz=$($getfilesize "$ISOFILE")
107 cyls=$(echo "$siz / 512 / 32 / 16 + 1" | bc) # C=$cyls H=16 S=32
108 ofs=$(echo "$cyls * 16 * 32 * 512 - 1" | bc) # padding offset (size - 1)
109 dd if=/dev/zero bs=1 count=1 seek=$ofs of="$ISOFILE" 2>/dev/null
116 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
117 [[ $WRKDIR_EXISTED = 'false' ]] && rmdir "$WRKDIR"
118 echo "Generated $ISOFILE"
121 ## EOF #########################################################################
122 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3