Page 1 of 1

VirtualBox won't boot from my ISO image

Posted: Sun Nov 01, 2020 8:18 am
by synthels
I am trying to compile my small kernel & bootloader into an ISO image with the following commands:

Code: Select all

nasm boot.asm -f bin -o boot.bin -> Compile the bootloader

Code: Select all

gcc -ffreestanding -c kernel.c -o kernel.o -> Create an object file of the kernel

Code: Select all

ld -Ttext 0x1000 kernel.o -o kernel.bin --oformat binary -> Compile it into a binary

Code: Select all

cat boot.bin kernel.bin > os.bin -> Cat them together

Code: Select all

mkisofs -no-emul-boot -b os.bin -o os.iso opt -> Create the iso image
Running this ISO through VirtualBox, I get this error: FATAL: Could not read from the boot medium! System halted.

I don't think that my bootloader is the issue, since setting -b boot.bin instead of -b os.bin with mkisofs makes the bootloader ISO work, but I can't load my kernel code like that!

Note that I don't have a GCC cross compiler set-up, I'm working from Ubuntu.

Re: VirtualBox won't boot from my ISO image

Posted: Sun Nov 01, 2020 6:03 pm
by Octocontrabass
synthels wrote:I don't think that my bootloader is the issue, since setting -b boot.bin instead of -b os.bin with mkisofs makes the bootloader ISO work,
It sounds like the size of your bootloader is the issue. Some BIOSes have trouble if your no-emulation image is bigger than 2kiB, or not evenly divisible by 2kiB.
synthels wrote:but I can't load my kernel code like that!
Yes you can!

Writing your own legacy bootloader is a big challenge. It's too easy to make a mistake somewhere that only causes problems once you run it on a different computer, and it takes a lot of time and effort to get something that works well. On top of that, new PCs have started to drop support for legacy boot. We strongly recommend using an existing bootloader (such as GRUB) to start out, and only writing your own once your OS reaches the limits of existing bootloaders.
synthels wrote:Note that I don't have a GCC cross compiler set-up, I'm working from Ubuntu.
That means setting up a GCC cross compiler will be easy. :wink: