Administrating Virtual Machines with QEMU Monitor

When QEMU is running, a monitor console is provided for performing interaction with the user. Using the commands available in the monitor console, it is possible to inspect the running operating system, change removable media, take screen shots or audio grabs and control several other aspects of the virtual machine.

Accessing Monitor Console

To access the monitor console from QEMU, press Ctrl+Alt+2. To return back to QEMU from the monitor console, press Ctrl+Alt+1.

To get help while using the console, use help or ?. To get help for a specific command, use help command.

Getting Information about the Guest System

To get information about the guest system, use the info option command. If used without any option, the list of possible options is printed. Options determine which part of the system will be analyzed:

info version

Shows the version of QEMU

info commands

Lists available QMP commands

info network

Shows the network state

info chardev

Shows the character devices

info block

Information about block devices, such as hard drives, floppy drives, or CD-ROMs

info blockstatsRead and write statistics on block devices

info registersShows the CPU registers

info cpusShows information about available CPUs

info historyShows the command line history

info irqShows the interrupts statistics

info picShows the i8259 (PIC) state

info pciShows the PCI information

info tlbShows virtual to physical memory mappings

info memShows the active virtual memory mappings

info jitShows dynamic compiler information

info kvmShows the KVM information

info numaShows the NUMA information

info usbShows the guest USB devices

info usbhostShows the host USB devices

info profileShows the profiling information

info captureShows the capture (audio grab) information

info snapshotsShows the currently saved virtual machine snapshots

info statusShows the current virtual machine status

info pcmciaShows the guest PCMCIA status

info miceShows which guest mice is receiving events

info vncShows the VNC server status

info nameShows the current virtual machine name

info uuidShows the current virtual machine UUID

info usernetShows the user network stack connection states

info migrateShows the migration status

info balloonShows the balloon device information

info qtreeShows the device tree

info qdmShows the qdev device model list

info romsShows the ROMs

info migrate_cache_sizesShows the current migration xbzrle (=Xor Based Zero Run Length Encoding) cache size.

info migrate_capabilitiesShows the status of the various migration capabilities, such as xbzrle compression.

info mtreeShows the VM Guest memory hierarchy.

info trace-events

Shows available trace-events and their status.

这些都可以在VNCViewer里面运行,然而有时候屏幕太小,不全,可以使用virsh进行操作

virsh # list
Id    Name                           State
----------------------------------------------------
14    instance-00000009              running
15    instance-0000000a              running

virsh # qemu-monitor-command 14 --hmp "info kvm"
kvm support: enabled

virsh # qemu-monitor-command 14 --hmp "info blockstats"
drive-virtio-disk0: rd_bytes=274441728 wr_bytes=777724928 rd_operations=15528 wr_operations=6520 flush_operations=673 wr_total_time_ns=121355399653 rd_total_time_ns=18996983203 flush_total_time_ns=4363807221

virsh # qemu-monitor-command 14 --hmp "info registers"
RAX=0000000000000000 RBX=ffffffff81c01fd8 RCX=00000000ffffffff RDX=0000000000000000
RSI=0000000000000001 RDI=ffffffff81ddae48 RBP=ffffffff81c01ea8 RSP=ffffffff81c01ea8
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000001
R12=ffffffff81cdc7c0 R13=0000000000000000 R14=ffffffffffffffff R15=000000000008c800
RIP=ffffffff8103df56 RFL=00000246 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=1
ES =0000 0000000000000000 000fffff 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0000 0000000000000000 000fffff 00000000
FS =0000 0000000000000000 ffffffff 00000000
GS =0000 ffff88007fc00000 000fffff 00000000
LDT=0000 0000000000000000 000fffff 00000000
TR =0040 ffff88007fc112c0 00002087 00008b00 DPL=0 TSS64-busy
GDT=     ffff88007fc04000 0000007f
IDT=     ffffffff81dd7000 00000fff
CR0=8005003b CR2=00007fff4cf57000 CR3=000000007b7fa000 CR4=001406f0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000d01
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=ffffffff00000000ffffffffff000000 XMM01=00000000000000000000000000ffffff
XMM02=00000000000000000000000000435455 XMM03=000000ff000000000000000000ff0000
XMM04=40404040404040404040404040404040 XMM05=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
XMM06=20202020202020202020202020202020 XMM07=ffff00ffffff00ffffffff00ffffffff
XMM08=00200000002000000000000000000000 XMM09=ff00ff00000000000000000000000000
XMM10=00002000000000000000000000000000 XMM11=00000000000000000000000000000000
XMM12=00000000000000000000000000000000 XMM13=00000000000000000000000000000000
XMM14=00000000000000000000000000000000 XMM15=00000000000000000000000000000000

virsh # qemu-monitor-command 14 --hmp "info tlb"     
0000000000400000: 0000000075a3f000 ----A--U-
0000000000401000: 0000000075a3e000 ----A--U-
0000000000402000: 00000000759ff000 ----A--U-
0000000000403000: 00000000759fe000 ----A--U-
0000000000404000: 0000000074dfe000 ----A--U-
0000000000405000: 0000000074dbf000 ----A--U-
0000000000406000: 0000000074dbe000 ----A--U-
0000000000407000: 0000000074d7f000 ----A--U-
0000000000408000: 0000000074dff000 ----A--U-
0000000000409000: 0000000074e3e000 ----A--U-
000000000040a000: 0000000074e3f000 ----A--U-
000000000040b000: 0000000074e7e000 ----A--U-
000000000040c000: 0000000074e7f000 ----A--U-
000000000040d000: 0000000074ebe000 ----A--U-
000000000040e000: 0000000074ebf000 ----A--U-

virsh # qemu-monitor-command 14 --hmp "info mem"
0000000000400000-0000000000420000 0000000000020000 ur-
0000000000421000-0000000000426000 0000000000005000 ur-
0000000000427000-000000000042c000 0000000000005000 ur-
000000000042e000-000000000044c000 000000000001e000 ur-
0000000000656000-0000000000658000 0000000000002000 ur-
0000000000658000-000000000065b000 0000000000003000 urw
000000000065b000-000000000065d000 0000000000002000 ur-
000000000065d000-000000000065f000 0000000000002000 urw
00000000006e1000-00000000006e3000 0000000000002000 urw
00000000006e3000-00000000006e5000 0000000000002000 ur-
00000000006e5000-00000000006e8000 0000000000003000 urw
00000000006e8000-00000000006e9000 0000000000001000 ur-
00000000006e9000-00000000006ea000 0000000000001000 urw
00000000006ea000-00000000006eb000 0000000000001000 ur-
00000000006eb000-0000000000701000 0000000000016000 urw
0000000000712000-0000000000715000 0000000000003000 urw
00007f0a00000000-00007f0a0003c000 000000000003c000 urw
00007f0a04000000-00007f0a04004000 0000000000004000 urw
00007f0a08000000-00007f0a08002000 0000000000002000 urw
00007f0a0e8ea000-00007f0a0e8ec000 0000000000002000 urw
00007f0a0f0e2000-00007f0a0f0e3000 0000000000001000 urw
00007f0a0f0ea000-00007f0a0f0ed000 0000000000003000 urw
00007f0a0f8ea000-00007f0a0f8ee000 0000000000004000 urw
00007f0a0f8ee000-00007f0a0f8f1000 0000000000003000 ur-

virsh # qemu-monitor-command 14 --hmp "info balloon"
balloon: actual=2048

Changing VNC Password

To change the VNC password, use the change vnc password command and enter the new password:

(qemu) change vnc password
Password: ********
(qemu)
 

Managing Devices

To release the device or file connected to the removable media device, use the eject device command. Use the optional -f to force ejection.

To change removable media (like CD-ROMs), use the change device command. The name of the removable media can be determined using the info block command:

(qemu) info block
ide1-cd0: type=cdrom removable=1 locked=0 file=/dev/sr0 ro=1 drv=host_device
(qemu) change ide1-cd0 /path/to/image

Changing Available Memory

If the virtual machine was started with the -balloon virtio option and the paravirtualized balloon device that allows to dynamically change the amount of memory available is therefore enabled, it is possible to change the available memory dynamically. For more information about enabling the balloon device.

To get information about the balloon device in the monitor console and to determine whether the device is enabled, use the info balloon command:

(qemu) info balloon

If the balloon device is enabled, use the balloon memory_in_MB command to set the requested amount of memory:

(qemu) balloon 400

virsh # qemu-monitor-command 14 --hmp "info balloon"
balloon: actual=2048

Dumping Virtual Machine Memory

To save the content of the virtual machine memory to a disk or console output, use the following commands:

memsave addr size filename

Saves virtual memory dump starting at addr of size size to file filename

pmemsave addr size filename

Saves physical memory dump starting at addr of size size to file filename

filename保存在HOST机器上

addr最小是0000000000400000

Managing Virtual Machine Snapshots

Virtual machine snapshots are snapshots of the complete virtual machine including the state of CPU, RAM, and the content of all writable disks. To use virtual machine snapshots, you must have at least one non-removable and writable block device using the qcow2 disk image format.

The following commands are available for managing snapshots in QEMU monitor:

savevm name

Creates a new virtual machine snapshot under the tag name or replaces an existing snapshot.

loadvm name

Loads a virtual machine snapshot tagged name.

delvm

Deletes a virtual machine snapshot.

info snapshots

Prints information about available snapshots.

(qemu) info snapshots
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 booting 4.4M 2010-11-22 10:51:10 00:00:20.476
2 booted 184M 2010-11-22 10:53:03 00:02:05.394
3 logged_in 273M 2010-11-22 11:00:25 00:04:34.843
4 ff_and_term_running 372M 2010-11-22 11:12:27 00:08:44.965

Unique identification number of the snapshot. Usually auto-incremented.

Unique description string of the snapshot. It is meant as a human readable version of the ID.

The disk space occupied by the snapshot. Note that the more memory is consumed by running applications, the bigger the snapshot is.

Time and date the snapshot was created.

The current state of the virtual machine's clock.

Suspending and Resuming Virtual Machine Execution

The following commands are available for suspending and resuming virtual machines:

stop

Suspends the execution of the virtual machine.

cont

Resumes the execution of the virtual machine.

system_powerdown

Sends an ACPI shutdown request to the machine. The effect is similar to the power button on a physical machine.

q or quit

Terminates QEMU immediately.

Live Migration

The live migration process allows to transmit any virtual machine from one host system to another host system without any interruption in availability. It is possible to change hosts permanently or just during a maintenance. It is recommended that the source and destination systems have the same architecture, however it is possible to migrate between hosts with AMD and Intel architectures.

The requirements for the live migration:

  • Live migration is only possible between VM Host Servers with the same CPU features. The only supported CPU model for migration is -cpu qemu64 (default) with no additional features specified.

  • No physical devices can be passed from host to guest.

  • The VM Host Server and VM Guest need to have proper timekeeping installed.

  • AHCI interface, virtfs feature, and the -mem-path command-line option are not compatible with migration.

  • Migration from SP3 to SP2 or SP1 hosted guests is not supported.

  • The virtual machine image must be accessible on both source and destination hosts. For example, it can be located on a shared NFS disk.

  • The image directory should be located in the same path on both hosts.

  • Both hosts must be located in the same subnet.

  • The guest on the source and destination hosts must be started in the same way.

The live migration process has the following steps:

  1. The virtual machine instance is running on the source host.

  2. The virtual machine is started on the destination host in the frozen listening mode. The parameters used are the same as on the source host plus the -incoming tcp:ip:port parameter, where ip specifies the IP address and port specifies the port for listening to the incoming migration. If 0 is set as IP address, the virtual machine listens on all interfaces.

  3. On the source host, switch to the monitor console and use the migrate -d tcp:destination_ip:port command to initiate the migration.

  4. To determine the state of the migration, use the info migrate command in the monitor console on the source host.

  5. To cancel the migration, use the migrate_cancel command in the monitor console on the source host.

  6. To set the maximum tolerable downtime for migration in seconds, use the migrate_set_downtime number_of_seconds command.

  7. To set the maximum speed for migration in bytes per second, use the migrate_set_speed bytes_per_second command.

QEMU KVM libvirt手册(2): monitor的更多相关文章

  1. QEMU KVM Libvirt手册(10):Managing Virtual Machines with libvirt

    libvirt is a library that provides a common API for managing popular virtualization solutions, among ...

  2. QEMU KVM Libvirt手册(11): Managing Storage

    When managing a VM Guest on the VM Host Server itself, it is possible to access the complete file sy ...

  3. QEMU KVM Libvirt手册(7): 硬件虚拟化

    在openstack中,如果我们启动一个虚拟机,我们会看到非常复杂的参数 qemu-system-x86_64 -enable-kvm -name instance-00000024 -S -mach ...

  4. QEMU KVM libvirt手册(4) – images

    RAW raw是默认的格式,格式简单,容易转换为其他的格式.需要文件系统的支持才能支持sparse file 创建image # qemu-img create -f raw flat.img 10G ...

  5. QEMU KVM libvirt 手册(3) - Storage Media

    访问Hard Drive 使用-hda –hdb qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda ubuntutest.im ...

  6. QEMU KVM Libvirt手册(8): 半虚拟化设备virtio

    KVM本身并不提供半虚拟化功能,是通过virtio来实现的 The benefits of virtio drivers are of lower overhead and higher perfor ...

  7. QEMU KVM libvirt 手册(1): 安装

    安装 对虚拟化的支持通常在BIOS中是禁掉的,必须开启才可以. 对于Intel CPU,我们可以通过下面的命令查看是否支持虚拟化. # grep "vmx" /proc/cpuin ...

  8. QEMU KVM Libvirt手册(10): KVM的各种限制

    Overcommits KVM allows for both memory and disk space overcommit. However, hard errors resulting fro ...

  9. QEMU KVM Libvirt手册(9): network

    虚拟网卡由-net nic定义 # qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda ubuntutest.img -vnc ...

随机推荐

  1. 从零开始学spring cloud(九) -------- 超时机制,断路器模式介绍

    目前存在的问题: 现在我们假设一下,服务提供者响应非常缓慢,那么消费者对提供者的请求就会被强制等待,直到服务返回.在高负载场景下,如果不做任何处理,这种问题很可能造成所有处理用户请求的线程都被耗竭,而 ...

  2. web配置详细解释

    <?xml version="1.0"?> <!--注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来配置应用程序的设置.可以使用 Visual S ...

  3. Pyton:类变量,实例变量,类对象,实例对象

    https://www.cnblogs.com/crazyrunning/p/6945183.html

  4. mysql 索引及索引创建原则

    是什么 索引用于快速的查询某些特殊列的某些行.如果没有索引, MySQL 必须从第一行开始,然后通过搜索整个表来查询有关的行.表越大,查询的成本越大.如果表有了索引的话,那么 MySQL 可以很快的确 ...

  5. 3,fiddler手机端的设置

    1,首先设置手机端代理 选择链接的无限网,设置其代理 2,安装手机证书 只有在启动fiddler的时候手机才能够上网, 在浏览器,输入主机ip+fiddler端口的地址 进入后是下边的界面 点击下载证 ...

  6. Jenkins自定义变量共享

    https://www.cnblogs.com/junneyang/p/5239480.html https://www.cnblogs.com/Rocky_/p/8317156.html https ...

  7. python 实现快排序

    def q_sort(arr): if len(arr)<2: return arr pivot = arr[0] less = [x for x in arr[1:] if x <= p ...

  8. AHOI——Day1个人感悟

    今天,是个bilibili的日子.(嗯?什么意思?) 洛谷已经尽力了: 于是我带着洛谷的祝福,来到了AHOI的考场--合肥一中. 其实我是考完才签到的,我一大早五点多就起来了,到考场后,在肯德基吃了早 ...

  9. 利用Python生成GIF动图

    一.PIL库 1.PIL库的概括: PIL(Python Image Library)是python的第三方图像处理库,但是由于其强大的功能与众多的使用人数,几乎已经被认为是python官方图像处理库 ...

  10. 88、const、static、extern介绍

    一.const与宏的区别 const简介:之前常用的字符串常量,一般是抽成宏,但是苹果不推荐我们抽成宏,推荐我们使用const常量. 执行时刻:宏是预编译(编译之前处理)const是编译阶段. 编译检 ...