kerravon wrote:Then it presents that as a read-only hard disk?
It does not present anything as anything. A CD is a CD, a hard disk is a hard disk, a USB stick is whatever the firmware chooses to present it as (which is very rarely a CD, historically often a floppy disk, and in the waning days of BIOS systems would have been a hard disk) up until the OS prods the magic handover bits to say it knows what the hell USB even is.
ISO9660 doesn't use the first CD sector of a medium: That's a whole 2048 bytes you can just do whatever you want with. What GRUB chooses to do is put a traditional boot sector in the first 512 bytes. This is a very common strategy and is called an
isohybrid. El Torito specifies how BIOS may locate a boot payload on a CD - actually, it specifies how firmware in general can locate
several boot payloads, as it was designed with the thought of supporting multiple architectures. With an El Torito isohybrid, you could have entirely different codepaths between your MBR and your El Torito boot payload - one taken by hard disks and floppy disks, the other by actual CDs - but there's no reason to do so: The BIOS disk read functions are generic - ah=42h will read a CD, a hard disk, a floppy disk - it doesn't care. You do need to query the sector size, though, as CDs use 2048 byte sectors and hard disks use 512 (or at least pretend to), but with a bit of division or multiplication this difference is irrelevant. So, GRUB, and most other isohybrid bootloaders, have a common second stage and both the MBR and the El Torito boot payloads load the same thing and continue on their merry way. GRUB
is big and complicated, and after loading the second stage it will have filesystem drivers so it can read ISO9660 or FAT or EXT or various other things, but it does not care much about the medium they are on: it continues to jump back to the BIOS to perform disk operations until/unless a native driver is loaded for a storage mechanism.
One neat thing about El Torito payloads is that they can be more than 512 bytes. How much more is uncertain - a BIOS may not support loading hundreds of sectors, for example, but it may be enough that your El Torito payload can
be the second stage, and your MBR boot code can load your El Torito payload from a fixed offset. This is how I do things - my El Torito boot payload is a whopping 25K, containing my whole generic BIOS loader.
Another neat thing that comes from El Torito's support for multiple boot payloads is that EFI specifies an El Torito payload to make EFI-bootable CDs. Unfortunately, it specifies that payload be a tiny FAT partition image, which can be a bit of a pain. Another trick I pull is to set up that FAT image for 2048 byte sectors, put all of the files I would normally put on my CD in it (which used to be several but is now just a kernel and ramdisk), ensuring they are contiguous, give the CD empty files with the right names, and then patch up the ISO filesystem afterwards with the offsets and sizes of the files in the FAT - EFI presents the FAT filesystem through its file-oriented disk APIs, and my BIOS loader sees the ISO9660 filesystem, but they both get the same files! As a special case of this, one particular build of my OS also has a file in the ISO that spans the whole disk (something ISO9660 is perfectly happy to do!), that just so happens to have "PDF" as its file extension, but that is somewhat off-topic for this thread.
Octocontrabass wrote:Syslinux uses 0x17. [...] Some BIOSes will examine the partition table and misbehave or refuse to boot if a partition starts at LBA 0.
For isohybrids, a partition ID of 0xCD is used with a claimed start LBA of 1. I think the original isohybrid implementation would throw in a fake partition with ID 0x17, which is supposedly assigned as a Windows "internal filesystem". GRUB ISOs are readable when written to a hard disk, at least under Linux, so either some devious probing is happening or the fake start LBA is understood.
My own hand-crafted isohybrids do not present any partitions, but seem to work on most hardware I've tried them on when written to USB sticks and booted as hard disks - but I'm probably just lucky!