Sure, we know that *someone* of the original Authors of the tool coded that, but - with all due respect to all involved - at least the way you explained it, it simply makes no sense whatsoever (to me at least).
Since usually the good guys that wrote those tools write very "sound" code, at least from a "phylosphical" point of view, I suspect that (while there is the possibility of a mistake by everone) that *somehow* the intention was not that of changing the MBR type depending on the filesystem(s) found but *something else*.
In any case, personally I see little advantages in that, if I were you I would rather write a grub4dos grldr.mbr installer (if you feel like one is needed) rather than fiddling with the old grubinst code.
Maybe useful, in any case, set aside for the moment the "fork" by Steve6375, which I am not familiar with, but that I presume won' t behave in any way differently if not for the slightly reduced space for an entirely optional and actually very rarely used "reserved" space for a BPB or similar, this is what I know that is needed to install grldr.mbr:
the whole grldr.mbr file is 9216 bytes, i.e. exactly 18 sectors
the file contains a "hole" on second sector, to hold "optionally" a copy of previous MBR
the first sector of it, the "proper" MBR, has three "holes".
- a first one 0x58 bytes from offset 0x08 (0x10 in Steve's version) useful to hold (when needed - very, very rare case - a bootinfotable or a BPB block)
- a second one for the disk signature from 0x1B8 (0x04 bytes in length)
- a third one for the partition table from 0x1BE, 4 entries by 16 bytes
You can completely ignore the "first hole" in the "proper" MBR and just fill the #2 and #3 with *any* previous content, as stated in the read me:
Quote
******************************************************************************
*** grldr.mbr - How to write it to Master Boot Track of the hard disk ***
******************************************************************************
grldr.mbr contains code that can be used as Master Boot Record. The code is
responsible for searching all partitions for grldr and when found, loading it.
Currently supported partition types are: FAT12/FAT16/FAT32, NTFS, EXT2/EXT3.
Logical partitions in the extended partition are supported, provided that the
extended partition type is Microsoft-compatible. In fact, the Linux extended
partition type(0x85) is not fully tested for the search mechanism.
How to write GRLDR.MBR to the Master Boot Track of a hard disk?
First, read the Windows disk signature and partition information bytes
(72 bytes in total, from offset 0x01b8 to 0x01ff of the MBR sector), and put
them on the same range from offset 0x01b8 to 0x01ff of the beginning sector of
GRLDR.MBR.
Optionally, if the MBR in the hard disk is a single sector MBR created by
Microsoft FDISK, it may be copied onto the second sector of GRLDR.MBR.
The second sector of GRLDR.MBR is called "previous MBR". When GRLDR not found,
"previous MBR" will be started.
No other steps needed, after all necessary changes stated above have been made,
now simply write GRLDR.MBR on to the Master Boot Track. That's all.
Since you want to have anyway the "previous MBR" on second sector, a reasonable procedure is the following:
- dump current MBR (whatever it is) to the second sector of a copy of grldr.mbr
- copy 4 bytes from offset 0x1B8 of second sector to same offset on first sector
- copy 64 bytes from offset 0x1BE of second sector to same offset on first sector
- (since the two bytes at offset 0x1BC are never used and are normally 0000 and the last two bytes of the MBR MUST be the "Magic Bytes" 55AA, you can as well use the simplified single 72 bytes copy as in the read me)
- write the thus modified copy of grldr.mbr to first 16 sectors of the disk
While you have the "copy of grldr.mbr" (i.e. before writing it to the MBR + hidden sectors) you may want to set the bunch of early "configuration bytes" to your likings (or according to the choices in the GUI) and these settings are also documented in the read me:
******************************************************************************
*** grldr.mbr - Details about the control bytes ***
******************************************************************************
Six bytes can be used to control the boot process of GRLDR.MBR.
Offset Length Description
====== ====== ==============================================================
02h 1 bit0=1: disable the search for GRLDR on floppy
bit0=0: enable the search for GRLDR on floppy
bit1=1: disable the boot of PREVIOUS MBR with invalid
partition table(usually an OS boot sector)
bit1=0: enable the boot of PREVIOUS MBR with invalid
partition table(usually an OS boot sector)
bit2=1: disable the feature of unconditional entrance to
the command-line(See below `--duce')
bit2=0: enable the feature of unconditional entrance to
the command-line(See below `--duce')
bit3=1: disable geometry tune(See below `--chs-no-tune')
bit3=0: enable geometry tune(See below `--chs-no-tune')
bit4 - bit6: reserved
bit7=1: try to boot PREVIOUS MBR after the search for GRLDR
bit7=0: try to boot PREVIOUS MBR before the search for GRLDR
03h 1 timeout in seconds to wait for a key press. 0xff stands for
waiting all the time(endless).
04h 2 hot-key code. high byte is scan code, low byte is ASCII code.
the default value is 0x3920, which stands for the space bar.
if this key is pressed, GRUB will be started prior to the boot
of previous MBR. See "int 16 keyboard scan codes" below.
06h 1 preferred boot drive number, 0xff for no-drive
07h 1 preferred partition number, 0xff for whole drive
As I see it,
anything else is NOT needed.
Let us remember that the scope is ONLY to install the grub4dos MBR code and nothing else (grubinst is not a "partitioning tool" or a "recovery tool" or an "increase boot chances" tool))
This could be done (excluded the configuration) in batch with just a bunch of commands *like* (using for the example dd for windows):
Quote
dd if=grldr.mbr of=mynew.mbr bs=512 count=16
dd if=\\.\Physicaldriven of=myold.mbr bs=512 count=1
dd if=myold.mbr of=mynew.mbr bs=1 count=512 seek=512
dd if=myold.mbr of=mynew.mbr bs=1 count=72 skip=440 seek=440
dd if=mynew.mbr of=\\.\Physicaldriven bs=512 count=16
Maybe you want - as an option - to provide an alternative "standard" MBR code, and if this is the case, I would suggest you to use the Syslinux one, which is surely freely redistributable.
Wonko