Reliable Custom FS Bootloader solution using GrUB.

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Reliable Custom FS Bootloader solution using GrUB.

Post by gravaera »

I discovered, by a small moment of extreme insight, that it is entirely possible to have a kernel loaded off of any custom filesystem by GrUB no less, via a method which completely invalidates the need to write any form of 512 byte partition bootsector code.

The method is simple: For OSs not using EXT, ReiserFS, or any other FS format recognized by GrUB, simply reserve a number of sectors directly following the first sector of your FS's partition on any drive.

Place your ELF kernel image in this space. Have GrUB load the kernel image from the first N secotrs of the partition. In this manner, any kernel image of any size may be loaded by GrUB off any custom Fs format.

Since GrUB loads the kernel directly off a partition, no bootloader is needed. In other words, the partition bootloader stage is completely bypassed. So no matter what partition your kernel exists on, GrUB can load it, and load it into protected mode no less, as long as GrUB is installed into the MBR.

http://wiki.osdev.org/I_use_a_Custom_Fi ... _for_me%3F

Please see the above link for more information. It may also be wise to add this to the Wiki's FAQ, so as to once and for all cut short the stream of constant bootloader questions. If everyone uses this method, then they get jumped directly into the protected mode kernel stage even on real hardware.

--All the best
gravaera
Last edited by gravaera on Tue Nov 03, 2009 3:31 pm, edited 1 time in total.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Combuster
Member
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: Found the ultimate Bootloader solution using GrUB.

Post by Combuster »

This just reminded me of a beginner mistake (no offence meant):

The reason to have the kernel stored in the filesystem is for convenience - you don't have static sizes, you don't have to special case to store a kernel, and it's user friendly. And once it works, you can just forget about it. While yes, GRUB can well operate in an unformatted environment but the key feature of GRUB over other bootloaders is that it can also operate in hosted environments.

Why would you think we were all no longer using LILO? :wink:


Nice article, but I would seriously considering labeling it something other than "ultimate solution" 8)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Found the ultimate Bootloader solution using GrUB.

Post by gravaera »

Heh. Point taken. :)

I'll just label it: Flexible GrUB based solution, or something to that effect.

--All the best
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Reliable Custom FS Bootloader solution using GrUB.

Post by Solar »

No offense intended, but of all the ways to boot your kernel using GRUB, this is the least flexible... it expects a kernel of a given size at a given position on the disk (as Combuster said). That's what LILO did, which is why GRUB was so successful getting rid of these limitations...
Every good solution is obvious once you've found it.
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

Re: Reliable Custom FS Bootloader solution using GrUB.

Post by fronty »

s/GrU/GRU/g. Purely aesthetic correction.
User avatar
scgtrp
Member
Member
Posts: 30
Joined: Sat Mar 28, 2009 7:32 pm

Re: Reliable Custom FS Bootloader solution using GrUB.

Post by scgtrp »

I made some miscellaneous capitalization fixes (mostly s/GrUB/GRUB/g).

My opinion is that this seems like an exceptionally hacky and temporary way to do it.
Better temporary solution: put the kernel and GRUB on a floppy/CD image; load kernel from there but have the kernel load anything else it needs from the correct partition.
Better permanent solution: implement your filesystem in GRUB.

This isn't a good enough solution to justify potentially changing the filesystem spec to allow for reserved sectors at the beginning.
Post Reply