Return to

How to setup image-based duel boot? as opposed to partition based

i have a Linux system (that currently boots via EFISTUB). i want to install a second operating system but not add any storage devices or repartition my existing setup.

is there a way i can have an img file that contains the entire partition table and filesystem for a second OS, and then boot the machine from it? I’m not talking about a RAMdisk like live session images use. i want to actually make changes while the OS inside the img is booted, and have those changes actually write to the image.

i know some motherboard firmwares can emulate a block device from an image file. unfortunately mine is not one of them.

ideally, i want to pick whether to boot my Linux system or my img file by selecting different .efi files for my motherboard to load. if that’s not feasible, i have grub2 installed if there’s a way to accomplish my goal with that.

1 Like

The Windows bootloader can boot a VHD/VHDX file. I believe that it has to be stored on a NTFS though.

For Linux the only way I know of to do it would be to first boot a kernel and initramfs image with support for the filesystem storing the IMG and whatever image format you used (RAW is an option but still). Then it could start a QEMU KVM on the image. Or I suppose the boot script in initramfs could loop-mount the root before doing the root-switch, and then no VM is involved. That gets tricky with the /etc/fstab references inside the loop image though since I don’t know if the system will search the image for other block device UUIDs. I don’t think it will.

Sorry, I am not sure any of that will help.

i could just have an initramfs loop-mount the image, but that would make update scripts for the OS inside the image absurdly complex. i would prefer for the image to contain its own everything such that the nested OS can be 100% independent of the greater filesystem the img is stored on.

in other words, i want the img to use its own bootloader partition and root partition. i believe i need something like losetup but somehow do it on the bootloader/firmware level.

is there some grub2 script i can make to accomplish this?
if i can just load a guest’s kernel and initramfs from inside the img file, i should be able to have the guest kernel loop-mount its img file and then load the fstab. this wont select based on .efi files though.

1 Like