Extended bootloader...
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Extended bootloader...
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...
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
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
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
-
- Member
- Posts: 155
- Joined: Fri Oct 27, 2006 5:11 am
- Location: Oberbayern
- Contact:
Re: Extended bootloader...
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
M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
http://mikeos.sourceforge.net
Re: Extended bootloader...
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.M-Saunders wrote:For FAT12, the FAT begins straight after the boot sector.
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...
It is not second stage bootloader. It is the first stage bootloader, which loads part of the self body at run-time.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?
If you have seen bad English in my words, tell me what's wrong, please.
Re: Extended bootloader...
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.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?
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).