Score:0

Grub2 boot from iso image

mx flag

I have set up a PXE boot environment using pxelinux but since I updated my motherboard's firmware, it doesn't support legacy mode anymore. So I added support for UEFI mode to my PXE setup.

I have compiled grub 2.06 with all modules included and am now at a point where I can boot into grub and it actually loads the grub.cfg from the TFTP server. I can boot my diskless ubuntu installation from NFS, Clonezilla and Parted Magic, both extracted from the ISO and with custom boot flags. The NFS and TFTP and DHCP servers are all provided by a raspberry pi 4 (aarch64).

Before I was able to simply boot from an ISO image using syslinux's memdisk tool. I have read it's documentation and I saw that I am supposed to be able to boot with grub2 using an entry like this:

menuentry "Memtest (ISO)" {
        linux16 /memdisk iso
        initrd16 /memtest/mt86plus64.iso
}

However when I select that entry I get an indicator that memdisk, then mt86plus64.iso are being downloaded and after that it simply hangs. When entering those commands in the prompt it hangs when trying to send boot. I get the newline, then it hangs.

I know I can use a loopback device like this

menuentry "Memtest (ISO)" {
       set isofile=/memtest/mt86plus64.iso
       loopback loop $isofile
       chainloader (loop)/EFI/bootx64.efi
       loopback --delete loop
}

However that has multiple drawbacks compared to the memdisk option. Firstly it requires individual configuration for every option where to load the kernel or bootloader. This is already a problem because I don't even know how to boot from Magic Boot Disk, which has msdos files, or SuperGrubDisk2, which doesn't support loopback booting at all, but works just fine with memdisk.
Secondly it downloads the entire iso image every file access. I wanted to boot from the ParrotOs ISO file with this entry:

menuentry "ParrotOS (ISO)" {
    set iso_path="/parrotos/Parrot-security-5.2_amd64.iso"
    export iso_path
    loopback loop $iso_path
    root=(loop)
    configfile /boot/grub/loopback.cfg
    loopback --delete loop
}

It then downloads the 5GB iso to fetch loopback.cfg, then it downloads the entire iso again to fetch grub.cfg, then 5GB again every time to fetch 3 fonts, 4 mods, etc. It just is not feasible at all to download the whole file 500 times just to get the bootloader to work. I actually haven't sat through the entire thing and gave up after 3 hours so I don't even know if that would work to begin with.

I can boot it by extracting the files from the ISO and then setting that directory as an NFS root, but again that is limited to kernels that support NFS.

So how do I boot arbitrary iso files? Preferably how do I fix memdisk, alternatively how do I maybe move the iso image to ram so I don't need to download it again and again?

EDIT I have found a partial answer here, but I'd still like some way to boot iso images (and other images) that would allow booting in UEFI mode.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.