Page 1 of 1

bootloader for cd

Posted: Sun Oct 18, 2015 11:01 am
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.

Re: bootloader for cd

Posted: Sun Oct 18, 2015 11:30 am
by sebihepp
Don't create one - use one, like GRUB.

Re: bootloader for cd

Posted: Sun Oct 18, 2015 12:18 pm
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

Re: bootloader for cd

Posted: Sat Oct 24, 2015 4:27 am
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

Re: bootloader for cd

Posted: Sat Oct 24, 2015 1:10 pm
by Awe2K
Also, this article may help you a bit.
http://wiki.osdev.org/Bootable_El-Torit ... RUB_Legacy

Re: bootloader for cd

Posted: Sat Oct 24, 2015 1:23 pm
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

Re: bootloader for cd

Posted: Sat Oct 24, 2015 11:49 pm
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