7

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?

13
  • The set root is not needed, and may be messing things up. If you got the disk/partition right looks OK otherwise.
    – ubfan1
    Jun 19, 2020 at 3:10
  • Ha, just tried this from UEFI -- black screen, no disk activity. Works fine in legacy mode. I'm switching my default boot to UEFI, so one more thing to add to my list to fix.
    – ubfan1
    Jun 19, 2020 at 3:35
  • @ubfan1 Thanks for the input. So at this point, am I to assume that there's no working solution for this idea?
    – heynnema
    Jun 19, 2020 at 3:44
  • 2
    20.04 has GRUB 2.04. 2.04 has problems with booting ISO files. Bug: bugs.launchpad.net/ubuntu/+source/grub2/+bug/1851311 A workaround is to add rmmod tpm anywhere above the first menuentry in grub.cfg. Alternately mkusb with #1 USB-Pack-EFI can be used to make a 20.04 USB that uses GRUB 2.02. Jun 19, 2020 at 5:34
  • 1
    @sudodus see posts 60 plus of the bug report. Jun 19, 2020 at 14:30

3 Answers 3

14

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.

8
  • Thanks for all of the information! I'm still digesting it all.
    – heynnema
    Jun 19, 2020 at 15:01
  • toram option looks interesting as I just upgraded from 8G to 32G of RAM and would like that to pay dividends. Jun 19, 2020 at 15:06
  • It would be good to add the bug references (rmmod tpm, and writeable) here too to explain the workarounds, instead of leaving them in the comments on the question.
    – ubfan1
    Jun 19, 2020 at 16:38
  • 1
    Thanks for the assist. The rmmod tpm worked, along with my understanding of how the disks get numbered hd0 <-> hd1. Please see my answer. I accepted your answer.
    – heynnema
    Jun 19, 2020 at 17:55
  • re: "rmmod tpm # Alternate Location", in GRUB, comments with # must begin in column 1... so create two lines, the comment, and the rmmod.
    – heynnema
    Jun 27, 2020 at 13:55
2

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


#!/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
}
5
  • I made a few trials with insmod part_gpt, insmod ext2 and without, could not notice any difference. Are they needed? Using (hdX,gptY) vs (hdX,Y) also did not do much. I edited my answer concerning rmmod tpm location. Jun 20, 2020 at 11:18
  • Good Idea having a menuentry to boot ISO's on USB's. I Will have to add one. I have a menuentry to boot Persistent USB's from internal grub. +1. Jun 20, 2020 at 11:30
  • @C.S.Cameron The whole reason that I wanted to boot the .iso is to be able to run fsck, as since 18.04 you can no longer do it when Recovery Mode booted on the primary SSD/HDD. insmod were included in the First Circle article. hd0,gpt7 includes gpt to identify the disk partition/table type... vs msdos, or something else.
    – heynnema
    Jun 20, 2020 at 14:46
  • @C.S.Cameron Entering fsck.mode=force would fsck on every boot, yes? I wouldn't want to give up my 15 second boot time for that. What is F6 for?
    – heynnema
    Jun 20, 2020 at 15:21
  • @C.S.Cameron Right now, I don't have to do any of those. I just boot to the external USB drive, directly from the GRUB menu, start terminal, run fsck. File system check from a Ubuntu Live DVD/USB only checks the DVD/USB, not the normally bootable SSD/HDD.
    – heynnema
    Jun 20, 2020 at 19:56
1

Similar to above. Hard drive boot has several issues.

I boot ISO from my hard drive or SSD. I typically have two drives & create a separate partition just for ISO. I then boot ISO from one drive to install into another drive.

I find I now have to add the rmmod tpm, but typically have to unmount the /isodrive and change mount of ESP so it does not overwrite my main working install.

2.04 Out of memory error loop mount

https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1851311

sudo umount -lrf /isodevice

So it does not overwrite my ESP, I unmount ESP while on the screen where we add name & password. I later have to edit fstab as it still has original ESP. I check mount, unmount ESP & mount another ESP like my sdb or an external flash drive.

Ubuntu Installer uses wrong bootloader location for USB/sdb UEFI installs

https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1173457

mount
sudo umount /target/boot/efi
sudo mount /dev/sdc1 /target/boot/efi

My ISO boot of Groovy, I now use labels so this is from the partition on my SSD and a test install of Groovy on sdb drive from sda:

menuentry "Ubuntu 20.10 Groovy amd64" {
    set isofile="/groovy-desktop-amd64.iso"
    insmod part_gpt
    rmmod tpm
    search --set=root --label iso_ssd --hint hd0,gpt5
    loopback loop (${root})$isofile 
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile toram
    initrd (loop)/casper/initrd
}

Similarly this is from partition on HDD. This was a new install for Focal to my SSD which now is my main working install. I still have 18.04 on SSD.

menuentry "Ubuntu 20.04 Focal amd64" {
    set isofile="/ubuntu-20.04-desktop-amd64.iso"
    insmod part_gpt
    rmmod tpm
    loopback loop (hd1,6)$isofile 
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile toram
    initrd (loop)/casper/initrd
}

Found using labels to mount drive, partition avoids the issue of drive changing if rebooting with another USB drive plugged in & drive changing from hd1 to hd2.

How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?

3
  • +1: So umount /isodevice works with the 'sledgehammer' options -lrf :-)
    – sudodus
    Jun 28, 2020 at 8:20
  • 1
    I have yet for it to let me install to sda as it has the /isodevice mounted on sda. And the option that pops up to offer to unmount partitions does not seem to unmount the isodevice. But if mounted it blocks install to sda. I do not think it is an issue installing to sdb or any other drive, but I typically unmount anyway. Not sure if related to having the toram parameter to have entire ISO in RAM.
    – oldfred
    Jun 28, 2020 at 15:06
  • sudo umount -lrf /isodrive did not work for me, sudo umount -lrf /isodevice did work. When booting using toram the file system check took three seconds, without toram it took over a minute. Jun 29, 2020 at 4:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .