bootloader for cd

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
gamecraftCZ
Posts: 1
Joined: Sun Oct 18, 2015 10:12 am

bootloader for cd

Post by gamecraftCZ »

Hello.
I want to create os, but i don't know how to create bootloader for load kernel from the cd.
Please help.
sebihepp
Member
Member
Posts: 190
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: bootloader for cd

Post by sebihepp »

Don't create one - use one, like GRUB.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: bootloader for cd

Post by Brendan »

Hi,
gamecraftCZ wrote:I want to create os, but i don't know how to create bootloader for load kernel from the cd.
Please help.
How it works is the firmware looks for a Boot Record in a specific sector of the CD; which tells it the disk is bootable and where to find a Boot Catalogue. The Boot Catalogue can have one or more entries (e.g. one for 80x86 BIOS, one for 80x86 UEFI, one for PowerPC, one for Itanium, etc), and the firmware chooses one that suits it (e.g. if the firmware is 80x86 BIOS it'd choose the Boot Catalogue for 80x86 BIOS). In this way you can have (e.g.) a generic "OS installer" CD that works on multiple platforms.

For 80x86 BIOS; there's 3 options: emulate a floppy disk (where the Boot Catalogue points to a floppy disk image), emulate a hard disk (where the Boot Catalogue points to a hard disk image), and "no emulation". The emulation options are mostly intended for crusty old OSs that don't support CD (e.g. DOS).

For the "no emulation" option; the BIOS loads your entire boot loader (which can be up to 500 KiB) and starts it. Typically; the boot loader would find file/s in the ISO9660 file system and load them (by using "int 0x13 extensions" to load 2048-byte sectors), in addition to doing whatever else it likes (getting a memory map and converting it into a nice/consistent representation like GRUB fails to do properly; auto-detecting and then setting the best video mode for the OS, video card and monitor, like GRUB fails to do properly; configuring paging so you don't need an awkward/ugly kludge at the start of your kernel like GRUB fails to do, handling security features like decryption and TPM like GRUB fails to do, etc).

So...

The first thing you're going to need is a utility that creates a ("*.iso") disk image, that can create the Boot Record, Boot Catalogue and data that the Boot Catalogue entries refer to; plus the files in the ISO9660 file system itself. There are existing utilities that can/will do this for you; but if you understand the ISO9660 file system (which you're going to need to understand to write a "no emulation" boot loader anyway) it's not too hard to write your own (e.g. so easy that it can be done with NASM macros alone), and writing your own utility can be more flexible.

Once you've got that working with a dummy "jmp $" boot loader (and tested to make sure other OSs can see files in the file system, and that it boots up to your "jmp $" properly); then start writing the boot loader.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
d3crypt
Posts: 12
Joined: Fri Oct 23, 2015 3:36 pm
Libera.chat IRC: d3crypt

Re: bootloader for cd

Post by d3crypt »

Brendan wrote:Hi,
gamecraftCZ wrote:I want to create os, but i don't know how to create bootloader for load kernel from the cd.
Please help.
How it works is the firmware looks for a Boot Record in a specific sector of the CD; which tells it the disk is bootable and where to find a Boot Catalogue. The Boot Catalogue can have one or more entries (e.g. one for 80x86 BIOS, one for 80x86 UEFI, one for PowerPC, one for Itanium, etc), and the firmware chooses one that suits it (e.g. if the firmware is 80x86 BIOS it'd choose the Boot Catalogue for 80x86 BIOS). In this way you can have (e.g.) a generic "OS installer" CD that works on multiple platforms.

For 80x86 BIOS; there's 3 options: emulate a floppy disk (where the Boot Catalogue points to a floppy disk image), emulate a hard disk (where the Boot Catalogue points to a hard disk image), and "no emulation". The emulation options are mostly intended for crusty old OSs that don't support CD (e.g. DOS).

For the "no emulation" option; the BIOS loads your entire boot loader (which can be up to 500 KiB) and starts it. Typically; the boot loader would find file/s in the ISO9660 file system and load them (by using "int 0x13 extensions" to load 2048-byte sectors), in addition to doing whatever else it likes (getting a memory map and converting it into a nice/consistent representation like GRUB fails to do properly; auto-detecting and then setting the best video mode for the OS, video card and monitor, like GRUB fails to do properly; configuring paging so you don't need an awkward/ugly kludge at the start of your kernel like GRUB fails to do, handling security features like decryption and TPM like GRUB fails to do, etc).

So...

The first thing you're going to need is a utility that creates a ("*.iso") disk image, that can create the Boot Record, Boot Catalogue and data that the Boot Catalogue entries refer to; plus the files in the ISO9660 file system itself. There are existing utilities that can/will do this for you; but if you understand the ISO9660 file system (which you're going to need to understand to write a "no emulation" boot loader anyway) it's not too hard to write your own (e.g. so easy that it can be done with NASM macros alone), and writing your own utility can be more flexible.

Once you've got that working with a dummy "jmp $" boot loader (and tested to make sure other OSs can see files in the file system, and that it boots up to your "jmp $" properly); then start writing the boot loader.


Cheers,

Brendan
Great information! Thanks
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: bootloader for cd

Post by Awe2K »

Also, this article may help you a bit.
http://wiki.osdev.org/Bootable_El-Torit ... RUB_Legacy
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: bootloader for cd

Post by BASICFreak »

If you are set on making you own This may help.

@Brendan - I know it's old, but I'm curious if you are working on recreating these as they are some of the best references that I have found on many subjects :D
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: bootloader for cd

Post by Brendan »

Hi,
BASICFreak wrote:If you are set on making you own This may help.

@Brendan - I know it's old, but I'm curious if you are working on recreating these as they are some of the best references that I have found on many subjects :D
Thanks :)

I'll be re-implementing similar code in the next/current version of my project; but I've shifted from "viewable source" to closed source, and the current version of my build utility (the utility that builds everything, including the project's web site and documentation) no longer supports "HTMLizing" source code.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply