grub-mkrescue builds ISO images suitable for EFI only

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

grub-mkrescue builds ISO images suitable for EFI only

Post by mallard »

So, I've recently bought a new laptop, got it all set up, etc. and am trying to build my OS on it. The actual build goes fine, but it appears that grub-mkrescue has decided that I need HFS+ formatted EFI-only boot images, rather than anything that QEMU is going to understand, so the ISO images are completely useless. I'm not sure why it thinks I need Apple's filesystem and CoreServices, but since this new laptop does boot via UEFI, I suppose creating EFI-based images makes some sort of sense (because nobody would ever need to build images for a different system, right?).

The relevant xorriso command (from grub-mkrescue -v) is:

grub-mkrescue: info: executing xorriso -as mkisofs -graft-points --modification-date=2014120322113800 -hfsplus -apm-block-size 2048 -hfsplus-file-creator-type chrp tbxj /System/Library/CoreServices/.disk_label -hfs-bless-by i /System/Library/CoreServices/boot.efi --efi-boot efi.img -efi-boot-part --efi-boot-image --protective-msdos-label -o btos.iso -r /tmp/grub.LYil9e --sort-weight 0 / --sort-weight 1 /boot isodir/.

Of course, grub-mkrescue has no (documented) options to make it do the right thing, so short of an undocumented option I'm probably going to have to write a script to replace it. The script will also need to work on my existing systems.

Does anybody know the steps that grub-mkrescue goes through? Does it do anything that's not possible via a shell script?

The other option would be to install grub on the HDD image that's also built by my build process, but the lack of decent disk image manipulation tools makes that difficult (it seems that everyone expects you just to mount the image on the host OS to manipulate it, but that would require 'root', which would require user input during the build, which is not an option).

I suppose this post also acts as a warning that the days of grub-mkrescue being a useful tool for osdev are severely limited...

(Before someone says it: Yes, I know it's vaguely possible to configure QEMU to support EFI. No, I'm not going to consider that a "solution" to this problem.)
Image
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: grub-mkrescue builds ISO images suitable for EFI only

Post by Nable »

Quick look at man pages revealed this path:
1.
man grub-mkrescue wrote:

Code: Select all

/Really nothing about different kinds of systems/
...
SEE ALSO
       grub-mkimage(1) //<-- Hmm..
2.
man grub-mkimage wrote:

Code: Select all

NAME
       grub-mkimage - make a bootable image of GRUB
...
       -O, --format=FORMAT
              generate an image in FORMAT available formats: i386-coreboot, i386-multiboot, i386-pc, i386-pc-pxe, i386-pc-eltorito, i386-efi, i386-ieee1275, i386-qemu, x86_64-efi,
              i386-xen,  x86_64-xen,  mipsel-yeeloong-flash,  mipsel-fuloong2f-flash,   mipsel-loongson-elf,   powerpc-ieee1275,   sparc64-ieee1275-raw,   sparc64-ieee1275-cdcore,
              sparc64-ieee1275-aout,  ia64-efi,  mips-arc,  mipsel-arc, mipsel-qemu_mips-elf, mips-qemu_mips-flash, mipsel-qemu_mips-flash, mips-qemu_mips-elf, arm-uboot, arm-efi,
              arm64-efi
Is it useful?

Upd: it looks like image type of result depends on files that grub-mkrescue finds in source directory. You can specify alternative source directory via this parameter:
man grub-mkrescue wrote:

Code: Select all

       -d, --directory=DIR
              use images and modules under DIR [default=/usr/lib/grub/<platform>]
Upd2: building GRUB2 (specific version for your target) from source may be a good idea. http://wiki.osdev.org/GRUB_2#Installing ... n_Mac_OS_X
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: grub-mkrescue builds ISO images suitable for EFI only

Post by mallard »

Just for clarification, the laptop is a PC running Linux (booting via UEFI), not a Mac, despite the odd desire of grub-mkrescue to use Apple-isms.

Anyway, after a bit of research, I've found this page: http://lukeluo.blogspot.co.uk/2013/06/g ... -with.html, which contains detailed information about how grub-mkrescue works, including an extremely the useful section "2.2 Home-brewed "grub-mkrescue"", which shows exactly how to build an ISO without using grub-mkrescue. I've added commands based on those into my Makefile and it seems to work...
Image
Post Reply