I created a multi-boot USB stick to load various ISO files, which can either be live systems or used to install different Linux distributions.
sda -sda1 1M | BIOS Boot partition to store MBR -sda2 64M | ESP for UEFI boot -sda3 100G | EXT4 for ISO & IMAGE I can easily start ISO files such as Debian, Ubuntu, Kali or other distributions from it, using the corresponding menuentry in the
/efi/boot/grub/grub.cfg
Now I have an disk-image created with dd from a whole USB stick where Debian is installed.
However, it's not a true ISO or image but rather a disk-image (snapshot/backup) of the USB stick with all its partitions, with the named example debian1.iso or debian2.img
I've now copied this file to the partition sda3 with the other correct ISO's.
I created the following menuentry with chainloader, but on the first attempt, GRUB simply restarts the boot process, and on the second attempt, I get an 'invalid signature' error.
menuentry "Chainload GRUB from USB Image debian1.iso" { loopback loop (hd0,3)/debian1.iso set root=(loop,1) chainloader +1 } menuentry "Boot Debian from ISO on USB (UEFI)" { set root=(hd0,3) loopback loop /debian2.img set root=(loop,1) chainloader /EFI/debian/grubx64.efi } How can I start this disk-image from GRUB and what does the menu entry look like?
It might be possible if the disk-image is written to a separate partition, but I don’t want that.
Here are entries I found, but they mostly deal with ISO files.
Using a bootable live cd disk image mounted on the hard drive
how to chainload from image file which contain multiple partitions?
How to boot Linux from image on disk or "Poor Man's Install"?
MEMDISK can boot floppy images, hard disk images and some ISO images.
At first, I found that it wasn’t possible, but then I discovered that it might be possible with memdisk or GRUB2 using loopback and overlayfs.
So, it is indeed possible.
Memdisk
Memdiskis primarily intended fortemporary boot environments, such as starting installation programs or diagnostic tools where permanent storage is not required or desired.
It is very useful if you just want to test the disk image.
loopback and overlayfs
You can boot a disk image with
GRUB’sloopbackfunction and make the filesystem writable by combining it withoverlayfs. An overlay layer is placed on top of the read-only image, writing changes to a separate partition or file. This way, the original image remains unchanged, and you can save modifications.
I need to figure out how to handle the changes if it works.
My GRUB is installed on a USB stick without an operating system, so I can't use grub-mkconfig.
So I have to make all the changes manually.
Is it possible to boot a disk-image via GRUB that is writable, make changes, and have those changes written directly to the image and how?
Is there another way besides memdisk to boot where I can make changes?
If it works with loopback and overlayfs, what do I need to consider, how do I set it up, and what does the menuentry looks like?
Is there some kind of small hack, or should I load additional files onto the GRUB stick to make this work and how?
The disk image itself also has GRUB, and the operating system on it is encrypted with LUKS.
Is it maybe possible to unpack the image into memory with GRUB, call GRUB from the disk image, unlock LUKS, boot the OS, make the changes, and save the whole thing as a new disk image to some partition?
initrdin the disk image. I don't know if it can work with LUKS encrypted filesystems, I have no knowledge of disk encryption. If you are interested, I can post the method in an answer.