4

I have created a VM withLibvirt and when I shut it down whether forcefully or with ACPI, it gets deleted. I create it:

<domain type='kvm'>
    <name>deneme2</name>
    <memory>2097152</memory>
    <vcpu>1</vcpu>
    <os>
        <type>hvm</type>
        <boot dev="hd" />
    </os>
    <features>
       <acpi/>
    </features>
    <on_poweroff>preserve</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <on_lockfailure>poweroff</on_lockfailure>
    <devices>
        <graphics type='vnc' port='-1'/>
        <disk type='file' device='disk'>
            <driver name='qemu' type='qcow2'/>
            <source file='/home/mustafa/buki/vms/deneme2/disk0.img'/>
            <target dev='vda' bus='virtio'/>
        </disk>
        <disk type='file' device='disk'>
            <source file='/home/mustafa/buki/vms/deneme2/cloud-init.img'/>
            <target dev='vdb' bus="virtio"/>
        </disk>
        <interface type='network'>
            <source network='br0-bridge'/>
            <mac address='00:16:3e:5a:41:9c'/>
            <model type="virtio" />
        </interface>

    </devices>

However although I use on_poweroff event properly, it gets deleted immediately.

$ virsh dumpxml deneme2 | grep "on_poweroff"
  <on_poweroff>preserve</on_poweroff>

$ virsh shutdown deneme2 --mode acpi
Domain deneme2 is being shutdown

$ virsh list --all
 Id    Name                           State
----------------------------------------------------

What is the reason of this?

Mustafa
  • 195
  • 2
  • 9

1 Answers1

12

You created your guest with virsh create (or its equivalent). This creates transient domains, which are deleted when they power off.

To create persistent domains, use virsh define instead. These remain defined after they are powered off or destroyed, and can be started again at any time.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • 1
    Perhaps mention `preserve` does not do what one might assume. – h0tw1r3 Dec 10 '15 at 14:32
  • 1
    You are right, I am using a libvirt go library I had used `DomainCreateXML`instead of `DomainDefineXML` , much appreciated. @h0tw1r3 what does preserve does than? – Mustafa Dec 10 '15 at 14:34
  • I have no idea what `preserve` is supposed to preserve. It's not very well documented. And it's not necessary for normal operation anyway. – Michael Hampton Dec 10 '15 at 14:35
  • AFAIK `preserve` is automatically translated to `destroy` for qemu, but with other hypervisors it will save the VM resources (all it's memory, hardware state, etc). Useful for low level debugging. – h0tw1r3 Dec 10 '15 at 14:43