El-Torito

From OSDev Wiki
Jump to: navigation, search

El-Torito is a standard for creating bootable CD-ROMs. The standard have different ways of booting a CD. It can be either emulated as a floppy drive or hard disc or booted using the no-emulation mode, where the bootloader is read of the ISO 9660 file system.

You can create a bootable CD emulated as a floppy drive or a bootable CD using no emulation.

This page is under construction! This page is a work in progress and may thus be incomplete. Its content may be changed in the near future.

Contents

Document Scope

The intention of this document is to explain what you need to know from the El-Torito standard to create a bootable CD with your own boot sector. For practical advice on actually writing your boot sector (along with an existing directory structure) to a CD or ISO file, see the Bootable CD and Mkisofs pages.

No-Emulation Mode

As mentioned above, it is possible to take your existing floppy or hard drive boot sectors and use emulation to boot from a CD. This part of the document focusses on no-emulation mode, where your boot sector is specifically designed to run from a CD.

Writing an El-Torito Boot Sector

At the start of your El-Torito boot sector, you simply need to set segment registers to known values (as usual) and use the BIOS to load files from the CD as per ISO 9660. As with a normal floppy or hard disk, DL contains the BIOS drive number.

Using Mkisofs, you can write your boot sector to a CD image (.iso) as follows:

mkisofs -R -b path/to/loader.sys -no-emul-boot -boot-load-size 4 -o [IsoFile.iso] [IsoDirectory]

The path to the loader.sys file (or whatever your stage 1 loader is called) should be the path where the loader will reside on your CD. The [IsoFile.iso] parameter contains the output file and the [IsoDirectory] parameter contains the directory structure to appear on your CD.

A BareBones Boot Sector with Optional Boot Information Table

When writing the CD, it is possible to add a boot information table to provide some information to your boot loader. This can be created by mkisofs when your boot code is written to the iso image. The Boot Information Table starts at offset 8 and is 56 bytes long. If you are familiar with Bios Parameter Blocks, you can think of the Boot Information Table as doing a similar job.

[ORG 0x7C00]
[BITS 16]
start:
  jmp	0x0000:boot
  times 8-($-$$) db 0
 
  ;	Boot Information Table
  bi_PrimaryVolumeDescriptor  resd  1    ; LBA of the Primary Volume Descriptor
  bi_BootFileLocation         resd  1    ; LBA of the Boot File
  bi_BootFileLength           resd  1    ; Length of the boot file in bytes
  bi_Checksum                 resd  1    ; 32 bit checksum
  bi_Reserved                 resb  40   ; Reserved 'for future standardization'
 
boot:
  ;	Boot code here - set segment registers etc...
  jmp $

If you are already familiar with boot sectors for other media, this should look quite familiar already. As usual, the first thing that the code does is jump to a known segment:offset location, where it will presumably set data and stack segment registers. I have used the times macro to provide padding for the table. This has two distinct advantages: firstly, if you decide to add anything else before the table, it will continue to reside at offset 8. Secondly, if you place more than 8 bytes worth of code before the table, you will get an assembler error. The Boot Information Table may need some explanation:

bi_PrimaryVolumeDescriptor contains the LBA address of the Primary Volume Descriptor, which contains information such as the address and length of the root directory. In practice, this value will normally be 0x10, because ISO 9660 reserves sectors 0x00-0x0F as a 'system area'. And yes - no more CHS calculations, for El-Torito no emulation mode on a modern PC, it's normally a safe bet that int 0x13 extensions are available!

bi_BootFileLocation is another LBA address containing the location of the boot file on the CD. The size of the boot file can be found (in bytes) in the bi_BootFileLength field.

bi_Checksum is a 32 bit checksum of all the 32-bit values in the boot file, starting at offset 64 (just after the boot information table).

To write the boot information table to your ISO image, use the following command:

mkisofs -R -b path/to/loader.sys -no-emul-boot -boot-load-size 4 \
-boot-info-table-o [IsoFile.iso] [IsoDirectory]

-boot-load-size 4 - Specifies the number of 512-bytes sectors to load. Four 512-byte sectors (2048 bytes) is one CD sector and is the number supported by most BIOS.

The path to the loader.sys file (or whatever your stage 1 loader is called) should be the path where the loader will reside on your CD. The [IsoFile.iso] parameter contains the output file and the [IsoDirectory] parameter contains the directory structure to appear on your CD.

Important note!

There are some BIOS bugs that might prevent No Emulation booting from working properly on certain machines. A brief list of them is available here

What Next?

The rest of the CD boot process relies on ISO 9660 rather than the El-Torito standards. After you have done the 'normal' boot sector jobs, such as setting segment registers to known values and saving the contents of DL (which contains the BIOS boot drive number), you can start reading the file system, in the 2k that you have available in your boot sector.

Generally, you will want to provide a minimal ISO 9660 driver, so that you can at least find and load your next stage loader. You have an option here - you can either use the path tables to find a file, or perform a full directory walk.

See Also

Articles

External Links

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox