Creating Bootable ISOs with xorriso
Creating Bootable ISOs with xorriso
An ISO 9660 image was originally designed for read-only optical CD-ROM discs. However, modern users expect an .iso file to boot from optical discs, burn directly to USB flash drives (dd if=image.iso of=/dev/sdX), and boot under both legacy BIOS and 64-bit UEFI firmware!
An image that satisfies all these contradictory requirements simultaneously is called a Hybrid ISO. Generating a hybrid ISO requires the Swiss Army knife of optical media authoring: xorriso.
+-------------------------------------------------------------+
| Anatomy of a Modern Hybrid ISO |
| |
| Sector 0: Master Boot Record (MBR) |
| - Boot code for legacy BIOS |
| - Partition table mapping the ISO and ESP |
| Post-MBR Gap: GRUB Core Image (i386-pc) |
| |
| ISO 9660 Primary Volume: |
| ├── /boot/vmlinuz-byol |
| ├── /boot/initramfs-byol.img |
| ├── /byol/rootfs.squashfs (Compressed OS payload) |
| └── /EFI/BOOT/BOOTX64.EFI (UEFI bootloader binary) |
| |
| El Torito Boot Record Catalog: |
| ├── Legacy BIOS Boot Catalog entry |
| └── EFI Boot Catalog pointing to the embedded FAT ESP image |
+-------------------------------------------------------------+
The El Torito Specification
In 1994, Phoenix Technologies and IBM authored the El Torito specification to allow computers to boot from CD-ROMs: - It defines a specialized directory in the ISO filesystem called the Boot Catalog. - For BIOS, it points to an initial boot sector (such as ISOLINUX isolinux.bin or GRUB eltorito.img). - For UEFI, it points to a partition image formatted as FAT32 containing /EFI/BOOT/BOOTX64.EFI.
The Master xorriso Command
The command to assemble a hybrid bootable ISO combining BIOS and UEFI support is one of the most sophisticated invocations in Linux administration:
$ xorriso -as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "BYOL_LIVE" \
-appid "BYOL Linux Live Installer" \
-publisher "K19G" \
-eltorito-boot boot/grub/bios.img \
-eltorito-catalog boot/grub/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--grub2-boot-info \
-eltorito-alt-boot \
-e EFI/boot/efiboot.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-output "byol-installer-x86_64.iso" \
iso-staging/Explaining the Critical Flags:
-volid "BYOL_LIVE": The filesystem volume label. Crucial: your initramfs/initscript will search for this label (LABEL=BYOL_LIVE) to locate its installation media!-eltorito-boot boot/grub/bios.img: Tells legacy BIOS systems where to find the Stage 1 bootloader.-e EFI/boot/efiboot.img: Specifies the FAT16/FAT32 floppy/hard-disk image containing the UEFI bootloader.-isohybrid-gpt-basdat: Modifies the MBR and GPT partition headers so modern motherboards see the ISO as a valid bootable USB thumbdrive when written withddor Rufus.