Page 1 of 1

[SOLVED] Chainloading EXT2 VBR from GRUB2: Invalid signature

Posted: Fri May 23, 2014 8:19 am
by Marionumber1
My OS kernel is loaded by a three-stage bootloader. The first stage, called stage1, is located in the MBR and is solely responsible for loading the VBR off the active partition. The VBR, or stage2, is filesystem-specific and contains just enough filesystem code to load the next stage, stage3. stage3 is much more complex, almost like a mini-kernel. It uses protected mode and paging, has a basic heap and physical memory allocator, and can load higher-half ELF binaries. Anyway, stage2 is designed so that it can either be loaded by an MBR (either stage1 or something else) or chainloaded from something like GRUB2. This is valuable in a dual-boot environment, since I don't need to overwrite the MBR to boot the kernel.

Currently, the only supported stage2 is for EXT2 filesystems. So when testing on real hardware, I write stage2 to the first 2 sectors of the partition (reserved area for VBRs) and then put stage3 on the filesystem. I added an entry to my GRUB2 configuration file to chainload this partition, but when I attempt to do so, I get an "Invalid signature. Press any key to continue..." error from GRUB2. My configuration entry for my OS is posted below. I'm completely lost with this error, and would be grateful for any help. All of my bootloader stages work in Bochs, but I'd like them to run on real hardware too.

Code: Select all

menuentry "DarkSide OS" {
        insmod ext2
        insmod chain
        set root='(hd0,msdos3)'
        chainloader +1
}

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Posted: Fri May 23, 2014 11:42 am
by jnc100
The GRUB chainloader command will only load a single sector, and expects it to be terminated by the 0xaa55 signature. If it doesn't find this, it will give the 'invalid signature' error.

Regards,
John.

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Posted: Fri May 23, 2014 1:17 pm
by Marionumber1
jnc100 wrote:The GRUB chainloader command will only load a single sector, and expects it to be terminated by the 0xaa55 signature. If it doesn't find this, it will give the 'invalid signature' error.

Regards,
John.
Thanks for telling me that, I had no idea GRUB only loaded one sector for chainloading. Regardless, this can easily be fixed by modifying my chainloader directive to load two sectors instead of one. One more question, though: does GRUB follow the MBR to VBR interface where the BIOS disk number is in DL and the MBR entry is pointed to by DS:SI?

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Posted: Sat May 24, 2014 8:10 am
by jnc100
Marionumber1 wrote:One more question, though: does GRUB follow the MBR to VBR interface where the BIOS disk number is in DL and the MBR entry is pointed to by DS:SI?
According to the source, yes, although this should be relatively easy to test yourself.

Regards,
John.

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Posted: Sat May 24, 2014 9:00 am
by Marionumber1
Well, now I'm having problems where the VBR just seems to hang, with the VGA cursor blinking. Even if I try to print a message using the BIOS at the beginning of my VBR, it doesn't do anything different. Holding down keys on the keyboard eventually causes the buffer to fill up and the PC speaker starts beeping. Also, if I try to reset the video mode back to text mode (mode 0x03) in my VBR, the screen will go completely black (almost as if a graphics mode has been set) and the same problem occurs.