Extended bootloader...

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
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Extended bootloader...

Post 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?
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: Extended bootloader...

Post 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
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: Extended bootloader...

Post 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
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Extended bootloader...

Post 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
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Extended bootloader...

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: Extended bootloader...

Post 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).
Post Reply