diff options
author | Andreas Loibl <andreas@andreas-loibl.de> | 2011-11-18 19:26:10 +0100 |
---|---|---|
committer | Andreas Loibl <andreas@andreas-loibl.de> | 2011-11-18 19:26:10 +0100 |
commit | ba23aa9a487c598211a27d51a613894af435fb03 (patch) | |
tree | 58dec294973ec919829c5cdd42b4a01836c0c678 | |
parent | f3ad1b9576e9a26cee97b6c38beb726dacd4b857 (diff) | |
download | kanotix-ba23aa9a487c598211a27d51a613894af435fb03.zip kanotix-ba23aa9a487c598211a27d51a613894af435fb03.tar.gz |
added FAT-Partition to Apple-Partition-Map
-rwxr-xr-x | config/binary_local-hooks/mkefipart-fat (renamed from mkefipart-fat) | 6 | ||||
-rwxr-xr-x | isohybrid-acritox | 84 | ||||
-rwxr-xr-x | isohybrid-embeddedfat | 57 |
3 files changed, 50 insertions, 97 deletions
diff --git a/mkefipart-fat b/config/binary_local-hooks/mkefipart-fat index 25e2828..5273076 100755 --- a/mkefipart-fat +++ b/config/binary_local-hooks/mkefipart-fat @@ -8,12 +8,12 @@ if [ ! -x /usr/bin/mmd ]; then exit 1 fi -img=efi-fat.img +img=binary/boot.efi.img [ "$1" ] && img="$1" rm -f "$img" -# Stuff boot*.efi into a FAT filesystem, making it as small as possible. 24KiB -# headroom seems to be enough; (x+31)/32*32 rounds up to multiple of 32. +# Stuff boot*.efi into a FAT filesystem, +# (x+1023)/1024*1024 rounds up to multiple of MB. mkfs.msdos -n KANOTIX_EFI -C "$img" \ $(( ($(stat -c %s binary/efi/boot/boot*.efi | awk '{s+=$1} END {print s}') / 1024 + 1023) \ / 1024 * 1024 )) diff --git a/isohybrid-acritox b/isohybrid-acritox index c12edec..6bd7416 100755 --- a/isohybrid-acritox +++ b/isohybrid-acritox @@ -3,28 +3,27 @@ # # Post-process a hybrid-ISO-image generated with isohybrid-bg2 # by injecting an "Apple Partition Map" into the image and appending a HFS+-partiton -# and a FAT-partition to allow "hybrid booting" as CD-ROM (EFI or El Torito) or as -# a hard-drive on Intel-Macs (EFI) and PCs (EFI or MBR). +# and using a FAT-partition embedded as file into the ISO9660 to allow "hybrid booting" +# as CD-ROM (EFI or El Torito) or as a hard-drive on Intel-Macs (EFI) and PCs (EFI or MBR). $bs=0x0200; $block0='45520200eb5f90'; # 512 - add (%eax),%al $bs=0x0400; $block0='45520400eb5f90'; # 1024 - add $0x0,%al +$bs=0x0800; $block0='45520800eb5f90'; # 2048 - or %al,(%bx,%si) # Apple Partition Map entries: -$pm1='504d000000000002000000010000000f4170706c650000000000000000000000000000000000000000000000000000004170706c655f706172746974696f6e5f6d617000000000000000000000000000000000000000000f00000003'; -$pm2='504d00000000000200000400000005006469736b20696d616765000000000000000000000000000000000000000000004170706c655f4846530000000000000000000000000000000000000000000000000000000000040040000033'; +$pm1='504d000000000003000000010000000f4170706c650000000000000000000000000000000000000000000000000000004170706c655f706172746974696f6e5f6d617000000000000000000000000000000000000000000f00000003'; # Apple_partition_map +$pm2='504d00000000000300000400000005006469736b20696d616765000000000000000000000000000000000000000000004170706c655f4846530000000000000000000000000000000000000000000000000000000000040040000033'; # Apple_HFS +$pm3='504d00000000000300000001000004004b414e4f5449585f454649000000000000000000000000000000000000000000444f535f4641545f313200000000000000000000000000000000000000000000000000000000040040000033'; # DOS_FAT_12 -die "Usage: $0 <isohybrid-bg2.iso> <HFS+-image> <FAT-image>\n" if $#ARGV != 2; +die "Usage: $0 <isohybrid-bg2.iso> <HFS+-image> <FAT-image-filename>\n" if $#ARGV != 2; -($file, $part, $fat) = @ARGV; +($file, $part, $filename) = @ARGV; open(FILE, "+< $file\0") or die "$0: cannot open $file: $!\n"; binmode FILE; open(PART, "< $part\0") or die "$0: cannot open $part: $!\n"; binmode PART; -open(FAT, "< $fat\0") or die "$0: cannot open $fat: $!\n"; -binmode FAT; - # Check if image has already been "patched" (i.e. it has the APM signature from $block0) seek(FILE, 0, SEEK_SET) or die "$0: $file: $!\n"; read(FILE, $test, 2) == 2 or die "$0: $file: read error\n"; @@ -40,6 +39,11 @@ seek(PART, 0x400, SEEK_SET) or die "$0: $file: $!\n"; read(PART, $test, 2) == 2 or die "$0: $file: read error\n"; die "$part doesn't seem to contain a HFS+ filesystem\n" if($test ne 'H+'); +$start = `isoinfo -J -s -l -i "$file" | awk '/$filename/{print \$10}'`; +if (!$start) { + die "$0: $filename: cannot determine position of file\n"; +} + # Get the total size of the image (@imgstat = stat(FILE)) or die "$0: $file: $!\n"; $imgsize = $imgstat[7]; @@ -59,19 +63,14 @@ if (!$partsize) { die "$0: $part: cannot determine length of file\n"; } -# Get the total size of the partiton -(@fatstat = stat(FAT)) or die "$0: $part: $!\n"; -$fatsize = $fatstat[7]; -if (!$fatsize) { - die "$0: $part: cannot determine length of file\n"; -} - seek(FILE, 0, SEEK_SET) or die "$0: $file: $!\n"; print FILE pack('H*',$block0); seek(FILE, $bs*1, SEEK_SET) or die "$0: $file: $!\n"; print FILE pack('H*',$pm1); seek(FILE, $bs*2, SEEK_SET) or die "$0: $file: $!\n"; print FILE pack('H*',$pm2); +seek(FILE, $bs*3, SEEK_SET) or die "$0: $file: $!\n"; +print FILE pack('H*',$pm3); # Pad the image to a fake cylinder boundary seek(FILE, $imgstat[7], SEEK_SET) or die "$0: $file: $!\n"; @@ -92,6 +91,10 @@ if ($padding) { } $partsize += $padding; +use integer; +$lba = $start*4; +$psize = $imgsize/512 - $lba; + # Adjust $pm2 (Apple_HFS) # "physical block start" and "physical block count" of partition: seek(FILE, $bs*2+8, SEEK_SET) or die "$0: $file: $!\n"; @@ -100,6 +103,14 @@ print FILE pack('NN', $imgsize/$bs, $partsize/$bs); seek(FILE, $bs*2+80, SEEK_SET) or die "$0: $file: $!\n"; print FILE pack('NN', 0, $partsize/$bs); +# Adjust $pm3 (DOS_FAT_12) +# "physical block start" and "physical block count" of partition: +seek(FILE, $bs*3+8, SEEK_SET) or die "$0: $file: $!\n"; +print FILE pack('NN', $lba*512/$bs, $psize*512/$bs); +# "logical block start" and "logical block count" of partition: +seek(FILE, $bs*3+80, SEEK_SET) or die "$0: $file: $!\n"; +print FILE pack('NN', 0, $psize*512/$bs); + $imgsize += $partsize; seek(FILE, $imgsize, SEEK_SET) or die "$0: $file: $!\n"; @@ -112,36 +123,35 @@ if ($padding) { print FILE "\0" x $padding; } -# TODO: merge isohybrid-embeddedfat into here -exit 0; - -# Append FAT partition to image -read FAT, $partition, $fatsize; -print FILE $partition; +# Done... +close(PART); -# Pad the partition to a fake cylinder boundary -$frac = $fatsize % $cylsize; -$padding = ($frac > 0) ? $cylsize - $frac : 0; -if ($padding) { - print FILE "\0" x $padding; +# Calculate partiton table (MBR) +$psize = $imgsize/512 - $lba; +$h = 64; $s = 32; +$hpc = 32; $spt = 63; +$bcyl = $lba / ($spt * $hpc); +$bhead = ($lba / $spt) % $hpc; +$bsect = ($lba % $spt) + 1; +$cylsize = $h*$s*512; +$c = $imgsize/$cylsize; +if ($c > 1024) { + $cc = 1024; +} else { + $cc = $c; } -$fatsize += $padding; +$ehead = $h-1; +$esect = $s + ((($cc-1) & 0x300) >> 2); +$ecyl = ($cc-1) & 0xff; # Adjust MBR partition table $fstype = 0xEF; -$pentry = 2; +$pentry = 1; seek(FILE, 430+16*$pentry, SEEK_SET) or die "$0: $file: $!\n"; -print FILE pack("CCCCCCCCVV", 0x80, 0xfe, 0xff, 0xff, $fstype, 0xfe, 0xff, 0xff, $imgsize/512, $fatsize/512); - -# Delete ISO9660 partition entry from MBR-partition-table -seek(FILE, 430+16*1, SEEK_SET) or die "$0: $file: $!\n"; -print FILE "\0" x 16; - -$imgsize += $fatsize; +print FILE pack("CCCCCCCCVV", 0x80, $bhead, $bsect, $bcyl, $fstype, $ehead, $esect, $ecyl, $lba, $psize); # Done... -close(PART); close(FILE); exit 0; diff --git a/isohybrid-embeddedfat b/isohybrid-embeddedfat deleted file mode 100755 index b35b3bc..0000000 --- a/isohybrid-embeddedfat +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/perl -# isohybrid-embeddedfat - written by Andreas Loibl <andreas@andreas-loibl.de> -# - -die "Usage: $0 <isohybrid-bg2.iso> <filename>\n" if $#ARGV != 1; - -($file,$filename) = @ARGV; -open(FILE, "+< $file\0") or die "$0: cannot open $file: $!\n"; -binmode FILE; - -# Get the total size of the image -(@imgstat = stat(FILE)) or die "$0: $file: $!\n"; -$imgsize = $imgstat[7]; -if (!$imgsize) { - die "$0: $file: cannot determine length of file\n"; -} - -$start = `isoinfo -J -s -l -i kanotix64.iso | awk '/$filename/{print \$10}'`; -if (!$start) { - die "$0: $filename: cannot determine position of file\n"; -} - -use integer; -$lba = $start*4; -$psize = $imgsize/512 - $lba; -$h = 64; $s = 32; -$hpc = 32; $spt = 63; -$bcyl = $lba / ($spt * $hpc); -$bhead = ($lba / $spt) % $hpc; -$bsect = ($lba % $spt) + 1; -$cylsize = $h*$s*512; -$c = $imgsize/$cylsize; -if ($c > 1024) { - $cc = 1024; -} else { - $cc = $c; -} -$ehead = $h-1; -$esect = $s + ((($cc-1) & 0x300) >> 2); -$ecyl = ($cc-1) & 0xff; - -# Adjust MBR partition table -$fstype = 0xEF; -$pentry = 1; - -seek(FILE, 430+16*$pentry, SEEK_SET) or die "$0: $file: $!\n"; -print FILE pack("CCCCCCCCVV", 0x80, $bhead, $bsect, $bcyl, $fstype, $ehead, $esect, $ecyl, $lba, $psize); - -# Delete other partition entry from MBR-partition-table -seek(FILE, 430+16*2, SEEK_SET) or die "$0: $file: $!\n"; -print FILE "\0" x 16; - -# Done... -close(PART); -close(FILE); - -exit 0; |