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'>
        <boot dev="hd" />
        <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 type='file' device='disk'>
            <source file='/home/mustafa/buki/vms/deneme2/cloud-init.img'/>
            <target dev='vdb' bus="virtio"/>
        <interface type='network'>
            <source network='br0-bridge'/>
            <mac address='00:16:3e:5a:41:9c'/>
            <model type="virtio" />


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

$ virsh dumpxml deneme2 | grep "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.