Update: New in libguestfs ≥ 1.13.19 is a tool to “sysprep” VMs. See the virt-sysprep manual page
Create new storage and copy the old VM. Because I’m using logical volumes, the size of the new LV must be exactly the same as the size of the old LV:
# lvcreate -L 10G -n FNew vg_host # dd if=/dev/vg_host/F14 of=/dev/vg_host/FNew bs=1M
Copy and modify the libvirt XML:
# virsh dumpxml F14 > /tmp/fnew.xml # emacs /tmp/fnew.xml
You need to change the following 4 fields in the XML:
<source dev='/dev/vg_host/...'> and
<mac address='...'>. For the UUID and MAC address, just randomly change the last few digits.
Define the new guest, but don’t boot it just yet:
# virsh define /tmp/fnew.xml Domain FNew defined from /tmp/fnew.xml
There are two files you need to edit inside the guest:
# guestfish -i -d FNew Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for a list of commands 'man' to read the manual 'quit' to quit the shell Operating system: Fedora release 14 (Laughlin) /dev/mapper/vg_f13x64-lv_root mounted on / /dev/vda1 mounted on /boot ><fs> edit /etc/sysconfig/network (change the hostname) ><fs> edit /etc/udev/rules.d/70-persistent-net.rules (change the MAC address to the same as the one in the libvirt XML file) ><fs> exit
Now you can go ahead and boot the new, cloned guest.
On the virt tools roadmap is a plan to refresh the old “virt-clone” tool to do all this properly and automatically.