/runqemu

A handy python script to run a QEMU virtual machine

Primary LanguagePython

runqemu

A handy python script to run a QEMU virtual machine

Quick Start

$ python3 runqemu.py
usage: runqemu.py [-h] -drive_image_path DRIVE_IMAGE_PATH [-ssh_port SSH_PORT]
                  [-enable_kvm ENABLE_KVM] -num_cores NUM_CORES -num_nodes
                  NUM_NODES -memory_size MEMORY_SIZE [-vnc_port VNC_PORT]
                  [-serial_port SERIAL_PORT] [-use_graphic USE_GRAPHIC]
                  [-qmp_path QMP_PATH] [-hmp_path HMP_PATH]
runqemu.py: error: the following arguments are required: -drive_image_path, -num_cores, -num_nodes, -memory_size

$ python3 runqemu.py -drive_image_path ~/qemu-virtual-machines/ubuntu.img -num_nodes 2 -memory_size 32 -num_cores 10

Accessing Serial Console

  • If you set the GRUB options of the guest virtual machine like below, you can access the serial console of the VM from the host machine.
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8 ignore_loglevel"
$ telnet localhost 1234
Trying ::1...
Connected to localhost.localdomain.
Escape character is '^]'.
[    0.000000] Linux version 5.5.0+ (root@vm) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #1 SMP Fri J
ul 17 13:31:25 UTC 2020

Accessing QEMU Monitors

  • QEMU offers two types of monitors: QMP and HMP.
  • Commands can be sent to a virtual machine using the monitors.
    • The command format of QMP is in JSON, and the format of HMP is in human-readable text.
  • The shells can be opened with socat.
$ sudo socat - UNIX-CONNECT:/tmp/hmp
$ sudo socat - UNIX-CONNECT:/tmp/qmp

Acknowledgement

We thank the anonymous reviewers for their insightful feedbacks and comments. This work was supported by National Research Foundation of Korea (NRF-2019R1A2B5B01069816) and the Institute for Information & communications Technology Promotion (IITP-2017-0-00466).