wok-stable diff syslinux/stuff/tools/isohybrid.sh @ rev 4513

syslinux: add isohybrid (shell version)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Nov 26 16:44:48 2009 +0100 (2009-11-26)
parents
children fdf437968364
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/syslinux/stuff/tools/isohybrid.sh	Thu Nov 26 16:44:48 2009 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +build="--build"
     1.7 +if [ "$1" == "$build" ]; then
     1.8 +	cat  >> $0 <<EOM
     1.9 +$(uuencode -m mbr/isohdpfx.bin -)
    1.10 +EOT
    1.11 +EOM
    1.12 +	sed -i "/$build/{NNNNNNNNNd}" $0
    1.13 +	exit
    1.14 +fi
    1.15 +
    1.16 +if [ -z "$1" ]; then
    1.17 +	cat << EOT
    1.18 +usage: $0 isoimage
    1.19 +EOT
    1.20 +	exit 1
    1.21 +fi
    1.22 +iso=$1
    1.23 +heads=64	# zipdrive-style geometry
    1.24 +sectors=32
    1.25 +partype=23	# "Windows hidden IFS"
    1.26 +
    1.27 +readiso()
    1.28 +{
    1.29 +	dd if=$iso bs=2k skip=$1 count=1 2> /dev/null | \
    1.30 +	dd bs=1 skip=$2 count=$3 2> /dev/null
    1.31 +}
    1.32 +
    1.33 +# read a 32 bits data
    1.34 +readlong()
    1.35 +{
    1.36 +	readiso $1 $2 4  | hexdump -e '"" 1/4 "%d" "\n"'
    1.37 +}
    1.38 +
    1.39 +# write a 32 bits data
    1.40 +storelong()
    1.41 +{
    1.42 +	printf "00000  %02X %02X %02X %02X \n" \
    1.43 +		$(( $2 & 255 )) $(( ($2>>8) & 255 )) \
    1.44 +		$(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
    1.45 +	hexdump -R | dd bs=1 conv=notrunc of=$iso seek=$(( $1 )) 2> /dev/null
    1.46 +}
    1.47 +
    1.48 +setmbr()
    1.49 +{
    1.50 +	uudecode | dd of=$iso conv=notrunc 2> /dev/null
    1.51 +	storelong 432 $(( $lba * 4 ))
    1.52 +	storelong 440 $(( ($RANDOM << 16) + $RANDOM ))
    1.53 +	storelong 446 $(( 0x80 + ( 1 << 16) ))
    1.54 +	esect=$(( $sectors + ((($cylinders -1) & 0x300) >> 2) ))
    1.55 +	ecyl=$(( ($cylinders - 1) & 0xff ))
    1.56 +	storelong 450 $(( $partype + (($heads - 1) << 8) + ($esect << 16) + ($ecyl <<24) ))
    1.57 +	storelong 458 $(( $cylinders * $heads * $sectors ))
    1.58 +	storelong 510 $(( 0xAA55 ))
    1.59 +}
    1.60 +
    1.61 +if [ "$(readiso 17 7 23)" != "EL TORITO SPECIFICATION" ]; then
    1.62 +	echo "$iso: no boot record found.";
    1.63 +	exit 1
    1.64 +fi
    1.65 +catalog=$(readlong 17 71)
    1.66 +if [ "$(readiso $catalog 0 32 | md5sum | awk '{ print $1 }')" != \
    1.67 +     "788e7bfdad52cc6aae525725f24a7f89" ]; then
    1.68 +	echo "$iso: invalid boot catalog.";
    1.69 +	exit 1
    1.70 +fi
    1.71 +lba=$(readlong $catalog 40)
    1.72 +if [ $(readlong $lba 64) -ne 1886961915 ]; then
    1.73 +	echo "$iso: bootloader does not have a isolinux.bin hybrid signature.";
    1.74 +	exit 1
    1.75 +fi
    1.76 +size=$(stat -c "%s" $iso)
    1.77 +pad=$(( $size % (512 * $heads * $sectors) ))
    1.78 +[ $pad -eq 0 ] || pad=$((  (512 * $heads * $sectors) - $pad ))
    1.79 +[ $pad -eq 0 ] || dd if=/dev/zero bs=512 count=$(( $pad / 512 )) >> $iso 2> /dev/null
    1.80 +cylinders=$(( ($size + $pad) / (512 * $heads * $sectors) ))
    1.81 +if [ $cylinders -gt 1024 ]; then
    1.82 +	cat 1>&2 <<EOT
    1.83 +Warning: more than 1024 cylinders ($cylinders).
    1.84 +Not all BIOSes will be able to boot this device.
    1.85 +EOT
    1.86 +	cylinders=1024
    1.87 +fi
    1.88 +
    1.89 +setmbr <<EOT