20.04 booting .iso from GRUB menu

I'm trying to boot a Ubuntu .iso image from GRUB. In Full Circle magazine, #157 page 61, they describe how to do this. It doesn't work.

I edited /etc/grub.d/40-custom, and added the following...

# Full Circle #157, page 61
menuentry "Ubuntu 20.04 ISO" {
     insmod part_gpt
     insmod ext2
     set root=(hd0,gpt7)
     set isofile="/ubuntu-20.04-desktop-amd64.iso"
     loopback loop $isofile
     linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject
     initrd (loop)/casper/initrd
}

My Ubuntu root is on /dev/sda7.

My .iso file is located in /.

The error I get when I try to boot the .iso is...

disk hd0,gpt7 not found
no server is specified
can't find command noprompt
you need to load the kernel first

enter image description here

Any ideas on how to make this work?


Booting ISO Files on HDD (Including 20.04)

Basic GRUB loopback menuentry for Booting ISOs is:

menuentry "isoname ISO" {
    set root=(hdX,Y)
    set isofile="/[path]/[name].iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile --
        initrd (loop)/casper/initrd
}
  • Where hdX is the disk and Y is the partition number of the ISO location.

  • [path] is the path to the ISO file, [name] is the name of the ISO file.

  • Multiple ISO files are allowed, one or more menuentries are required per ISO file. (each ISO can have multiple persistence files).

Persistence (Optional)

  • If we want a persistent OS add the word Persistent to the GRUB menuentry, (via /etc/grub.d/40-custom).

  • If using a persistent partition make it ext4 and label it casper-rw for 19.10 and previous ISO files.

  • For 20.04 ISO files label the persistent partition writable.

  • Only one persistent partition is allowed per drive,

  • If using persistent files, each ISO can have it's own persistence.

  • Each ISO can have a writable (or casper-rw) file up to 4GB and an optional home-rw file up to 4GB.

  • Persistent files must be located on a FAT32 partition.

  • If more than one persistence file is used, a persistence-path must be given. Just the unique name of the persistent files folder is required. One casper-rw/writable file and one home-rw file per folder.

GRUB 2.04 Workaround

  • Ubuntu versions 18.04 and previous use GRUB 2.02 for booting. Versions 19.10 and later use GRUB 2.04 for booting in UEFI mode. GRUB 2.04 has problems booting ISO files in UEFI mode.

  • Workaround for booting ISO files in GRUB 2.04 UEFI mode is to add rmmod tpm to /boot/grub/grub.cfg just before the first menuentry:

    export linux_gfx_mode
    rmmod tpm
    menuentry 'Ubuntu efi' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-79a50dba-9300-4c89-b7e8-887651e746c9' {
    
  • If the host system is pre-19.10 GRUB 2.02 should be in use and workaround is not needed.

Final menuentry may look like:

menuentry "Ubuntu 20.04 ISO" {
    rmmod tpm
    set root=(hd0,3)
    set isofile="/isos/ubuntu-20.04-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile persistent persistent-path=/ub2004-1/ fsck.mode=skip quiet splash toram -- 
        initrd (loop)/casper/initrd
}

with rmmod tpm shown in alternate location.

  • toram option may be used to boot to RAM for high speed on computers with lots of RAM, but takes longer to boot.

  • fsck.mode=skip option stops Filesystem Checking.

  • The Language/Try/Install screen can be eliminated by removing maybe-ubiquity from grub.cfg

  • Locating rmmod tpm tn the alternate location, inside the menuentry, will give the warning error: no such module when booting in BIOS mode, see post 60 bug report https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1851311

mkusb USB-pack-EFI replaces rmmod tpm with:

grub_platform
if test "$grub_platform" = "efi"; then
        rmmod tpm
fi

So that rmmod tpm is only run on UEFI boots.


Thanks to @C.S.Cameron for the fix! Here's my final /etc/grub.d/40-custom file.

  • added rmmod tpm (See https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1851311)

  • changed set root= to hd0<->hd1 depending on if an external USB disk was connected or not


#!/bin/sh
exec tail -n +4 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
# Full Circle #157, page 61
menuentry "Ubuntu 20.04 Desktop ISO (external hd0 disk)" {
        insmod part_gpt
        insmod ext2
        rmmod tpm
        set root=(hd0,gpt1)
        set isofile="/ubuntu-20.04-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet splash
        initrd (loop)/casper/initrd
}
menuentry "Ubuntu 20.04 Desktop ISO (internal hd0 only)" {
        insmod part_gpt
        insmod ext2
        rmmod tpm
        set root=(hd0,gpt7)
        set isofile="/home/redacted/Documents/Disk_images/Ubuntu/ubuntu-20.04-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet splash
        initrd (loop)/casper/initrd
}