Parallels / vagrant-parallels

Vagrant Parallels Provider
https://parallels.github.io/vagrant-parallels
MIT License
996 stars 87 forks source link

use clonefile copy for macvm boxes #459

Closed mattlqx closed 1 year ago

mattlqx commented 1 year ago

Vagrant uses prlctl clone to make a copy of the stored box when up'ing a VM. On Intel, this can be a linked clone, but on ARM, this is not an option with Apple's MacVMs. As such, Parallels does a full traditional copy of the box files into a new location that is then registered resulting in the requirement of 2(box size) space. Since MacVMs can be quite large (in our case 30-40GB after all our preparation and additional software), this can quickly run a laptop out of space with just a VM or two. (There's other factors here as well, like APFS snapshots if you're running Time Machine which will hold on to space after you've destroyed VMs.)

APFS supports the clonefile(2) call which creates a copy-on-write clone of the file meaning it's effectively a quick and free operation to fork a copy of a file. Subsequent writes to the clone are where additional bytes begin to be required. In our testing, this has been a huge time and space saver to do a clone copy of the MacVM and register it into Parallels.

I believe the best option is for Parallels to natively implement this when calling prlctl clone on APFS but considering that's a bigger ask and closed-source, I've created these modifications to the vagrant-parallels plugin to orchestrate it as a workaround until proper support can be added to Parallels.