Page 1 of 1

Extended bootloader...

Posted: Tue Sep 16, 2008 5:44 pm
by Troy Martin
Is it possible to put my second stage bootloader (which only needs two sectors or so) in the two sectors directly after the bootsector? Will anything affect this? Will this affect anything?

Re: Extended bootloader...

Posted: Tue Sep 16, 2008 6:13 pm
by IanSeyler
Hi Troy,

It depends on the file system. I know that FAT16 and FAT32 keeps some "reserved sectors" after the boot sector. I did this for a while when I was writing my OS but in the end went back to the second stage loader being its own file. It made it easier to make changes when it was just a file.

The FreeDOS project has some open source boot sectors that can load a file from FAT12, 16, and 32. I am using the FAT32 version that I modified a bit.

-Ian

Re: Extended bootloader...

Posted: Wed Sep 17, 2008 1:49 am
by M-Saunders
For FAT12, the FAT begins straight after the boot sector, so you don't want to start writing anything else in the second and third sectors. See http://www.it.lth.se/ssoa/Project1/FAT12Description.pdf

M

Re: Extended bootloader...

Posted: Wed Sep 17, 2008 2:08 am
by AJ
M-Saunders wrote:For FAT12, the FAT begins straight after the boot sector.
There is (as iseyler points out) a reserved sectors field in the BPB. This allows you to store a second stage loader there. The problem with that is that if you want to install a boot loader on an already formatted FAT partition (DOS' equivalent of the "sys" command), this is impossible unless you have already left those free sectors.

By far the more versatile way is to store any supplementary stages is to store them as files, if you are sticking with the FAT format.

Cheers,
Adam

Re: Extended bootloader...

Posted: Wed Sep 17, 2008 3:43 am
by egos
Troy Martin wrote:Is it possible to put my second stage bootloader (which only needs two sectors or so) in the two sectors directly after the bootsector?
It is not second stage bootloader. It is the first stage bootloader, which loads part of the self body at run-time.

Re: Extended bootloader...

Posted: Wed Sep 17, 2008 9:56 am
by quok
Troy Martin wrote:Is it possible to put my second stage bootloader (which only needs two sectors or so) in the two sectors directly after the bootsector? Will anything affect this? Will this affect anything?
For MBR code on a HD, there's a 63 sector gap between the boot sector and the start of the first partition. You CAN hide extra code there. That is exactly what GRUB does when it needs to use a stage_1.5. The stage_1.5 then loads the stage2 using filesystem routines.

Be careful though as this area may be used by other things as well. If you're replacing the MBR on the HD then you should be fine, but if you're only replacing the bootsector of a partition, I'd definitely shy away from using this technique.

Also, in case anyone decides to try this trick with a GPT partitioning scheme, you can't... there's no 63 sector gap between the "MBR" and the start of the first partition. A lot of that space that is otherwise reserved in a DOS/MBR partitioning scheme contains parts of the GPT when using a GPT partitioning scheme (such as on EFI systems).