macosvm icon indicating copy to clipboard operation
macosvm copied to clipboard

Clone VM with a different serial number?

Open maximvelichko opened this issue 1 year ago • 4 comments

I would like to clone an existing VM with a different serial number. Is there any trick to achieve it? It looks like Apple's virtualization API does not support it. Yet, if I --restore a VM from an .ipsw, I get a new random (?) serial number every time. (Random, or not, that's exactly what I need!)

However, I don't want to go through the same setup and provisioning steps again every time. Is there any trick to clone a VM and force a serial number to get regenerated (randomly, or explicitly, either it will work for me)

maximvelichko avatar Sep 10 '24 05:09 maximvelichko

Sadly, this is not officially possible and I'm not aware of any tricks. Presumably, it would involve making modifications to both the aux and system volumes, but someone would have to see how exactly is the serial number kept in sync between the two. Some people tried, but I am yet to see a solution that would allow it to be modified. I'll keep this open, so if anyone sees a solution, feel free to post it here.

(FWIW I have never had real issues with running clones of the same VM - the only observable behavior is that cloned VMs are indistinguishable on the network where protocols are Apple-specific and rely on UUIDs, e.g., in Bonjour etc. - the "undefined behavior" is that they show up as one on the outside, but I never had issues using them as build VMs, but your mileage may vary)

s-u avatar Mar 18 '25 01:03 s-u

Thank you, @s-u !

I tried to find it but could not. I thought that Parallels lets you assigning an arbitrary serial number, though it looks like it's not supported for ARM machines (i.e. the same restriction).

I am looking to assign random hardware UUID to cloned machines. To allow them enrolling into MDM. To install configuration profiles, which is the only option to automate certain things (like PPPC, Full Disk Access for applications, system extensions etc. etc.) these days. Right now the only option I can see is to run setup one time per machine (i.e. go through the setup wizard which is boring and error prone :-)), then clone each of the VMs and use it to spawn a clean VM when I need it. I.e. 3 VMs means three times running the wizard (an when Apple releases a new macOS, I must update each of them separately). Not impossible, though I hoped to automate it somehow.

maximvelichko avatar Mar 18 '25 04:03 maximvelichko

@maximvelichko This is a bit OT, but you can skip the wizard if you just touch /var/db/.AppleSetupDone (and possibly also .AppleDiagnosticsSetupDone). Similarly, you can skip user setup if you just copy over the user plist into /var/db/dslocal/nodes/Default/users/ (or use dscl on the Default node; you may also want to do the same to the admin group if you want the user to have sudo). Note that on the boot disk the /var tree is in the Data volume under /private and you can mount the whole image with diskutil. (I didn't actually try this on a VM so you mileage may vary). You still need to do the restore part, so it doesn't save that much time, but it allows you to pretty much script the whole setup.

s-u avatar Mar 18 '25 05:03 s-u

Oh, and for the user, there is also ~/Library/Preferences/com.apple.SetupAssistant.plist with the personal preferences if you want to avoid questions on the first login.

s-u avatar Mar 18 '25 05:03 s-u