wok view syslinux/stuff/tools/isohybrid.sh @ rev 6606
Added perl and m4 to autoconf depends.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sat Oct 09 17:56:22 2010 +0000 (2010-10-09) |
parents | 81f59d88ba12 |
children | b25fc6e108b2 |
line source
1 #!/bin/sh
3 build="--build"
4 if [ "$1" == "$build" ]; then
5 cat >> $0 <<EOM
6 $(uuencode -m mbr/isohdpfx.bin -)
7 EOT
8 EOM
9 busybox sed -i "/$build/{NNNNNNNNNd}" $0
10 exit
11 fi
13 if [ -z "$1" ]; then
14 cat << EOT
15 usage: $0 isoimage
16 EOT
17 exit 1
18 fi
19 iso=$1
20 heads=64 # zipdrive-style geometry
21 sectors=32
22 partype=23 # "Windows hidden IFS"
24 readiso()
25 {
26 dd if=$iso bs=2k skip=$1 count=1 2> /dev/null | \
27 dd bs=1 skip=$2 count=$3 2> /dev/null
28 }
30 # read a 32 bits data
31 readlong()
32 {
33 readiso $1 $2 4 | hexdump -e '"" 1/4 "%d" "\n"'
34 }
36 # write a 32 bits data
37 storelong()
38 {
39 printf "00000 %02X %02X %02X %02X \n" \
40 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \
41 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
42 hexdump -R | dd bs=1 conv=notrunc of=$iso seek=$(( $1 )) 2> /dev/null
43 }
45 setmbr()
46 {
47 uudecode | dd of=$iso conv=notrunc 2> /dev/null
48 storelong 432 $(( $lba * 4 ))
49 storelong 440 $(( ($RANDOM << 16) + $RANDOM ))
50 storelong 446 $(( 0x80 + ( 1 << 16) ))
51 esect=$(( $sectors + ((($cylinders -1) & 0x300) >> 2) ))
52 ecyl=$(( ($cylinders - 1) & 0xff ))
53 storelong 450 $(( $partype + (($heads - 1) << 8) + ($esect << 16) + ($ecyl <<24) ))
54 storelong 458 $(( $cylinders * $heads * $sectors ))
55 storelong 510 $(( 0xAA55 ))
56 }
58 if [ "$(readiso 17 7 23)" != "EL TORITO SPECIFICATION" ]; then
59 echo "$iso: no boot record found.";
60 exit 1
61 fi
62 catalog=$(readlong 17 71)
63 if [ "$(readiso $catalog 0 32 | md5sum | awk '{ print $1 }')" != \
64 "788e7bfdad52cc6aae525725f24a7f89" ]; then
65 echo "$iso: invalid boot catalog.";
66 exit 1
67 fi
68 lba=$(readlong $catalog 40)
69 if [ $(readlong $lba 64) -ne 1886961915 ]; then
70 echo "$iso: bootloader does not have a isolinux.bin hybrid signature.";
71 exit 1
72 fi
73 size=$(stat -c "%s" $iso)
74 pad=$(( $size % (512 * $heads * $sectors) ))
75 [ $pad -eq 0 ] || pad=$(( (512 * $heads * $sectors) - $pad ))
76 [ $pad -eq 0 ] || dd if=/dev/zero bs=512 count=$(( $pad / 512 )) >> $iso 2> /dev/null
77 cylinders=$(( ($size + $pad) / (512 * $heads * $sectors) ))
78 if [ $cylinders -gt 1024 ]; then
79 cat 1>&2 <<EOT
80 Warning: more than 1024 cylinders ($cylinders).
81 Not all BIOSes will be able to boot this device.
82 EOT
83 cylinders=1024
84 fi
86 setmbr <<EOT