Hi,
Now that my kernel is ripe for memory management, I need a memory map. Unfortunately, I can't fit the code to load it in my bootloader. So I decided to build a bootloader in two stages. The only question I am asking myself is: where should I put the second stage bootloader on the disk?
First I thought of letting the kernel start with the second stage bootcode, but I have never seen anyone do that. What should I do?
Where to put the second stage boot loader
- Revelation
- Member

- Posts: 47
- Joined: Sat Jun 21, 2008 8:15 am
Where to put the second stage boot loader
Now is the winter of my disk content.
Re: Where to put the second stage boot loader
The best thing to do is put it in the next sector after your first stage.
Re: Where to put the second stage boot loader
Sadly enough, the statement (the easiest thing to do == the best thing to do) is rarely true when it comes to OSdev.
If you were desperate/lazy and willing to make your floppy (if that is the medium you are using) unreadable by most OSes, then go ahead and put the second stage loader in the next sector. The truth is, this method is hardly flexible and I don't advise it in the long run.
Most x86 bootloaders do one of the following:
- Parse the filesystem for a specific file which is the second stage and load it. This of course, requires filesystem support, and so you may have different bootloaders for floppies, CDs, and other mediums with different file systems.
- The LBA and drive of the second stage bootloader is hardcoded into the bootloader upon install. This method is filesystem independent, but it does require you to make sure in some way that the second-stage loader NEVER gets moved.
If you were desperate/lazy and willing to make your floppy (if that is the medium you are using) unreadable by most OSes, then go ahead and put the second stage loader in the next sector. The truth is, this method is hardly flexible and I don't advise it in the long run.
Most x86 bootloaders do one of the following:
- Parse the filesystem for a specific file which is the second stage and load it. This of course, requires filesystem support, and so you may have different bootloaders for floppies, CDs, and other mediums with different file systems.
- The LBA and drive of the second stage bootloader is hardcoded into the bootloader upon install. This method is filesystem independent, but it does require you to make sure in some way that the second-stage loader NEVER gets moved.
"Sufficiently advanced stupidity is indistinguishable from malice."
Re: Where to put the second stage boot loader
I personally place mine in the following sectors of the floppy, but my OS doesn't need to be read in other OS's and it doesn't need to have any sort of compliance with FS standards.
Website: https://joscor.com
Re: Where to put the second stage boot loader
I would suggest doing what Zenith advised against, and, later, if you do need to have some FS support on your boot floppy, add FS support to your bootloader.
Evolving an OS is a lot easier that spontaneously creating one.
Evolving an OS is a lot easier that spontaneously creating one.
C8H10N4O2 | #446691 | Trust the nodes.
- Masterkiller
- Member

- Posts: 153
- Joined: Sat May 05, 2007 6:20 pm
Re: Where to put the second stage boot loader
Most common FileSystem for 1.44 Floppy image is FAT12. I don't know what term you have in mind with "Most OSes". Generally it is impossible things portable for all the OSes, so Linux and Windows will be good enough. Both OSes can read FAT12 and the common structure of FAT12 is:Zenith wrote:If you were desperate/lazy and willing to make your floppy (if that is the medium you are using) unreadable by most OSes
1. Boot Record
2. Reserved Sectors (Number of sectors is specified in Boot Record)
3. FAT two times (Information about size of this field is available at Boot Record)
4. ROOT directory (Number of entries in ROOT field in Boot Record/16)
By Default reserved sectors field is zero and the FAT table comes just after the Boot Record. If you set it to one, the disk becomes unreadable until you move all sectors of FAT tables and Root directory one sector up. Freed sector is available to use for the second stage loader and also is guaranteed not to be overwritten while other OS writing to your floppy diskette.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
Current state: real-mode kernel-FS reader...
Re: Where to put the second stage boot loader
You're right, it should be supported by a lot of OSes, but from experience, I had troubles getting Linux and (sometimes) Windows to recognize a floppy with more than 1 reserved sector (honestly, I also used the consecutive sector method in my old bootloader). But this of course assumes you're using a floppy drive instead of some other boot medium like a CD.
"Sufficiently advanced stupidity is indistinguishable from malice."
- Combuster
- Member

- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Where to put the second stage boot loader
A well designed bootloader can work off a floppy, HD and CD without any changes in code. There are enough similarities between them. In the CD case, El Torito provides everything and the kitchen sink.
In fact, the more challenging task is portability to the harddisk.
In fact, the more challenging task is portability to the harddisk.