20.04 booting .iso from GRUB menu
Solution 1
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 andY
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
(orcasper-rw
) file up to 4GB and an optionalhome-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 warningerror: 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.
Solution 2
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
}
Solution 3
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?
Boris Hamanov
Former DEC Hardware Engineer, DEC Field Service Manager, and DEC VAX/VMS System Manager, but mostly a Computer Hardware Service Manager. Have worked for Digital Equipment Corporation, Computerland, Sony, Computerware, Executron Computers, CompUSA, and Apple Computer. Hardware, software, and management savvy.
Updated on September 18, 2022Comments
-
Boris Hamanov over 1 year
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
Any ideas on how to make this work?
-
Boris Hamanov almost 4 yearsThanks for all of the information! I'm still digesting it all.
-
WinEunuuchs2Unix almost 4 years
toram
option looks interesting as I just upgraded from 8G to 32G of RAM and would like that to pay dividends. -
ubfan1 almost 4 yearsIt 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.
-
Boris Hamanov almost 4 yearsThanks 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. -
Meninx - メネンックス almost 4 yearsI 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 concerningrmmod tpm
location. -
Meninx - メネンックス almost 4 yearsGood 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.
-
Boris Hamanov almost 4 years@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 theFirst Circle
article.hd0,gpt7
includes gpt to identify the disk partition/table type... vs msdos, or something else. -
Boris Hamanov almost 4 years@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? -
Boris Hamanov almost 4 years@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
, runfsck
. File system check from a Ubuntu Live DVD/USB only checks the DVD/USB, not the normally bootable SSD/HDD. -
Boris Hamanov almost 4 yearsre: "rmmod tpm # Alternate Location", in GRUB, comments with # must begin in column 1... so create two lines, the comment, and the rmmod.
-
Meninx - メネンックス almost 4 years@heynnema: Yes, of course, Please let me know if the edit is okay.
-
Boris Hamanov almost 4 years@C.S.Cameron Looks fine.
-
sudodus almost 4 years+1: So
umount /isodevice
works with the 'sledgehammer' options-lrf
:-) -
oldfred almost 4 yearsI 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.
-
Meninx - メネンックス almost 4 years
sudo umount -lrf /isodrive
did not work for me,sudo umount -lrf /isodevice
did work. When booting usingtoram
the file system check took three seconds, without toram it took over a minute.