booting kernel from bootsector

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
bradd

booting kernel from bootsector

Post by bradd »

Hey guys.. For my floppy boot, I have a bootsector that loads the next stage from my own floppy filesystem.. thats all fine and good.. What I need to know is how to do this with a hard drive.. I mean, I have 512bytes at the start of the HD, but how would I load the next stage?? would I mark the blocks as used and store the starting block in the bootsector? Or would I have to implement my filesystem in the 512bytes??
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:booting kernel from bootsector

Post by bubach »

Thats up to you.
bradd wrote:Or would I have to implement my filesystem in the 512bytes??
No, but enought of it to load a file..
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:booting kernel from bootsector

Post by Solar »

Examples might help.

LILO - the Linux Loader - determines the sector number of the kernel image, and stores that in the boot sector. That way, LILO doesn't have to understand the file system, it just tells the hard drive to load from sector X. This is "one-stage bootloading". The downside is that, whenever you recompile your kernel, you have to re-run LILO (reinstall the MBR) because the sector number of the kernel image changed.

GRUB - the Grand Unified Bootloader - does a similar thing (sector number hardcoded into the MBR), but it doesn't load the kernel but a second GRUB stage, which in turn is "smart" enough to read the file system, load the configuration file, and find any kernel image by actually interpreting the file system. That's "two-stage bootloading", with the advantage that you don't hae to do anything after a kernel recompile.
Every good solution is obvious once you've found it.
Dreamsmith

Re:booting kernel from bootsector

Post by Dreamsmith »

DOS provides another example. Like GRUB, it interprets the filesystem and loads the file regardless of it's physical location, but like LILO, it does this in one stage. It can get away with this since the filesystem it reads is simple enough to be interpretted from a 512-byte snatch of code. Some other operating systems have a "boot filesystem" designed to be easy to interpret for that very reason...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:booting kernel from bootsector

Post by Pype.Clicker »

Dreamsmith wrote: DOS provides another example.
are you sure of this ? afaik, DOS had some hidden system (thus unmoveable) files like MSDOS.SYS that were implied in the BOOT process ... They were damn looking like a second stage ...
Dreamsmith

Re:booting kernel from bootsector

Post by Dreamsmith »

Sort of/not really. There are actually three files involved in the normal DOS boot process: IO.SYS, MSDOS.SYS, and COMMAND.COM. IO.SYS is the one that is loaded first, and is the one that processes your CONFIG.SYS. Whether MSDOS.SYS is then loaded or not depends on the system (under DOS 7.0+, MSDOS.SYS is just a text file). But in any case, this isn't really a multistage boot process in the same sense as we were discussing above WRT GRUB and LILO. (If it was, then LILO would also have to be considered a multistage booter -- after all, loading the Linux kernel is just the first step, booting proceeds by loading /sbin/init).
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:booting kernel from bootsector

Post by Pype.Clicker »

what i actually meant is that i'm not sure at all that MS-DOS were using the FAT lookup to locate MSDOS.SYS (when it wasn't a text file) but that it instead hard-code its position and length and made it system-file so that it doesn't move.

afaik, in DOS7+ (e.g. win9x), the actual 'MSDOS.SYS' content has been moved to some system location after the boot sector ...
aladdin

Re:booting kernel from bootsector

Post by aladdin »

I think MS-dos uses interpret fat file system since version 3.0 (Kro$oft announced that system file can now be any where in the root dir, and they where very happy), but before that, system files was in contigous region, just after fat, and was stored on a "hidden zone", this zone was protected by medos itself so you can't move them.
Post Reply