Libvirt guest destroyed after shutdown

Mustafa asked:

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?

My answer:


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.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.