Bootloader: Floppy vs HD vs CD
Posted: Sat Oct 22, 2011 5:22 pm
Hi OsDev forum! First, thanks for all the amazing information found on this site, and I look forward to contributing to the community knowledge base in the future.
I've recently started getting into OS dev and currently have a working single stage bootloader that simply prints some characters, loads a kernel (3 sectors following bootsector) that implements some VGA functions, and a c utility that packages all of that up into a flat binary floppy image. It's at the point where I have a working knowledge of what's going on, and it's time to start expanding, starting with a proper bootloader. (Also, I'm fully aware that GRUB will do everything and more, but I'm entering OS development for educational value, and I feel writing a bootloader is valuable).
Also, please know that I've spent a few weeks reading the wiki/searching the forum/googling about bootloader theory/reading the GRUB src before coming to you with questions, so I apologize if there's something obvious out there I missed. I did my best!
So my goal is to move away from a flat binary image, and get some sort of file system going. I understand that the classic approach is a FAT12 floppy with a simple bootsector that can parse the filesystem (or else a utility that hard-codes the sector/size of the second stage on disk, ala grub-setup) because of the simplicity of FAT12. However, I do have problems with this approach:
1) FAT12 is old and deprecated. This will never be my OS's main file system, so why spend time on it now if there are other options that aren't terribly more complicated and are more useful (ISO)
2) Floppies are old and deprecated; people boot off CDs (which are becomming also-deprecated in favor of USB sticks now...)
3) Tool support is deprecated. I'm devving on Win7x64 through cygwin. There don't seem to be any virtual floppy emulators that work on Win7x64, and I'd rather not deal with a linux VM just to mount/write to a floppy
4) Tool support is less convenient. Even if I ignore #3 and go the VM route (or use linux natively even) it doesn't seem like the floppy image will ever be as easy as a CD image. You can just throw a mkisofs command into a makefile to generate your bootable image ready for VM testing, whereas you'd need to actually mount a virtual floppy on a virtual floppy drive, copy files, unmount it, and then fire up the VM. I suppose you could put all those commands into a makefile, but it'd be very environment-specific compared to the mkisofs approach.
In researching my options based on these criteria, it seems like El-Torrito is probably what I'm after because:
1) easy to create ISOs without dealing with drive virtualization
2) cross platform (mkisofs works in cygwin)
3) Booting from CD is something all modern OSes need to do anyway at install time, so it won't be 'wasted energy' long term
However, I do have a few questions based on what I've been read:
1) First and foremost, is any of the information/understanding I've articulated above inaccurate?
2) Is el-torrito the best route to take until my OS is ready to implement real filesystems/be installed on a hard drive (and if I'm not scared of taking on a slightly more advanced FS than fat12)?
3) Using el-torrito, is there any size limit on the bootloader anymore (other than the limitations of 0x7C00 up until the end of free low-memory itself)? Does the El-Torrito method load the entire file specified by the -b flag, or does it only load one sector?
4) Is the concept of a multi-stage bootloader still needed in el-torrito? If so, why?
5) I'm a little bit confused as to how the boot information table works in El-Torrito. The wiki seems to suggest that the mkisofs utility takes "-b /path/to/loader" and installs that file into the boot sector, and if passed proper parameters fills in the info like bi_PrimaryVolumeDescriptor. My question is...why do we care? If this file is already loaded into memory, this info doesn't really do anything for us unless we want to self-relocate (and why do that?)? (Afterthought: I guess bi_PrimaryVolumeDescriptor is quite useful, but what about the boot file location and length)
6) There's example source code on the el-torrito wiki that shows a simple bootloader with [ORG 0x7C00] but there's a post on the forum that says "the boot record on the CD can ask the BIOS to load 400 KiB at 0x00006000, instead of just one sector that is always loaded at 0x007C00". Is this a discrepancy, or am I getting confused between emulation and no emulation?
7) Speaking of emulation, is there any value to using emulation instead of no-emulation? The impression I get is emulation is an older practice, but at the same time I could see emulation being useful because the bootloader architecture would be roughly the same across CD, floppy, and HD (other than specifics, like which file system is implemented): a 512byte sector that knows where to find a second stage that knows how to read filesystems/set up for pmode. Seems like no-emulation would make it so you'd need a completely different CD specific bootloader that does all of that?
Thanks so much for your help!
Sean
I've recently started getting into OS dev and currently have a working single stage bootloader that simply prints some characters, loads a kernel (3 sectors following bootsector) that implements some VGA functions, and a c utility that packages all of that up into a flat binary floppy image. It's at the point where I have a working knowledge of what's going on, and it's time to start expanding, starting with a proper bootloader. (Also, I'm fully aware that GRUB will do everything and more, but I'm entering OS development for educational value, and I feel writing a bootloader is valuable).
Also, please know that I've spent a few weeks reading the wiki/searching the forum/googling about bootloader theory/reading the GRUB src before coming to you with questions, so I apologize if there's something obvious out there I missed. I did my best!
So my goal is to move away from a flat binary image, and get some sort of file system going. I understand that the classic approach is a FAT12 floppy with a simple bootsector that can parse the filesystem (or else a utility that hard-codes the sector/size of the second stage on disk, ala grub-setup) because of the simplicity of FAT12. However, I do have problems with this approach:
1) FAT12 is old and deprecated. This will never be my OS's main file system, so why spend time on it now if there are other options that aren't terribly more complicated and are more useful (ISO)
2) Floppies are old and deprecated; people boot off CDs (which are becomming also-deprecated in favor of USB sticks now...)
3) Tool support is deprecated. I'm devving on Win7x64 through cygwin. There don't seem to be any virtual floppy emulators that work on Win7x64, and I'd rather not deal with a linux VM just to mount/write to a floppy
4) Tool support is less convenient. Even if I ignore #3 and go the VM route (or use linux natively even) it doesn't seem like the floppy image will ever be as easy as a CD image. You can just throw a mkisofs command into a makefile to generate your bootable image ready for VM testing, whereas you'd need to actually mount a virtual floppy on a virtual floppy drive, copy files, unmount it, and then fire up the VM. I suppose you could put all those commands into a makefile, but it'd be very environment-specific compared to the mkisofs approach.
In researching my options based on these criteria, it seems like El-Torrito is probably what I'm after because:
1) easy to create ISOs without dealing with drive virtualization
2) cross platform (mkisofs works in cygwin)
3) Booting from CD is something all modern OSes need to do anyway at install time, so it won't be 'wasted energy' long term
However, I do have a few questions based on what I've been read:
1) First and foremost, is any of the information/understanding I've articulated above inaccurate?
2) Is el-torrito the best route to take until my OS is ready to implement real filesystems/be installed on a hard drive (and if I'm not scared of taking on a slightly more advanced FS than fat12)?
3) Using el-torrito, is there any size limit on the bootloader anymore (other than the limitations of 0x7C00 up until the end of free low-memory itself)? Does the El-Torrito method load the entire file specified by the -b flag, or does it only load one sector?
4) Is the concept of a multi-stage bootloader still needed in el-torrito? If so, why?
5) I'm a little bit confused as to how the boot information table works in El-Torrito. The wiki seems to suggest that the mkisofs utility takes "-b /path/to/loader" and installs that file into the boot sector, and if passed proper parameters fills in the info like bi_PrimaryVolumeDescriptor. My question is...why do we care? If this file is already loaded into memory, this info doesn't really do anything for us unless we want to self-relocate (and why do that?)? (Afterthought: I guess bi_PrimaryVolumeDescriptor is quite useful, but what about the boot file location and length)
6) There's example source code on the el-torrito wiki that shows a simple bootloader with [ORG 0x7C00] but there's a post on the forum that says "the boot record on the CD can ask the BIOS to load 400 KiB at 0x00006000, instead of just one sector that is always loaded at 0x007C00". Is this a discrepancy, or am I getting confused between emulation and no emulation?
7) Speaking of emulation, is there any value to using emulation instead of no-emulation? The impression I get is emulation is an older practice, but at the same time I could see emulation being useful because the bootloader architecture would be roughly the same across CD, floppy, and HD (other than specifics, like which file system is implemented): a 512byte sector that knows where to find a second stage that knows how to read filesystems/set up for pmode. Seems like no-emulation would make it so you'd need a completely different CD specific bootloader that does all of that?
Thanks so much for your help!
Sean