Asking about 2 stages of bootloader

Why must there be 2 stages of bootloaders in a general-purpose system? Why can’t the first stage bootloader perform the functionality of the second stage bootloader?

I have tried to search on wiki and google but there is no result for those question

In an (U)EFI system, there is only a single “boot loader”, therefore, I am going to assume you are talking about a legacy BIOS Booting system here.

Most Legacy systems use the MBR partitioning system. This MBR resides in the first sector of the disk, and is loaded by the POST and executed. This MBR is commonly used to only load the first sector of a partition. This technique is independent of the file system(s) installed.

This MBR only loads the first sector of the partition. This newly loaded sector then must either load any remaining sectors or load another complete file.

One of the most common errors found when just starting out is that the coder places the disk read services in an area that has yet to be read. Therefore, all of the functionality that reads any remaining sectors must be in this first 512 bytes loaded by the MBR.

Depending on the file system used, these 512 bytes is not really enough to do a comprehensive read of the file system.

Therefore, usually the first stage loader loads a second stage loader, whereas this second stage loader knows the file system it resides on, and can load many files, placing them in specific/random places, etc., allowing for a much more comprehensive loading system.

The first stage loader then only has to worry about finding one file, usually in the root directory, or a known child directory.

Another thing to know is that depending on the file system installed, there is a set amount of room for the first stage loader. For example, a FAT file system allows up to so many sectors after the BPB and before the FAT. This amount of space may not be enough for a comprehensive loader. Therefore, the first stage loader resides in this area and loads the second stage from the file system. Some FAT drivers also incorrectly assume this space will only be one sector.

Other examples include a Linux ext2 system only allowing two blocks before the super-block. The LEANFS allows up to 32 blocks for this first stage loader.

Since each file system only allows so much space in its initial loaded area, the first sector loaded by the MBR, this usually means you must have a second stage loader.

With this being said, this doesn’t mean that the first stage boot loader can’t do what the second stage loader does. If you are designing your own system, the sky is the limit. You can do just about anything you want. The only draw back is, if the file system you use is not a commonly used system, you can’t transfer files from a host to your guest. Therefore, most people choose a common file system to be able to transfer files to and from with ease.

Leave a Comment