On Thu, Aug 01, 2019 at 10:12:15AM +0200, Jan Horak wrote:
Hi all,

i created a script in PHP for create a virtual server with two QCOW2 discs … 
one is our system for installation and second is target system.

After successfully instalation (create a blank Debian system, prepare all files 
and grub partitions) i need a restart virtual without a installation disk.

If i use Virsh:

detach-disk --domain debian-test2 --persistent --target vda
reset debian-test2


Hi,

I cannot really help you with the PHP part and I'm not sure about more things,
but this particular scenario is something that libvirt is actually prepared to
do (kind of) and for example virt-install uses it.  The approach is as follows:

1) You create the XML that you want the VM to have when installing the machine,
  let's call it the "install xml".

2) You create the XML that the VM should start with when it is already installed
  and it is the one that will persist in the libvirt configuration for long
  time (well, longer than the install xml).  Let's call this the "persistent 
xml".

3) You define the VM using the persistent xml.  That will get you a VM that is
  not started.

4) Then, you start the machine with the install xml, using the create API
  (analogous to virsh create vm.xml).  Just make sure the name and UUID are the
  same.

That will get you a VM running with the install xml that, when turned off and
then started again (without reboot/reset/restart, you need to have it shut down
completely before starting it) will start with the persistent xml.  No need to
have support for disk hot-(un)plug, no magic.

Even better way to use this is registering a callback for the VM's lifecycle
event, starting the VM after the event was fired.  That way you can automate the
installation to turn off the machine after it is completed and there is no need
for any polling.  I'm not sure, however, how relevant that is or if it is
possible to be used from the PHP bindings.

Have a nice day,
Martin

Attachment: signature.asc
Description: PGP signature

_______________________________________________
libvirt-users mailing list
libvirt-users@redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-users

Reply via email to