lost and found ( for me ? )

Fedora 19 KVM : qemu-guest-agent

[ about qemu-guest-agent ]


qemu-guest-agent provides system-level operation between a KVM host and VMs.

[ install ]

KVM host
I have installed KVM related packages via virt-preview repository.
[root@localhost ~]# cat /etc/fedora-release ;uname -ri; qemu-system-x86_64 --version
Fedora release 19 (Schrödinger’s Cat)
3.10.6-200.fc19.x86_64 x86_64
QEMU emulator version 1.6.0, Copyright (c) 2003-2008 Fabrice Bellard

VM ( CentOS 6.4 64bit )
[root@localhost ~]# cat /etc/centos-release ;uname -ri
CentOS release 6.4 (Final)
2.6.32-358.14.1.el6.x86_64 x86_64

on the VM, install qemu-guest-agent
[root@localhost ~]# yum install qemu-guest-agent.x86_64 -y

[root@localhost ~]# rpm -ql `rpm -qa | grep qemu-guest`
/etc/rc.d/init.d/qemu-ga
/etc/sysconfig/qemu-ga
/usr/bin/qemu-ga

[root@localhost ~]# egrep -v ^# /etc/sysconfig/qemu-ga | grep -v ^$
TRANSPORT_METHOD="virtio-serial"
DEVPATH="/dev/virtio-ports/org.qemu.guest_agent.0"
LOGFILE="/var/log/qemu-ga.log"
PIDFILE="/var/run/qemu-ga.pid"
BLACKLIST_RPC="guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest-file-seek,guest-file-flush"

start qemu-qa on the VM.
can’t run..
[root@localhost ~]# /etc/init.d/qemu-ga start

[root@localhost ~]# /etc/init.d/qemu-ga status
qemu-ga is stopped

needs to create virtio serial port with special name org.qemu.guest_agent.0

shutdown the VM

on the KVM host
virsh # shutdown centos6-vm1
ドメイン centos6-vm1 はシャットダウン中です

create virtio serial for qemu-guest-agent.
virsh # edit centos6-vm1



add red lines between <devices> .. </devices>
virsh # dumpxml centos6-vm1
<domain type='kvm' id='6'>
 <name>centos6-vm1</name>
 <uuid>0c3d42a4-283f-cc47-0da4-8cedaaef93ec</uuid>
 <memory unit='KiB'>1048576</memory>
 <currentMemory unit='KiB'>1048576</currentMemory>
 <vcpu placement='static'>1</vcpu>
 <resource>
   <partition>/machine</partition>
 </resource>
 <os>
   <type arch='x86_64' machine='pc-i440fx-1.4'>hvm</type>
   <boot dev='hd'/>
 </os>
 <features>
   <acpi/>
   <apic/>
   <pae/>
 </features>
 <cpu mode='host-passthrough'>
 </cpu>
 <clock offset='utc'/>
 <on_poweroff>destroy</on_poweroff>
 <on_reboot>restart</on_reboot>
 <on_crash>restart</on_crash>
 <devices>
   <emulator>/usr/bin/qemu-kvm</emulator>
   <disk type='file' device='disk'>
     <driver name='qemu' type='qcow2'/>
     <source file='/var/disk1/KVM_Images/centos6-vm1.qcow2'/>
     <target dev='vda' bus='virtio'/>
     <alias name='virtio-disk0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
   </disk>
   <controller type='usb' index='0'>
     <alias name='usb0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
   </controller>
   <controller type='virtio-serial' index='0'>
     <alias name='virtio-serial0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
   </controller>
   <controller type='pci' index='0' model='pci-root'>
     <alias name='pci0'/>
   </controller>
   <interface type='network'>
     <mac address='52:54:00:74:71:61'/>
     <source network='network1'/>
     <target dev='vnet0'/>
     <model type='virtio'/>
     <alias name='net0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
   </interface>
   <serial type='pty'>
     <source path='/dev/pts/2'/>
     <target port='0'/>
     <alias name='serial0'/>
   </serial>
   <console type='pty' tty='/dev/pts/2'>
     <source path='/dev/pts/2'/>
     <target type='serial' port='0'/>
     <alias name='serial0'/>
   </console>
   <channel type='spicevmc'>
     <target type='virtio' name='com.redhat.spice.0'/>
     <alias name='channel0'/>
     <address type='virtio-serial' controller='0' bus='0' port='1'/>
   </channel>
   <channel type='unix'>
     <source mode='bind' path='/var/lib/libvirt/qemu/centos6-vm1.agent'/>
     <target type='virtio' name='org.qemu.guest_agent.0'/>
     <alias name='channel1'/>
     <address type='virtio-serial' controller='0' bus='0' port='2'/>
   </channel>
   <input type='tablet' bus='usb'>
     <alias name='input0'/>
   </input>
   <input type='mouse' bus='ps2'/>
   <graphics type='spice' port='5900' autoport='yes' listen='127.0.0.1' keymap='ja'>
     <listen type='address' address='127.0.0.1'/>
   </graphics>
   <video>
     <model type='qxl' ram='65536' vram='65536' heads='1'/>
     <alias name='video0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
   </video>
   <memballoon model='virtio'>
     <alias name='balloon0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
   </memballoon>
 </devices>
 <seclabel type='dynamic' model='selinux' relabel='yes'>
   <label>system_u:system_r:svirt_t:s0:c718,c938</label>
   <imagelabel>system_u:object_r:svirt_image_t:s0:c718,c938</imagelabel>
 </seclabel>
</domain>

virsh #

on the virt-manager ( KVM host)




start the VM
on the KVM host
# virsh start centos6-vm1

on the VM, start qemu-ga.
I was able to start qemu-ga.
[root@localhost ~]# /etc/init.d/qemu-ga start
qemu-ga を起動中:                                          [  OK  ]

[root@localhost ~]# /etc/init.d/qemu-ga status
qemu-ga (pid  1283) を実行中...

[root@localhost ~]# lsof -p 1283
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAME
qemu-ga 1283 root  cwd    DIR              253,0     4096      2 /
qemu-ga 1283 root  rtd    DIR              253,0     4096      2 /
qemu-ga 1283 root  txt    REG              253,0   141864 262824 /usr/bin/qemu-ga
qemu-ga 1283 root  mem    REG              253,0  1916568    290 /lib64/libc-2.12.so
qemu-ga 1283 root  mem    REG              253,0   936976    365 /lib64/libglib-2.0.so.0.2200.5
qemu-ga 1283 root  mem    REG              253,0   154504    281 /lib64/ld-2.12.so
qemu-ga 1283 root    0u   CHR                1,3      0t0   3656 /dev/null
qemu-ga 1283 root    1u   CHR                1,3      0t0   3656 /dev/null
qemu-ga 1283 root    2u   CHR                1,3      0t0   3656 /dev/null
qemu-ga 1283 root    3wW  REG              253,0        5 130661 /var/run/qemu-ga.pid
qemu-ga 1283 root    4w   REG              253,0        0 130662 /var/log/qemu-ga.log
qemu-ga 1283 root    5u   CHR              248,2      0t0   9646 /dev/vport0p2
qemu-ga 1283 root    6u  unix 0xffff88003dfab380      0t0  11614 socket



[root@localhost ~]# chkconfig --list qemu-ga
qemu-ga         0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@localhost ~]# chkconfig qemu-ga on

[root@localhost ~]# chkconfig --list qemu-ga
qemu-ga         0:off 1:off 2:on 3:on 4:on 5:on 6:off

[ sample usage ]

on the KVM host

get network info of the VM via virsh.
on the KVM host.
virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-network-get-interfaces"}'
{"return":[{"name":"lo","ip-addresses":[{"ip-address-type":"ipv4","ip-address":"127.0.0.1","prefix":8},{"ip-address-type":"ipv6","ip-address":"::1","prefix":128}],"hardware-address":"00:00:00:00:00:00"},{"name":"eth0","ip-addresses":[{"ip-address-type":"ipv4","ip-address":"192.168.100.176","prefix":24},{"ip-address-type":"ipv6","ip-address":"fe80::5054:ff:fe74:7161","prefix":64}],"hardware-address":"52:54:00:74:71:61"}]}


virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-info"}'
{"return":{"version":"1.0","supported_commands":[{"enabled":true,"name":"guest-network-get-interfaces"},{"enabled":true,"name":"guest-suspend-hybrid"},{"enabled":true,"name":"guest-suspend-ram"},{"enabled":true,"name":"guest-suspend-disk"},{"enabled":true,"name":"guest-fsfreeze-thaw"},{"enabled":true,"name":"guest-fsfreeze-freeze"},{"enabled":true,"name":"guest-fsfreeze-status"},{"enabled":false,"name":"guest-file-flush"},{"enabled":false,"name":"guest-file-seek"},{"enabled":false,"name":"guest-file-write"},{"enabled":false,"name":"guest-file-read"},{"enabled":false,"name":"guest-file-close"},{"enabled":false,"name":"guest-file-open"},{"enabled":true,"name":"guest-shutdown"},{"enabled":true,"name":"guest-info"},{"enabled":true,"name":"guest-ping"},{"enabled":true,"name":"guest-sync"},{"enabled":true,"name":"guest-sync-delimited"}]}}



shutdown the VM
on the KVM host
virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-shutdown"}'

logs on the VM
[root@localhost ~]# tail -f /var/log/qemu-ga.log



Broadcast message from root@localhost.localdomain
(unknown) at 21:43 ...

The system is going down for power off NOW!
hypervisor initiated shutdown




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.