Is there any way to boot MacOS from a DMG or raw disk image file and have it be writable?

I would like to set up a tripple boot system where each OS can either be booted separately or run as a virtual machine under the others, and it seems the best way to do this is to store each OS in a disk image file on a partition they all can access. This seems possible to do for Windows and Linux, since Windows can boot from a VHDX file on an NTFS partition, and Linux can boot from anywhere as long as you can create an initramfs that mounts the root filesystem, and there is a good NTFS driver in the kernel. I could even use my Linux image under WSL2 if I make it a VHDX file. You can also mount NTFS read write on MacOS, so it would be able to start Windows and Linux as virtual machines.

However, I am not sure if I can get MacOS to boot from a disk image. It seems that MacOS has a pivot_root system call, which is what is used on Linux to switch to the new root from the initramfs, but the process of verifying and mounting all the APFS volumes at the right places seems to happen in the MacOS kernel and not in userspace, and I'm not sure if it is specified in any kernel options or configuration files. Maybe it would be possible to create a small root partition that mounts all the volumes from the disk image in the right places and then calls pivot_root if I knew more about how to configure this. I think MacOS recovery can boot directly from a DMG, but then the filesystem is most likely read-only, and how this is configured doesn't seem to be documented anywhere.

Is there another way to do this or will I have to run MacOS from its own partition and try to pass it directly to QEMU as the disk image? Another reason why I would prefer to boot everything from disk images is so I don't have to worry about figuring out how much space I'm going to need on each OS and resizing and moving partitions if I need more space on one, since my laptop only has a 256 GB SSD.

submitted by /u/emassey0135
[link] [comments]