How to create a new domain from an existing base image in virsh

kvm-virtualizationlibvirtvirsh

Is there a way of creating a domain with virsh from a base image? I have looked around and found that it is possible using virt-install, however I would prefer it if this was done purely through virsh, as I am using libvirt language bindings just to make things easier.

I have thought of one way of doing it, which would involve dumping out the XML configuration into a temporary file, editing some of the settings, such as the name, memory, vcpus, and possibly the disk size. Then using that XML file to create the new image, would that be a feasible way of doing it?

Best Answer

You can copy the image file for any VM and clear the VM specific data (IP,...etc) using the command:

virt-sysprep -a <image_file>

Then use virt-install (in an example):

virt-install \
   -n vm_name \
   --connect=qemu:///system \
   --description "Any description" \
   --os-type=Linux \
   --ram=2048 \
   --vcpus=1 \
   --disk path=image_file,bus=virtio,size=12 \
   --graphics vnc \
   --network bridge=virbr0,model=virtio \
   --boot hd

Make sure that --boot hd is specified to let the VM boot from hard disk.

Related Topic