qemu-init uses the qemu monitor to communicate with the registered guests. This will be done through monitor redirection with 2 types of sockets: tcp sockets and unix sockets. The behavior of qemu with (at least) socket redirection makes is necessary to have 2 channels:
- interactive channel - stay connected until the user actively dissconnects
- command channel - send a single command to the monitor and disconnect
|Socket and channel combinations
The qemu monitor is important cause qemu-init requires it for communication. It will be started by default, redirected via tcp at localhost. The first port number is defined in . For each virtual machine started by
/etc/qemu/monitor.conf  (default: 30320)
qemu-init  the port will be increased by 1. Make sure that no other programs uses a port inside the range required by
qemu-init . If no valid port could be determined, the monitor will be disabled silently.
The qemu monitor will be bound to
(IPv4) by default always.
qemu-init  checks for address
::1  (IPv6) too. If it is available the qemu monitor will be bound to ::1 additional.
It is a requirement that the monitor could be accessed via a tcp socket. The stop function of
qemu-init  uses a socket to shutdown virtual machines clean. See Stop a VM below for details.
There are multiple ports used by the monitor. The first one is MONPORT (monitor port), calculated like described above. The MONPORT is used by
qemu-mon  to establish a permanent connection. The second one is the CTLPORT (control port). Its number is MONPORT+100. The CTLPORT is used by
qemu-cmd . Both tools checks for the proper IP version of the socket. The background to have multiple ports is, that there is only one connection to a socket possible at the same time.