2 ################################################################################
4 # Purpose: create a multiboot ISO using grml2usb
5 # Author: Michael Prokop <mika@grml.org>,
6 # Thorsten Glaser <tg@mirbsd.org>
7 ################################################################################
9 # * generalise the script so we can provide it as part of the grml2usb suite
10 # * improve error handling
11 # * support isolinux as bootloader on the ISO
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 echo >&2 "Usage: $0 target.iso source1.iso [source2.iso ...]"
29 # ********* PLEASE ADJUST! *******************************************
30 # specify path to the grml2usb script you'd like to use
32 # work directory for creating the filesystem
33 WRKDIR='/dev/shm/grml2iso.tmp'
34 # ********* PLEASE ADJUST! *******************************************
36 test $# -lt 2 && usage
38 echo >&2 Error: target file "'$1'" already exists.
45 # note: grub-pc_1.96+20090603-1_i386.deb seems to be b0rken
46 GRUB_DEB="grub-pc_1.96+20080724-16_i386.deb"
48 # normalise path (in mksh I’d just use the realpath builtin…)
51 *) ISOFILE=$ORIG_DIR/$ISOFILE ;;
54 # create necessary stuff under WRKDIR
55 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
56 mkdir -p "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
58 # execute grml2usb with all ISOs you'd like to install
59 $GRML2USB "$@" "$WRKDIR/cddir"
62 # as we don't want to rely on a grub2 installation on the
63 # running system let's grab it from the net
64 cd "$WRKDIR"/grub_tmp/
65 wget http://ftp.de.debian.org/debian/pool/main/g/grub2/"$GRUB_DEB"
68 ./usr/bin/grub-mkimage -d usr/lib/grub/i386-pc \
69 -o "$WRKDIR"/cddir/boot/grub/core.img biosdisk iso9660
71 for a in usr/lib/grub/i386-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do
72 test -e $a && cp $a "$WRKDIR"/cddir/boot/grub/
75 cat usr/lib/grub/i386-pc/cdboot.img "$WRKDIR"/cddir/boot/grub/core.img \
76 > "$WRKDIR"/cddir/boot/grub/eltorito.img
79 # finally generate the CD/DVD-iso
80 mkisofs -V 'grml-multiboot' -l -r -J -no-pad \
81 -no-emul-boot -boot-load-size 4 -boot-info-table \
82 -b boot/grub/eltorito.img -c boot/grub/eltorito.cat \
85 # pad the output ISO to multiples of 256 KiB for partition table support
86 siz=$($getfilesize "$ISOFILE")
87 cyls=$(echo "$siz / 512 / 32 / 16 + 1" | bc) # C=$cyls H=16 S=32
88 ofs=$(echo "$cyls * 16 * 32 * 512 - 1" | bc) # padding offset (size - 1)
89 dd if=/dev/zero bs=1 count=1 seek=$ofs of="$ISOFILE" 2>/dev/null
91 # create a manifold-boot image with a partition table, if possible
92 if mksh -c true 2>/dev/null && \
93 test -e /usr/share/grml-live/scripts/bootgrub.mksh; then
94 echo "Creating a manifold-boot ISO image"
96 mksh /usr/share/grml-live/scripts/bootgrub.mksh -A -M 1 -p 0x83 -g $cyls:16:32 | \
97 cat - boot/grub/core.img | \
98 dd conv=notrunc of="$ISOFILE" conv=notrunc 2>/dev/null
100 echo "Cannot find mksh or bootgrub.mksh, not generating manifold-boot ISO image"
106 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
109 echo "Generated $ISOFILE"
111 ## EOF #########################################################################