Creating a bootable ISO image with custom bootloader

前端 未结 2 859
滥情空心
滥情空心 2020-12-06 02:39

I am trying to convert a bootloader I wrote in Assembly Language to an ISO image file. The following is the code from MikeOS bootloader. Here is my bootloader code:

2条回答
  •  我在风中等你
    2020-12-06 03:20

    For CD; there's a specification ("El Torito") that describes how bootable CDs work; where the first 16 (2048-byte) sectors are unused, there's a "boot catalogue" that the firmware uses to decide which boot loader it should use (so you can have a single CD that boots very different systems - e.g. PC BIOS, UEFI, PowerPC, etc), then the boot loaders themselves.

    For "PC BIOS" alone, there's 3 possibilities:

    • emulate a floppy disk (using a "floppy disk image" stored on CD)
    • emulate a hard disk (using a "hard disk image" stored on CD)
    • no emulation

    The first 2 options are mostly for compatibly purposes only (crusty old OSs that don't support booting from CDs, like MS-DOS); and have performance implications (e.g. to emulate loading one 512-byte virtual sector, the firmware has to load a real 2048-byte sector and throw away the excess 1536 bytes). Any OS designed/written in the last 15+ years should be using "no emulation".

    For "no emulation":

    • The firmware loads your entire boot loader (which can be up to about 512 KiB) and not just one sector
    • Sectors on CDs are 2048 bytes (and not 512 bytes); and should be loaded via. "int 0x13 extensions" (and not the old/limited "CHS disk functions" that you'd use for floppy)
    • There is no need for a BIOS Parameter Block (which should be considered mandatory for floppy disks)
    • There is no need for a partition table (which should be considered mandatory for hard disks, including GPT)
    • You'll probably want to support ISO9660 as the file system (to find the kernel and/or other files that the boot loader needs to load) and not FAT.

    Also note that (in general) for "PC BIOS" you're probably going to want 5 different boot loaders (one for floppy, one for "MBR partitioned" hard disk, one for "GPT partitioned" hard disk, one for CD, and one for network boot). These cases are all different enough (and the "one 512-byte initial sector only" limitation for 3 of these cases is restrictive enough) to make the "all devices supported by one boot loader" idea a disaster.

    To actually generate the ISO; you can use an existing tool (e.g. mkisofs), or you can write your own tool (ISO9660 and "El Torito" are both relatively easy to understand, and writing your own tool to generate an ISO can be done in less than 2 days, which is like a drop in the ocean for OS development projects).

提交回复
热议问题