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 setting grml2usb options
11 ################################################################################
13 # define function getfilesize before "set -e" {{{
14 if stat --help >/dev/null 2>&1; then
15 getfilesize='stat -c %s' # GNU stat
17 getfilesize='stat -f %z' # BSD stat
21 # adjust variables if necessary through environment {{{
22 # path to the grml2usb script you'd like to use
23 [ -n "$GRML2USB" ] || GRML2USB='grml2usb'
24 # work directory for creating the filesystem
25 [ -n "$WRKDIR" ] || WRKDIR='/tmp/grml2iso.tmp'
32 echo >&2 "Usage: $0 [OPTIONS] -o target.iso source1.iso [source2.iso ...]"
35 -b Boot Params Additional boot parameters passed to grml2usb
36 -c Directory Copy files from directory to generated iso
37 -f Force overwrite of existing target.iso
39 [ -n "$1" ] && exit $1 || exit 1
43 # command line handling {{{
44 [[ $# -gt 2 ]] || usage 1
50 while getopts fb:c:o: name; do
52 o) ISOFILE="$OPTARG";;
53 b) GRML2USB_PARAMS='--bootoptions='"${OPTARG}";;
60 # make sure -o is specified
61 [ -n "$ISOFILE" ] || usage 1
63 # we don't to override any files by accident
64 if [ -e "$ISOFILE" -a ! -n "$FORCE" ]; then
65 echo "Error: target file $ISOFILE exists already." >&2
69 if [ ! -z "$DIR" -a ! -d "$DIR" ] ; then
70 echo "Error: specified parameter for -c is not a directory" >&2
74 shift $(($OPTIND - 1))
77 # we need root permissions for executing grml2usb {{{
78 if [[ $(id -u) != 0 ]]; then
79 echo >&2 "Error: please run $0 as root."
86 # note: grub-pc_1.96+20090603-1 seems to be b0rken
87 GRUB_VERSION="grub-pc_1.96+20080724-16"
92 *) ISOFILE=$ORIG_DIR/$ISOFILE ;;
96 # create necessary stuff under WRKDIR {{{
97 [ -d "$WRKDIR" ] && WRKDIR_EXISTED='true' || WRKDIR_EXISTED='false'
98 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
99 mkdir -p "$WRKDIR/cddir"
102 # execute grml2usb with all ISOs you'd like to install {{{
103 $GRML2USB "${GRML2USB_PARAMS}" "$@" "$WRKDIR/cddir"
106 # move syslinux to isolinux {{{
107 mv "$WRKDIR"/cddir/boot/syslinux "$WRKDIR"/cddir/boot/isolinux
110 echo "menu label ^Isolinux prompt" > boot/isolinux/promptname.cfg
111 echo "include hd.cfg" >> boot/isolinux/grmlmain.cfg
114 # copy specified directory to cd {{{
115 if [ -n "$DIR" ] ; then
116 echo >&2 "Copying ${DIR} to generated iso"
122 # generate the CD/DVD ISO {{{
123 mkisofs -V 'grml-multiboot' -l -r -J -no-pad \
124 -no-emul-boot -boot-load-size 4 -boot-info-table \
125 -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
129 # pad the output ISO to multiples of 256 KiB for partition table support {{{
130 siz=$($getfilesize "$ISOFILE")
131 cyls=$(echo "$siz / 512 / 32 / 16 + 1" | bc) # C=$cyls H=16 S=32
132 ofs=$(echo "$cyls * 16 * 32 * 512 - 1" | bc) # padding offset (size - 1)
133 dd if=/dev/zero bs=1 count=1 seek=$ofs of="$ISOFILE" 2>/dev/null
140 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
141 [[ $WRKDIR_EXISTED = 'false' ]] && rmdir "$WRKDIR"
142 echo "Generated $ISOFILE"
145 ## EOF #########################################################################
146 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3