Looking closely at a personal bootloader of mine that I'm starting to code, I have a question. This appears when I performed the following steps:
- I created the bootloader.asm and made the bin:
nasm -f bin bootloader.asm -o bootloader.bin
- Place the generated bin at the beginning (Sector 0) of a zero-padded file (size 1.44 MB, standard floppy disk capacity):
dd if=/dev/zero of=bootloader.img bs=1024 count=1440
dd if=bootloader.bin of=bootloader.img seek=0 count=1 conv=notrunc
- Created the iso image, with a given directory, in the El Torito extension:
genisoimage -quiet -V 'hashidaOS.iso' -input-charset iso8859-1 -o hashidaOS.iso -b bootloader.img -hide bootloader.img iso/
After all this, everything is working in a virtual machine, but when I tried to read the .iso to find out more about El Torito I realized that sector 0 (512 bytes) of the .iso are all 0! So how can this be if the virtual machine's "virtual bios" tries to fetch the bootloader only from sector 0?
To read the .iso I used:
hexdump -C hashidaOS.iso
and
dd if=HashidaOS.iso bs=512 count=1 | xxd
Both gave me the cruel truth of the zeros filled in Sector 0.
Based on all this (sorry if I wrote so much, one of my first questions on stack overflow), can you guys answer some questions, please? Here they are:
- If the storage is bootable, is the bootloader really in physical sector 0 all the time?
- How did Oracle VM fetch my bootloader if it is not in Sector 0 of the .iso?
- Are the INT 19h for loading the bootloader also used by the Oracle VM as a real BIOS? If so, does it also load sector 0 of the storages?
- That sector 0 missed code could be something related to the ISO El Torito specifications?
I would be very grateful for any help, sorry if there are any English mistakes, I'm dying of sleep finishing this question
For bootable CD-ROMs there's a "boot catalogue", which is like a list of different boot loaders. The computer's firmware searches this list for whatever makes sense. For example, if the computer is "80x86 BIOS" it will search for a boot catalogue entry that is intended for "80x86 BIOS", and if the computer is "80x86 UEFI" it will search for an entry that is intended for "80x86 UEFI", and if the computer is PowerPC or SPARC or anything else then the firmware will search for a suitable boot loader for those. That way you can have a single CD (possibly an OS installer) that supports and works for many different computers, with a different/suitable boot loader for each type of computer.
The boot catalogue entry also says where on the CD the actual bootable data for the boot catalogue entry is. The data is never in "sector 0 of the CD"; and all specifications relating to CD-ROMs specify the first sector (and the first 16 sectors I think) as "all zeroes" because a CD's sectors are written in a spiral and a CD reader will start at a random position on the outer-most part of the spiral with no guarantee that it will be any specific sector, and with a poor ability for a CD drive to "seek backwards" from a random starting point to the first sector. In other words; the hardware is designed to have a blank and ignorable "lead in" at the start of the media to solve technical problems (it's much easier to start at a random sector at the start of the spiral and scan/seek forwards).
For "80x86 BIOS" there's actually 3 possibilities for boot catalogue entries: emulate a floppy disk, emulate a hard disk, and don't emulate anything. The first 2 options are for legacy boot loaders that were written before CD-ROMs existed, and in those cases the boot catalogue entry points to a disk image, and booting from the emulated disk follows the old rules for the emulated device.
In other words, for "floppy emulation" the boot loader will be in the first fake/emulated sector of the fake/emulated floppy disk, and could actually be almost anywhere on the real CD but should not be in the first sector of the CD.
I should probably also mention that in old CHS schemes (that are used for real and emulated floppy disks) the first sector is traditionally "sector 1" (and "sector 0" doesn't exist). This is something you'll need to remember when your boot loader tries to load something to boot from the floppy disk.