Qemu Monitor interface

 

 

目錄

 

 


Guest 有什麼 USB Port:

qm> info usb

  Device 0.1, Port 6, Speed 12 Mb/s, Product QEMU USB Tablet
  Device 0.0, Port 1, Speed 1.5 Mb/s, Product USB Host Device

Host 有什麼:

qm> info usbhost

  Bus 1, Addr 2, Port 1, Speed 480 Mb/s
    Hub: USB device 8087:0024
  Bus 2, Addr 2, Port 1, Speed 480 Mb/s
    Hub: USB device 8087:0024
  Auto filters:
    Bus *, Addr *, Port *, ID 0471:485d

usb_add device -- add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')

qm> usb_add host:2.8

usb_del device -- remove USB device 'bus.addr'

 

 


virsh qemu-monitor-command

 

Help:

qemu-monitor-command Domain_Name --hmp help

acl_add aclname match allow|deny [index] -- add a match rule to the access control list
acl_policy aclname allow|deny -- set default access control list policy
acl_remove aclname match -- remove a match rule from the access control list
acl_reset aclname -- reset the access control list
acl_show aclname -- list rules in the access control list
balloon target -- request VM to change its memory allocation (in MB)
block_passwd block_passwd device password -- set the password of encrypted block devices
block_resize device size -- resize a block image
..................................................

qemu-monitor-command VM-NAME --hmp help info

info

# 查看 info 支援什麼 cmd

qemu-monitor-command Domain_Name --hmp info

info balloon  -- show balloon information
info block  -- show the block devices
info blockstats  -- show block device statistics
info capture  -- show capture information
info chardev  -- show the character devices
info cpus  -- show infos for each CPU
...........................

virsh # qemu-monitor-command c6a --hmp info balloon

balloon: actual=512

看 verson

virsh # qemu-monitor-command <domain> --hmp info version

3.1.0Debian 1:3.1+dfsg-8+deb10u8

看 VNC INFO

virsh # qemu-monitor-command <domain> --hmp info vnc

Server:
     address: 0.0.0.0:5965
        auth: none
Client:
     address: 192.168.123.21:2698
  x509_dname: none
    username: none

qemu-monitor-command rocky8 --hmp info block

drive-virtio-disk0 (#block178): /mnt/raid/rockylinux/rocky8.qcow2 (qcow2)
    Attached to:      /machine/peripheral/virtio-disk0/virtio-backend
    Cache mode:       writeback

drive-virtio-disk1 (#block328): /mnt/raid/rockylinux/data.raw (raw)
    Attached to:      /machine/peripheral/virtio-disk1/virtio-backend
    Cache mode:       writeback

qemu-monitor-command rocky8 --hmp info blockstats

drive-virtio-disk0: 
 rd_bytes=441516544 wr_bytes=1294465024 
 rd_operations=19394 wr_operations=3040 flush_operations=698 
 wr_total_time_ns=10055376778 rd_total_time_ns=8325926809 flush_total_time_ns=33380182892 
 rd_merged=62 wr_merged=888 idle_time_ns=24824672968

 


change

 

如何 change

行 ps aux | grep kvm 會見到

/usr/bin/kvm ............-vnc 192.168.123.10:31,password ..........

那 change 的方法就是

emu-monitor-command <domain> --hmp change  vnc :65

emu-monitor-command <domain> --hmp change  vnc  password your_new_pw

 


USB

usb_add

usb_add disk:/tmp/disk.usb

info usb

eject

usb_del

usb_del 0.2

 


Network

 

set_link name on|off -- change the link status of a network adapter

 

 


VNC

 

set_password protocol password                                                   # protocol: spice/vnc

 


Replace Disk

 

Verifying Guest Suppor

grep CONFIG_HOTPLUG /boot/config-*

CONFIG_HOTPLUG_PCI=y
CONFIG_HOTPLUG_PCI_ACPI=y

查看要 replace 的目標

virsh # qemu-monitor-command rocky8 --hmp info block

drive-scsi0-0-0-2 (#block787): nbd://127.0.0.1:10810 (raw)
    Attached to:      scsi0-0-0-2
    Cache mode:       writeback

drive_del vs device_del

drive_del

Close out the host-side resource and prevent any further IO to the device

The result is that guest generated IO is no longer submitted against the host device underlying the disk.

drive_del should be used in the case that a device_del doesn't complete successfully.

device_del

中斷 Guset 與 Device 的連接

Diagram

Host (Drive)--(Device) Guest

i.e.

virsh qemu-monitor-command rocky8 --hmp info block

...

drive-scsi0-0-0-2 (#block1759): /mnt/raid/rockylinux/data2.raw (raw)
    Attached to:      scsi0-0-0-2
    Cache mode:       writeback

Remark: 這裡的 "drive-scsi0-0-0-2" 是 CLI 時用到的 id, 只要對應就 ok

virsh qemu-monitor-command rocky8 --hmp device_del scsi0-0-0-2

virsh qemu-monitor-command rocky8 --hmp info block

# scsi0-0-0-2 完全不見了

P.S.

如果使用 drive_del 先

virsh qemu-monitor-command rocky8 --hmp drive_del drive-scsi0-0-0-2

virsh qemu-monitor-command rocky8 --hmp info block

scsi0-0-0-2: [not inserted]
    Attached to:      scsi0-0-0-2

Plug

Check Device Current Parameter

ps aux | grep qemu-system-x86_64

...
-drive file=nbd:127.0.0.1:10810,format=raw,if=none,id=drive-scsi0-0-0-2 \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=2,drive=drive-scsi0-0-0-2,id=scsi0-0-0-2,logical_block_size=4096,physical_block_size=4096

P.S.

'id' parameters is required when adding devices and drive objects so that they can be referenced when deleting them.

"if=none"          # which allows qemu to use this drive with any guest visible device.

check block size

drive_add

# drive_add         # define a block driver in qemu like -device on the command line

drive_add slot ...  # add drive to PCI storage controller, 一般 slot 都係 0

virsh qemu-monitor-command rocky8 --hmp drive_add 0 file=nbd:127.0.0.1:10810,format=raw,if=none,id=drive-scsi0-0-0-2

virsh qemu-monitor-command rocky8 --hmp info block

drive-scsi0-0-0-2 (#block1101): nbd://127.0.0.1:10810 (raw)
    Removable device: not locked, tray closed
    Cache mode:       writeback

device_add

Once you've defined an a new 'drive' object, to make it visible to the guest it needs to be connected to a device.

device 會是 virtio-blk-pci / scsi-disk

Help: virsh qemu-monitor-command rocky8 --hmp device_add ?

virsh qemu-monitor-command rocky8 --hmp device_add scsi-hd,?

virsh # qemu-monitor-command rocky8 --hmp device_add scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=2,drive=drive-scsi0-0-0-2,id=scsi0-0-0-2,logical_block_size=4096,physical_block_size=4096

這裡的 "id" 用於 "Attached to: scsi0-0-0-2"(--hmp info block) device_del 時要用到

scsi-hd

  • bus=                       # 非必要
  • channel=                 # 非必要
  • scsi-id=                   # 非必要
  • lun=                       # 非必要
  • drive=<str>            # 必要, Node name or ID of a block device to use as a backend

virsh qemu-monitor-command rocky8 --hmp info block

  • Controller/Bridge/Hub devices
  • USB devices
  • Storage devices (scsi-hd = "virtual SCSI disk")
  • Network devices
  • Input devices
  • CPU devices
  • ...
drive-scsi0-0-0-2 (#block1149): nbd://127.0.0.1:10810 (raw)
    Attached to:      scsi0-0-0-2
    Cache mode:       writeback

Remark: file

id="drive-scsi0-0-0-2"

virsh qemu-monitor-command rocky8  --hmp drive_add 0 \
  file=/mnt/raid/rockylinux/data2.raw,format=raw,if=none,id=$id

block_size="logical_block_size=4096,physical_block_size=4096"

# virsh qemu-monitor-command rocky8 --hmp device_add scsi-hd,drive=${id},id=scsi0-0-0-2,${block_size}

virsh qemu-monitor-command rocky8 --hmp device_add \
scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=2,drive=${id},id=scsi0-0-0-2,${block_size}

virsh qemu-monitor-command rocky8 --hmp info block

Guest(VM)

當 disk offline 後

echo offline > /sys/block/sda/device/state

echo 1 > /sys/block/sda/device/delete

當 disk online 了

echo "- - -" > /sys/class/scsi_host/host0/scan

Remark

ls -l /sys/class/scsi_host

lrwxrwxrwx. 1 root root 0 Jan  6 17:22 host0 -> ../../devices/pci0000:00/0000:00:06.0/virtio3/host0/scsi_host/host0
lrwxrwxrwx. 1 root root 0 Jan  6 17:22 host1 -> ../../devices/pci0000:00/0000:00:01.1/ata1/host1/scsi_host/host1

 


Doc

 

http://en.wikibooks.org/wiki/QEMU/Monitor