Page 1 of 1

Help needed booting El Torito boot sector on real machine.

Posted: Thu May 06, 2021 8:17 am
by ljtpetersen
I've been trying to write a boot loader compatible with both UEFI and legacy BIOS. So far, I've gotten UEFI working fine. As well, the boot sector works in virtual box. However, when I use Win32DiskImager (I'm on Windows with WSL) to put my ISO on a USB drive, only the UEFI boot works. My boot sector should do nothing. It jumps to the start of my code, then jumps to itself. In theory, when running my boot sector, nothing should happen. Instead, when I try to execute it, the cursor jumps around on the left of the screen before returning to the boot media selection menu.
Why would this be happening?
Also, I use the isohdpfx.bin file from the isolinux Debian package. My project is licensed under GPL 3. Is it legal for me to package that file in my project. Also, do I need to give credit? If so, where should I give credit?
As well, I use gnu-efi for the UEFI bootloader portion. To include it, there is a git clone inside my Makefile. Is that OK?

Here is the command I used to make the .iso:

Code: Select all

$ xorriso -as mkisofs -c boot/bootcat -o out/os.iso \
  -b boot/boot_sector.bin -no-emul-boot -boot-load-size 4 \
  -isohybrid-mbr boot/isohdpfx.bin \
  -eltorito-alt-boot -e boot/efi.img -no-emul-boot -isohybrid-gpt-basdat out/iso
I compiled the boot_sector.bin file with nasm:

Code: Select all

$ nasm -f bin -o boot/boot_sector.bin boot_sector.asm
My boot sector is:

Code: Select all

[org 0x7c00]
[bits 16]

Main:
    jmp 0x0:.start

    times 64 - ($ - $$) db 0

.start:
    jmp $
The rest of my code can be found on my GitHub:
https://github.com/ljtpetersen/jpos/

Re: Help needed booting El Torito boot sector on real machin

Posted: Thu May 06, 2021 8:01 pm
by bzt
ljtpetersen wrote:As well, the boot sector works in virtual box. However, when I use Win32DiskImager (I'm on Windows with WSL) to put my ISO on a USB drive, only the UEFI boot works.
I'm not sure what those command line argument specifies (and why you have specified "-no-emul-boot" twice), but the no emulation El Torito image needs a boot catalog which records the boot sector's LBA (in 2048 byte sectors). If you want a hybrid image, you'll need:

Code: Select all

sector 0: mbr for HDD
...
sector N: vbr for CDROM
...
sector M: boot catalog, with two entries: sector N for legacy BIOS machines, and sector L for UEFI
...
sector L: starting sector of the ESP
Maybe take a look at my bootloader and hybrid image creator that's known to work perfectly: BOOTBOOT (mkbootimg is an all-in-one, dependency free image creator, MIT licensed, you're free to study it's code).
ljtpetersen wrote:Also, I use the isohdpfx.bin file from the isolinux Debian package. My project is licensed under GPL 3. Is it legal for me to package that file in my project.
If you also use GPL then yes, but why do you need that in the first place? Or if you're not writing your own loader, then why don't you simply use isolinux's boot sector too?

Cheers,
bzt

Re: Help needed booting El Torito boot sector on real machin

Posted: Thu May 06, 2021 8:11 pm
by Octocontrabass
ljtpetersen wrote:Why would this be happening?
El Torito is for CDs only. It doesn't apply when you're booting from other media.

You've chosen "isohdpfx.bin" as your boot sector for non-CD media. The source code says it's really only meant to load ISOLINUX and nothing else. Are you sure it will load your code correctly?
bzt wrote:I'm not sure what those command line argument specifies (and why you have specified "-no-emul-boot" twice), but the no emulation El Torito image needs a boot catalog which records the boot sector's LBA (in 2048 byte sectors).
That's what the "-c boot/bootcat" parameter is for.

Re: Help needed booting El Torito boot sector on real machin

Posted: Thu May 06, 2021 9:01 pm
by ljtpetersen
Haha yeah I posted this topic, then continued debugging and found a solution using one of the tutorials on the wiki. https://wiki.osdev.org/Bootable_Disk
I wanted to delete this topic but it hadn't been verified by the mods yet. By the time I checked, there were already two replies.

Re: Help needed booting El Torito boot sector on real machin

Posted: Fri May 07, 2021 4:51 am
by bzt
Octocontrabass wrote:That's what the "-c boot/bootcat" parameter is for.
Yeah, but we don't know what's in "boot/bootcat". Does it contain all the required entries with valid sector addresses?

Cheers,
bzt

Re: Help needed booting El Torito boot sector on real machin

Posted: Fri May 07, 2021 1:55 pm
by Octocontrabass
Yes. The file is generated by xorriso.

Re: Help needed booting El Torito boot sector on real machin

Posted: Sat May 08, 2021 12:15 pm
by bzt
Octocontrabass wrote:Yes. The file is generated by xorriso.
I know, what I meant is, we don't know if the boot catalog is generated correctly, one should dump the actual file to see if it has really all the required entries with correct LBA addresses, and if not then there must be a problem with the command line flags. Creating a correct disk image file that can be booted from HDD under BIOS and UEFI and from CDROM under BIOS and UEFI as well is a tricky business, there are lot of things that could go wrong (different sector size is just one example). I've tried to solve these with xorriso too, but ended up writing my own tool instead.

Cheers,
bzt

Re: Help needed booting El Torito boot sector on real machin

Posted: Sat May 08, 2021 1:22 pm
by Octocontrabass
This is the same configuration used to generate every Linux hybrid ISO, so I see no reason to suspect issues with the boot catalog. The boot catalog is only used for optical media anyway, so it wouldn't cause problems with USB boot.