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
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:
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:
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.