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?

  • virt-install is just another Python program. Have you considered reading it to see what it is doing? – Michael Hampton Jan 27 '16 at 16:41
  • Thanks for the reply, I think I have found a solution though, where I would just clone the storage volume of a base image and use that as the disk for the new domain. That should work hopefully... – brti Jan 28 '16 at 11:27

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.