macosvm icon indicating copy to clipboard operation
macosvm copied to clipboard

Feature Request: Support multiple automount volumes

Open aaronclarke opened this issue 2 years ago • 0 comments

The virtualization framework supports having multiple automounted volumes with different readonly vs readwrite statuses, as can be seen described in Apple's documentation for VZVirtioFileSystemDeviceConfiguration

But the current support for --vol only allows for one automounted volume. If two are specified, an error is thrown due to reusing the same VZVirtioFileSystemDeviceConfiguration.macOSGuestAutomountTag tag.

I see that there is a method already in macosvm called addAutomountDirectoryShares:readOnly: which does know how to share describe multiple automounted directories, but it forces them all to have the same value for readOnly, and the code is currently unreachable.

Motivating example:

I want to start my VM with two automounted directories, one that is readonly so that the guest VM can't ruin it, and one that has readwrite capabilities so that the guest VM can write some data back to the host.

~/Desktop/macosvm -g \
--vol ~/Desktop/sharedWithVM/fromHost,ro,automount \
--vol ~/Desktop/sharedWithVM/fromGuest,automount \
macos_14.1/vm.json

Potential implementation:

I've got a working implementation of this in my fork: aaronclarke:feature/multiple_automount

There I've hacked this together by making macosvm loop over the shares twice:

  1. Loop one: Loop over all shares
    • if share is an automount share and automounting is available, add it to a list of automount shares and continue
    • otherwise do normal share specifications
  2. Loop two:
    • Loop over all discovered automount shares. Batch each directory together into a single VZMultipleDirectoryShare and set that as the share for VZVirtioFileSystemDeviceConfiguration with the VZVirtioFileSystemDeviceConfiguration.macOSGuestAutomountTag tag.

If that seems acceptable I could send a pull request.

aaronclarke avatar Oct 28 '23 00:10 aaronclarke