I have a existing VM I am very happy with the hardware config for, but I would like to clone the XML and generate a new UUID for a separate VM without using virt-manager, as the virt-manager VM duplication feature is quite lacking and could clone some elements of the XML incorrectly.
Simply having an identical clone is not ideal, for when you do virsh define, the identical UUID screws everything up.
What are your best practices for keeping the hardware config of your XML and generating a new unique UUID with the least amount of hassle? Creating a new VM and copying and pasting seems like a roundabout way and requires more steps than simply a command to random seed a new UUID in the XML.
Next thing I’m worried about is NVRAM files and if virsh define makes those as well after deleting the entries, along with what virt-manager adds to the XML for specific OS preparations. It would be nice to have a cheat sheet for OS prep quirks rather than have it buried in virt-manager. Again, virt-manager’s VM cloning wizard can mess up duplicating the XML.
Depending on how much of the original VM you want to retain, invoking virt-clone with the appropriate parameters should do the trick
virt-clone is a command line tool for cloning existing virtual machine images using the libvirt hypervisor management library. It will copy the disk images of any existing virtual machine, and define a new guest with an identical virtual hardware configuration. Elements which require uniqueness will be updated to avoid a clash between old and new guests.
What I’m worried about is if virt-manager is just a frontend to that CLI. If it is, then they’re doing it wrong, and we need a cheat sheet for the correct way of doing it.
/usr/share/virt-manager/virt-manager is another Python script which initalises the interface and wires up UI elements to underlying logic. Logic for the ‘Clone Virtual Machine’ dialog (defined with some XML) is controlled by clone.py which, as we’d hoped, instantiates the same Cloner class as virt-clone.
Sounds like we’re getting into the weeds here. Anecdotally, I haven’t had any issues using virt-manager's clone functionality. Plus my quick dive into the code (primarily to sate my own curiosity) highlighted
cloning via virt-manager and virt-clone is handled the same way
there are unit tests in place that enforce expected behaviour
Either the way cloning behaves (through virt-manager or virt-clone) isn’t what you were expecting, or there’s a genuine bug in code. If there were more information to go on (XML dump, log files, screenshots, etc) no doubt someone here (or, better yet, the virt-manager issue tracker) could provide further assistance.
Without the specifics of your particular case, we’re at an impasse.