Administrating virtual machines with qemu Monitor
When qemu is running, a monitor console is provided for inserting 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 blockstats
-
Read and Write statistics on Block devices
-
Info registers
-
Shows the CPU registers
-
Info CPUs
-
Shows information about available CPUs
-
Info history
-
Shows the command line history
-
Info IRQ
-
Shows the interrupts statistics
-
Info PIC
-
Shows the i8259 (PIC) State
-
Info PCI
-
Shows the PCI Information
-
Info TLB
-
Shows virtual to physical memory Mappings
-
Info mem
-
Shows the active virtual memory Mappings
-
Info JIT
-
Shows dynamic compiler Information
-
Info KVM
-
Shows the KVM Information
-
Info NUMA
-
Shows the NUMA Information
-
Info USB
-
Shows the guest USB devices
-
Info usbhost
-
Shows the host USB devices
-
Info Profile
-
Shows the profiling information
-
Info capture
-
Shows the capture (audio grab) Information
-
Info snapshots
-
Shows the currently saved Virtual Machine snapshots
-
Info status
-
Shows the current virtual machine status
-
Info PCMCIA
-
Shows the guest PCMCIA status
-
Info Mice
-
Shows which guest mice is refreshing events
-
Info VNC
-
Shows the VNC Server Status
-
Info name
-
Shows the current Virtual Machine name
-
Info UUID
-
Shows the current Virtual Machine UUID
-
Info usernet
-
Shows the user network stack connection States
-
Info migrate
-
Shows the migration status
-
Info balloon
-
Shows the balloon device information
-
Info qtree
-
Shows the Device Tree
-
Info qdm
-
Shows the qdev Device Model List
-
Info ROMs
-
Shows the Roms
-
Info migrate_cache_sizes
-
Shows the current migration xbzrle (= XOR based zero Run Length Encoding) cache size.
-
Info migrate_capabilities
-
Shows the status of the various migration capabilities, such as xbzrle compression.
-
Info mtree
-
Shows the VM guest memory hierarchy.
-
Info trace-Events
-
Shows Available Trace-events and their status.
These functions can be run in vncviewer. However, sometimes the screen is too small and incomplete. You can use virsh to perform operations.
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 = 00000000 ffffffff RDX = 0000000000000000
RSI = 0000000000000001 RDI = ffffffff81ddae48 RBP = ffffffff81c01ea8 RSp = ffffff81c01ea8
R8 = 0000000000000000 R9 = 0000000000000000 R10 = 0000000000000000 R11 = 0000000000000001
R12 = ffffff81csc7c0 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 000 fffff 00000000
Cs = 0010 0000000000000000 ffffffff 00a09b00 DPL = 0 cs64 [-Ra]
Ss = 0018 0000000000000000 ffffffff 00c09300 DPL = 0 DS [-wa]
DS = 0000 0000000000000000 000 fffff 00000000
FS = 0000 0000000000000000 ffffffff 00000000
GS = 0000 ffff88007fc00000 000 fffff 00000000
LDT = 0000 0000000000000000 000 fffff 00000000
Tr = 0040 ffff88007fc0000c0 00002087 running 8b00 DPL = 0 TSS64-busy
Gdt = ffff88007fc04000 0000007f
IDT = ffffff81dd7000 00000fff
Cr0 = 8005003b Cr2 = 20177fff4cf57000 32a = 2017100007b7fa000 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 = 1271f80
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 = ffffffff00000000ffffffff000000 xmm01 = 00000000000000000000000000 ffffff
Xmm02 = 00000000000000000000000000435455 xmm03 = 000000ff000000000000000000ff0000
Xmm04 = 40404040404040404040404040404040 xmm05 = 5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
Xmm06 = 20202020202020202020202020202020 xmm07 = ffff00ffffff00ffffffff00ffffffff
Xmm08 = 00200000002000000000000000000000 xmm09 = ff00ff000000000000000000000000000000
Xmm10 = 00002000000000000000000000000000 xmm11 = 00000000000000000000000000000000
Xmm12 = 00000000000000000000000000000000 xmm13 = 00000000000000000000000000000000
Xmm14 = 00000000000000000000000000000000 xmm15 = 00000000000000000000000000000000
Virsh # qemu-monitor-command 14 -- HMP "info TLB"
0000000000400000: 20171000075a3f000 ---- A--U-
0000000000401000: 20171000075a3e000 ---- A--U-
0000000000402000: 00000000759ff000 ---- A--U-
0000000000403000: 00000000759fe000 ---- A--U-
0000000000404000: commandid 74dfe000 ---- A--U-
0000000000405000: commandid 74dbf000 ---- A--U-
0000000000406000: commandid 74dbe000 ---- A--U-
0000000000407000: 10910974d7f000 ---- A--U-
0000000000408000: commandid 74dff000 ---- A--U-
0000000000409000: 10910974e3e000 ---- 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
20177f0a00000000-00007f0a0003c000 000000000003c000 urw
20177f0a04000000-20177f0a04004000 0000000000004000 urw
20177f0a08000000-20177f0a08002000 0000000000002000 urw
20177f0a0e8ea000-20177f0a0e8ec000 0000000000002000 urw
20177f0a0f0e2000-20177f0a0f0e3000 0000000000001000 urw
20177f0a0f0ea000-20177f0a0f0ed000 0000000000003000 urw
20177f0a0f8ea000-20177f0a0f8ee000 0000000000004000 urw
20177f0a0f8ee000-20177f0a0f8f1000 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 passwordPassword: ********(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 blockide1-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 to file filename
-
Pmemsave ADDR size filename
-
Saves physical memory dump starting at ADDR of size to file filename
Filename is stored on the host machine.
The minimum ADDR value is 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 CLOCK1 booting 4.4M 2010-11-22 10:51:10 00:00:20.4762 booted 184M 2010-11-22 10:53:03 00:02:05.3943 logged_in 273M 2010-11-22 11:00:25 00:04:34.8434 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 ubuntures.
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 shoshould 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:
The Virtual Machine instance is running on the source host.
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.
On the source host, switch to the monitor console and use the migrate-d tcp: destination_ip: PORT command to initiate the migration.
To determine the state of the migration, use the info migrate command in the monitor console on the source host.
To cancel the migration, use the migrate_cancel command in the monitor console on the source host.
To set the maximum tolerable downtime for migration in seconds, use the migrate_set_downtime number_of_seconds command.
To set the maximum speed for migration in bytes per second, use the migrate_set_speed bytes_per_second command.