[SOLVED] Chainloading EXT2 VBR from GRUB2: Invalid signature

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

[SOLVED] Chainloading EXT2 VBR from GRUB2: Invalid signature

Post 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
}
Last edited by Marionumber1 on Mon May 26, 2014 11:27 am, edited 1 time in total.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Post 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.
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Post 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?
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Post 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.
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: Chainloading EXT2 VBR from GRUB2: Invalid signature

Post 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.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
Post Reply