[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt-users] Virtual machine removal through command line.

On 18.12.2014 23:35, Le Bris Gilles wrote:

Until today, I hadn't found a way to cleanly remove a KVM virtual
machine through command line on CentOS 6 or 7! I had to run 'systemctl
restart libvirtd' or 'service libvirtd restart'

After several months (!!!), I found this thread:

Now, I know how to cleanly remove a KVM virtual machine (with default
file location):
virsh destroy vm.example.com <http://vm.example.com>
virsh undefine vm.example.com <http://vm.example.com> --managed-save
/bin/rm /var/lib/libvirt/images/vm.example.com.img
/bin/rm /var/log/libvirt/qemu/vm.example.com.log
virsh vol-delete /var/lib/libvirt/images/vm.example.com.img --pool default

I don't know if the last command ('virsh vol-delete' avoiding the
libvirtd restart) is a bug or a feature but it must be documented! Only
a libvirt developer can guess something like this.

Well, there are basically two ways how to provide a diskt to a VM. The first one is to provide a path to the file directly, the other is to provide a volume and pool names. It's documented here:


There are plenty of examples, like:

    <disk type='volume' device='disk'>
      <driver name='qemu' type='raw'/>
      <source pool='blk-pool0' volume='blk-pool0-vol0'/>
      <target dev='hdk' bus='ide'/>

Then, when undefying a domain, you can certainly do 'vol-delete'. It comes natural if you have it that way.

What's interesting here though, is that restarting the daemon makes VMs go away. Although, since you have to pass '--managed-save' to the 'undefine' command, I guess the libvirt-guests.service is configure to managed save you guests. So they are not really gone, rather than saved on your disk:

# virsh list --all
 Id    Name                           State
 -     dummy                          shut off
 -     fedora                         shut off
 -     fedora21                       shut off
 -     freebsd                        shut off
 -     gentoo                         shut off
 -     migt10                         shut off
 -     rhel7                          shut off
 -     win7                           shut off


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]