[syslinux] [PATCH] chain.c32: add support for loading GRUB stage2

Gert Hulselmans gerth at zytor.com
Tue Jun 8 13:08:26 PDT 2010


Thomas Bächler wrote:
>> GRUB's loading mechanism allows to somehow provide stage2 with the
>> selected disk and partition, BSD slice, etc. (ie, to tell stage2 what
>> it's "root" is). I don't yet understand the notation used in that
>> mechanism. Besides, since stage2 images will not necessarily be loaded
>> from the disk (and partition, etc.) they were installed to, it seems
>> best to just use the first disk.
>
> I believe that is not the purpose of stage2's "root". When stage2 is
> loaded, it looks for a file /grub/menu.lst or /boot/grub/menu.lst to
> read a configuration from. My guess is that the "root" in this case is
> the device where it looks for that file.
>
> Without menu.lst, grub will just show a prompt. If I am right, it would
> be very useful to be able to APPEND a "root" so that a chainloaded grub
> can load a configuration file without user intervention.
>

Grub4dos (based on Grub Legacy) can chainload stage2 of Grub Legacy too:
    chainloader --force --load-segment=0 --load-offset=0x8000 --boot-cs=0
--boot-ip=0x8200 (...)/.../stage2

Paul Bolle's patch does the same. So that is good news.

When I wanted to chainload grldr (Grub4dos) with chain.c32 I (Grub4Dos ==>
based on Grub Legacy
>From my experience with grub4dos and the install_partition variable:
First post of Tinybit:
http://www.boot-land.net/forums/index.php?showtopic=8457

Post #4 (Tinybit)
========
The lower word of install_partition should be 0xFFFF, so you need not
touch it. The highest byte(8-bit) of install_partition should be 0. The
less significant byte is the actual partition number and should be
adjusted, i.e., for 0x00PPFFFF, the PP should be adjusted. Some
devices(floppy, cdrom) use the "whole drive"(read "unpartitioned"), so the
PP should be FF.
========

You shouldn't set the install_partition variable yourself. It won't work,
or at least not for grub4dos (grldr).

Post #22
========
Before jumping to the entry point at the very beginning of GRLDR, you
should setup DL=(BIOS drive) and DH=(partition number). For partition
numbers, 0 - 3 are primary, 4 - 0xFE are logical. (DH=0xFF) stands for
whole drive(unpartitioned). DH will later be passed to
install_partition(the third byte, from bit 16 to bit 23).
========

Setting DL (BIOS drive) and DH (partition number) let grub4dos search for
its menu.lst file on that partition first.

Setting DL (used by almost all bootsectors to know the boot drive) is
already implemented in chain.c32

Setting DH is also added in recent versions of chain.c32:
/*
* grldr of Grub4dos wants the partition number in DH:
* -1:   whole drive (default)
* 0-3:  primary partitions
* 4-*:  logical partitions
*/
regs.edx.b[1] = whichpart-1;


So you can try if Grub Legacy uses DH to sets its root partition or not:

  # Set root partition to third primary partition
  chain.c32 hd0 3 grub=/boot/grub/stage2

I hope this info is useful.

- Gert Hulselmans




More information about the Syslinux mailing list