How make a bootable ISO for my UEFI application bare bones?

Well, I maked a rust UEFI application and run it on the efi shell of virtualbox ( development of my application is on ubuntu 20.04 and tests are hosted on virtualbox installed on windows 10 session ).

To do this, I make an ISO file like :

xorriso -as mkisofs -R -J -o myiso.iso /some/directories/BOOTX64.EFI /some/others/directories/myapp.elf

When Im on virtualbox, I switch to FS0 file system and I can see my 2 executables : ( BOOTX64.EFI and myapp.elf ). The BOOTX64.EFI is launched by command line, work and return some information like the gop protocol framebuffer localisation and some other stuff. I also use the EFI file system to load and use myapp.elf and for this part of program, it doesn't give information about myapp.elf file or I can't read it. ( no error, no warning, I'm almost sure my code in the EFI application is correct but for example, the file_info protocol return 0 ( size or file_size )).

I think the problem is my ISO file, isn't a true bootable file format. For example, after switched FS0 file system and list the content on the EFI shell, all executables information like date or hour are at 0. ( only file size is returned correctly ).

I don't wanna use application like grub or isolinux because the goal of my project is to learn to make that. ^^

If someone can explain step by step the procedure to make a bootable .ISO of UEFI application bare bones with some others executables included in the .ISO, will be really appreciated.

Hopefully that's the problem...


Since you reopened the question on superuser I decided to give it a go on my own side.

The culprit is that you create an ISO without partitioning the ISO as GPT and without marking any partition as ESP (EFI System Partition). You are thus left with an ISO that is not recognized by the basic utilities shipped with UEFI including the filesystem drivers.

What you need to do is to make an ESP on your system and then make an ISO out of that ESP. Follow these steps:

  1. Create a disk.img full of zeroes.
dd if=/dev/zero of=disk.img bs=512 count=93750
  1. Partition that raw zeroed image with GPT and create a ESP partition on it(type in order o, y, n, default, default, default, ef00, w, y). See the image for more details on the steps of the gdisk command.
gdisk disk.img

gdisk-example

  1. Setup a loopback device to mount the disk.img. The disk.img file here is a raw hard-disk image. It isn't in any special format like a .iso format. It means that nor the Linux archiver nor the Linux mount utility will recognize it. You need to use losetup to setup a loopback device that will make this raw disk image into an actual fake hard-disk device that the mount utility can then mount easily. The offset in the command specifies where the partition starts. You can use fdisk -lu disk.img to find out where this partition starts. The offset given here is the right one for the steps I've mentionned above so it should work without problem.
sudo losetup --offset 1048576 --sizelimit 46934528 /dev/loop5 disk.img
  1. Create a FAT32 filesystem on the loopback device. Basically, you are creating a full filesystem on the ESP partition.
sudo mkdosfs -F 32 /dev/loop5
  1. Mount the filesystem on /mnt.
sudo mount /dev/loop5 /mnt
  1. Copy the efi app to the mount point.
sudo cp path/to/boot.efi /mnt
  1. Copy the kernel to the mount point.
sudo cp path/to/kernel.elf /mnt
  1. Make an ISO file out of the whole mount point.
sudo mkisofs -o disk.iso /mnt
  1. Give permission to all users on the ISO.
sudo chmod a+rwx disk.iso
  1. Attach the ISO file to the virtual box cd-rom then boot the machine. You should now have your efi app in the shell along with the kernel. You should be able to boot the kernel now.

Also, feel free to put the last few commands in a script and run it directly like such:

sudo cp path/to/boot.efi /mnt
sudo cp path/to/kernel.elf /mnt
sudo mkisofs -o disk.iso /mnt
sudo chmod a+rwx disk.iso

You don't need to rerun the first few commands because, once the filesystem is mounted, you just need to copy new compiled files onto the mount point and make a new ISO file out of it. Maybe you have to rerun the first commands when you reboot I haven't tested.

Also, with this method, you don't need to setup virtual box anymore. Just set it up once to use the disk.iso file and it will always use the same file even if you modify it.

One last thing is that /dev/loop5 may be busy. Maybe try another higher loopback device if it is the case or try sudo umount /dev/loop5.