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 firstAny ideas on how to make this work?
133 Answers
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
hdXis the disk andYis 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
Persistentto the GRUB menuentry, (via/etc/grub.d/40-custom).If using a persistent partition make it ext4 and label it
casper-rwfor 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-rwfile 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 tpmto/boot/grub/grub.cfgjust 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.
toramoption may be used to boot to RAM for high speed on computers with lots of RAM, but takes longer to boot.fsck.mode=skipoption stops Filesystem Checking.The Language/Try/Install screen can be eliminated by removing
maybe-ubiquityfrom grub.cfgLocating
rmmod tpmtn the alternate location, inside the menuentry, will give the warningerror: no such modulewhen booting in BIOS mode, see post 60 bug report
mkusb USB-pack-EFI replaces rmmod tpm with:
grub_platform
if test "$grub_platform" = "efi"; then rmmod tpm
fiSo 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 )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
} 5 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
sudo umount -lrf /isodeviceSo 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
mount
sudo umount /target/boot/efi
sudo mount /dev/sdc1 /target/boot/efiMy 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