Hits : 4839


libvirt : The virtualization API



virsh --version=long

virsh -c qemu:///system
#virsh list

virsh -c qemu:///system start archlinux
virsh -c qemu:///system shutdown archlinux


snapshot & restore


virsh # snapshot-create archlinux
Domain snapshot 1315923139 created
 
virsh # snapshot-create archlinux
Domain snapshot 1315923216 created
 
virsh # snapshot-list archlinux
 Name                 Creation Time             State
---------------------------------------------------
 1315923139           2011-09-13 17:12:19 +0300 running
 1315923216           2011-09-13 17:13:36 +0300 running
 
virsh # snapshot-revert archlinux 1315923139 
 
virsh # snapshot-list archlinux
 Name                 Creation Time             State
---------------------------------------------------
 1315923139           2011-09-13 17:12:19 +0300 running
 1315923216           2011-09-13 17:13:36 +0300 running
 
virsh # snapshot-revert archlinux 1315923216
 
virsh # snapshot-list archlinux
 Name                 Creation Time             State
---------------------------------------------------
 1315923139           2011-09-13 17:12:19 +0300 running
 1315923216           2011-09-13 17:13:36 +0300 running
 
virsh # snapshot-delete archlinux 1315923216 
Domain snapshot 1315923216 deleted
 
virsh # snapshot-delete archlinux 1315923139
Domain snapshot 1315923139 deleted
 
virsh # snapshot-create-as archlinux archlinux_20110913_1742
Domain snapshot archlinux_20110913_1742 created
 
virsh # snapshot-list archlinux
 Name                 Creation Time             State
---------------------------------------------------
 archlinux_20110913_1742 2011-09-13 17:42:48 +0300 running

virsh connect


virsh -c qemu:///system list --all

or via ssh

virsh -c qemu+ssh://example.com/system list --all


Problem on client:


error: End of file while reading data: sh: nc.openbsd: command not found: Input/output error


Solution on server:


# ln -s /usr/bin/nc /usr/bin/nc.openbsd


top


virt-install


eg.


#!/bin/sh

virt-install \
        --connect=qemu+ssh://ebal@example.com/system \
        -n archlinux \
        -r 512 \
        -d \
        --description='Arch Linux, a lightweight and flexible Linux' \
        --os-type=linux \
        --boot menu=on \
        --disk path=/var/lib/libvirt/images/archlinux.qcow2,size=8 \
        -c /var/lib/libvirt/isos/archlinux-2011.08.19-core-dual.iso \
        --livecd \
        --graphics vnc,listen=10.10.10.1,port=5902


top


libvirtd PolicyKit


/etc/polkit-1/localauthority/50-local.d/libvirtd.pkla


[Local access to libvirtd to group: kvm]
Identity = unix-group:kvm
Action = org.libvirt.unix.manage
ResultAny = yes
ResultInactive = yes
ResultActive = yes


top



libvirt capabilities


# virsh capabilities


top



interfaces


virsh iface-list
virsh iface-undefine em1
virsh iface-destroy em1

top


auth


unix_sock_group = "kvm"
unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"
unix_sock_dir = "/var/run/libvirt"
auth_unix_ro = "none"
auth_unix_rw = "none"


top



domstate


$ sudo virsh domstate winxp
running

$ sudo virsh domstate f17
shut off