Daemon Beast
Daemon Beast

Reputation: 2909

How to make a bootable disc (.iso) that loads a kernel (.elf)

I have made a very basic kernel and I want to make a bootable disc image that loads the kernel. I have tried to convert the kernel from .elf to .bin to .iso, but this has resulted in a non-bootable disc image. When I try to load the disc image into virtualbox or qemu, it notifies me that the disc image is in raw format and fails to load.

I converted from .elf to .bin using objcopy -O binary kernel.elf kernel.bin and then attempted to convert to .iso using converters like poweriso, winiso and magiciso. The conversion either failed or created a non-bootable disc image.

How do I make a bootable disc image that loads my kernel. If a bootloader is required, I would prefer to make a custom one with very minimal code designed only to start my kernel.

Upvotes: 0

Views: 2120

Answers (1)

fysnet
fysnet

Reputation: 449

There is a lot more to it that just converting your kernel file to binary and placing it on an ISO disc (image).

You need to have a boot loader of some kind. If you boot as a legacy BIOS machine, you will need a boot loader that understands the ISO file system, finding, then reading the kernel file into memory. There are a few already made, Grub comes to mind.

Since you want to create your own (and I commend you on that), you will need to read up on how the ISO file system is stored on the disc, how the BIOS will load one or more sectors for you, etc.

For example, the BIOS will load one or more sectors from the disc using different methods. One would be floppy emulation, another could be hard drive emulation, while another could be direct ISO disc sector reads.

I would suggest that you don't start with ISO. Start with a floppy image or even better, a hard drive image. Then all you have to do is write a boot sector and loader that uses the BIOS read disk services. This is much easier.

However, don't get me wrong, there is still a lot of work to do this.

If you wish to skip all of that, you can write your kernel as a (Win) PE file and use the newer firmware (UEFI) to load it for you. EFI will use a GPT formatted drive with one or more FAT volumes and will find and load your PE formatted executable for you.

However, and some may disagree, but since you are doing this project as a learning experience, I suggest you take the Legacy BIOS route. This will let you learn a lot more about how a computer boots up, loads the first instructions, etc.

For the Legacy BIOS floppy or hard drive route, do a search for boot sectors and either floppy or hard drive. This will show you how some have accomplished the task. This boot sector usually loads another file which is the OS loader. This loader is then used to load the kernel and (possibly) other files, setting up the necessary items before jumping to the kernel.

If you wish, I have written a few books on this subject, showing how to write boot sectors for floppies, hard drives, as well as ISO disc images. I also have included example source code from an earlier version.

Upvotes: 1

Related Questions