3

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?

brti
  • 31
  • 1
  • 3
  • 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

1 Answers1

3

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.

MadHatter
  • 78,442
  • 20
  • 178
  • 229
Ahmed
  • 411
  • 4
  • 5