3

I've noted that the Ubuntu ISO file is bootable on systems with BIOS and with UEFI. I've remastered Ubuntu from scratch and I'd like my ISO file to be bootable in both cases.

My remastering of Ubuntu is done by first installing debootstrap into a chroot jail, and then gradually adding files until I have all desired programs. However, the resulting ISO file is only bootable on a system with BIOS.

I believe I need some different magic with mkisofs, but what about the files in EFI/BOOT? What is the origin of those files? Is there anything else I need?

Thanks!

AndyS

AndyS
  • 31

1 Answers1

0

You can generate an ESP (EFI System Partition) image suitable for booting on UEFI with:

#! /bin/sh

BOOT_IMG_DATA=$(mktemp -d)
BOOT_IMG=efi.img

mkdir -p $(dirname $BOOT_IMG)

truncate -s 4M $BOOT_IMG
mkfs.vfat $BOOT_IMG
mkdir -p $BOOT_IMG_DATA/efi/boot

grub-mkimage \
    -C xz \
    -O x86_64-efi \
    -p /boot/grub \
    -o $BOOT_IMG_DATA/efi/boot/bootx64.efi \
    boot linux search normal configfile \
    part_gpt btrfs fat iso9660 loopback \
    test keystatus gfxmenu regexp probe \
    efi_gop efi_uga all_video gfxterm font \
    echo read ls cat png jpeg halt reboot

mcopy -i $BOOT_IMG -s $BOOT_IMG_DATA/efi ::

That will generate a FAT-formatted file (change the location of the file by changing the $BOOT_IMG variable), which is, in turn, an ESP image.

You can use the generated image by adding the flag -append_partition 2 0xef efi.img to the xorriso command.

The resulting xorriso command may be something like this:

xorriso -as mkisofs \
    -r -V <ISO_LABEL> \
    -o <OUTPUT_ISO_IMAGE> \
    -J -J -joliet-long -cache-inodes \
    -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
    -b isolinux/isolinux.bin \
    -c isolinux/boot.cat \
    -boot-load-size 4 -boot-info-table -no-emul-boot \
    -eltorito-alt-boot \
    -e --interval:appended_partition_2:all:: \
    -append_partition 2 0xef efi.img \
    -no-emul-boot -isohybrid-gpt-basdat \
    <ISO_DIRECTORY>

Bear in mind that you also need to use ISOLINUX if you want your image to boot on BIOS systems. GRUB2 is for UEFI.

Also, you should use a recent version of xorriso (the flag --interval:appended_partition_2:all:: was added a couple years ago, so old versions doesn't support it).

For further guidance, also take a look to this question.