最後更新: 2019-10-08
介紹
安 agent 後有的好處(功能)
支援 virsh 的 shutdown / reboot
In virsh, users can select shutdown/reboot method via "--mode agent"
ie.
virsh reboot --mode agent $DOMAIN
virsh shutdown --mode agent $DOMAIN
freeze fs
在建立 snapshots 可以 freeze filesystems, 令獲得的 snapshot 完整
ie.
virsh snapshot-create --quiesce $DOMAIN
virsh snapshot-create-as --quiesce $DOMAIN
virsh blockcommit
# The contents of snap2 are moved into snap1, resulting in:
# base ← snap1 ← active, snap2 is no longer valid and can be deleted
i.e.
virsh blockcommit $dom $disk -base snap1 -top snap2 -wait -verbose
QEMU Guest Agent
[Step1] Host
QEMU exposes GA via virtio serial port
<devices>
...
<channel type='unix'>
<source mode='bind'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
</devices>
Save 後
<channel type='unix'> <target type='virtio' name='org.qemu.guest_agent.0'/> <address type='virtio-serial' controller='0' bus='0' port='1'/> </channel>
Checking: 當 Guest Start 後
Hypervisor 會有
ls -l /var/lib/libvirt/qemu/channel/target/domain-*/org.qemu.guest_agent.0
srwxrwxr-x 1 libvirt-qemu kvm 0 May 26 18:06
/var/lib/libvirt/qemu/channel/target/domain-ID-VM_NAME/org.qemu.guest_agent.0
...
Guest 會有
ls -l /dev/virtio-ports/org.qemu.guest_agent.0
lrwxrwxrwx 1 root root 11 May 26 10:06 /dev/virtio-ports/org.qemu.guest_agent.0 -> ../vport3p1
/etc/init.d/qemu-guest-agent
# default transport
TRANSPORT=virtio-serial:/dev/virtio-ports/org.qemu.guest_agent.0
P.S. virtio-serial
A transport mechanism is needed for communication between the host userspace and guest userspace
It has two parts:(Guest)
(a) device emulation in qemu that presents a virtio-pci device to the guest and
(b) a guest driver that presents a char device interface to userspace applications.
[Step2] Guest
Debian/Ubuntu
apt-get install qemu-guest-agent
Centos
yum install qemu-guest-agent
Notes
The QEMU guest agent package ( qemu-guest-agent ) is installed by default in Red Hat Enterprise Linux 7
Start & Enable Service
systemctl enable qemu-guest-agent --now
[Step3] Test qemu-guest-agent
domtime seafile
失敗
error: argument unsupported: QEMU guest agent is not configured
OR
error: Guest agent is not responding: Guest agent not available for now
成功
Time: 1552741916
P.S.
date
Friday, May 26, 2023 PM06:20:02 HKT
virsh domtime --pretty u22
# 這裡的時間係用 Guest 的時區
Time: 2023-05-26 10:20:02
Usage
domtime seafile
Time: 1514292860
沒有安 agent 時
error: Guest agent is not responding: QEMU guest agent is not connected
domfsinfo seafile
Mountpoint Name Type Target ------------------------------------------------------------------- / dm-0 xfs vda /boot vda1 xfs vda
set-user-password
set-user-password domain user password
fsfreeze
virsh domfsfreeze guestname
Freeze domain's mounted filesystems.
此時 VM 沒有了 Disk 的 R/W 能力
virsh domfsthaw guestname
Thaw mounted filesystems within a running domain, which have been frozen by domfsfreeze command.
用處: Backup running VM
virsh domfsfreeze vmname
qemu-img create -f qcow2 -b qcow2image.vm qcow2.snap
OR
cp qcow2.snap backup.img
Window 's GA
好處
# 分別: some guests ignore ACPI shutdown event
virsh shutdown --mode=agent GUEST
# 分別: snapshot without having to perform a fsck
virsh snapshot-create --quiesce GUEST
# 分別: using the guest operating system's power management functions.
virsh dompmsuspend GUEST
Intro:
http://www.linux-kvm.org/page/WindowsGuestDrivers
Binary Drivers:
https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
獲得
/mnt/tmp ├── amd64 │ ├── 2k8 │ ├── ... │ └── w8 ├── ARM64 │ └── w10 ├── Balloon │ ├── 2k12 │ ├── ... │ └── xp ├── guest-agent │ ├── qemu-ga-i386.msi │ └── qemu-ga-x86_64.msi ...
# Guest 的 XML
# Note that the source socket name must be unique in the host, 非切要 <channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/win7x86.agent'/> <target type='virtio' name='org.qemu.guest_agent.0'/> </channel>
# Guest 開機後
# 入 CD 安 virtio-serial driver
virsh attach-disk guest /home/iso/virtio-win.iso hdc --type cdrom
在 Control Panel > Hardware and Sound > Device manager > 安 vioserial
Install guest-agent/qemu-ga-i386.msi
Checking
# Power Shell
Get-Service QEMU-GA
Status Name DisplayName ------ ---- ----------- Running QEMU-GA QEMU Guest Agent