Virtualization with KVM
Virtualization is a hot topic in the operating systems world these days. The use cases vary from server consolidation, virtual test environments to Linux enthusiasms who can’t decide which distribution is best. The Kernel-based Virtual Machine, kvm is a popular full-virtualization solution for Linux based systems. It can be used to run guests systems on systems with hardware virtualization extensions (AMD-V or Intel VT-x).
The goal of this project was creating a minimal solution that would allow a user to run virtual machines (VM) over yocto.
Packages
The project is based on the meta-xen layer from oe-core. This layer creates a target image that can act as a host for running VMs using the Xen hypervisor. It also features the libvirt package used for the virtual machine management.
KVM
KVM can be used to run multiple virtual machines that containing unmodified Windows or Linux images. Starting from the 2.6.20 version, the kvm component is included in the mainline Linux kernel so no extra packages are required for kvm support, only a proper kernel configuration.
Qemu
To be able to run the KVM virtual machines, the qemu package was included in the image. This comes with built-in support for KVM and for all the new advanced features like virtio, which is the main platform for IO virtualization If the underlying hardware does not provide support for KVM or if it has been disabled, qemu can be used to run the VMs using software emulation, but with a performance loss.
Libvirt
Libvirt is a toolkit for interacting with virtual machine hypervisors. It comes with a C API and a set of bindings for common languages. The functionality is exposed through the virsh command. The library is also used by some modern VM management systems to handle typical tasks when dealing with VMs. Our layer builds libvirt only for the qemu package. To configure libvirt for other hypervisors you just have to make some minor modifications to the recipe provided by the meta-xen layer. An example of how to remotely connect using Virt-manager to control the VMs can be found in the VMM section (TODO).
Virtual Machine Management
CLI
If you already have an existing VM image, it can be run from the CLI using the various qemu-system-* commands. To connect to the console of the VM, the user has to configure a vncserver. The vnc option can be used for this. The target image does not contain any additional tools for the creation and the management of the virtual machines, but, it has the libvirt package installed and has the libvirtd daemon listening for new connections. This allows other tools like virt-install to remotely connect to the hypervisor running on the host system and run all the commands on the host. The virt-install utility is a CLI tool for the creation of new VMs. A tutorial on how to use virt-install for the creation of VMs can be found here.
GUI
Virt-manager is a popular desktop interface for managing VMs. It offers an interactive wizard for the creation of new virtual machines and it presents statistics on the resource utilization of the running domains. To communicate with the hypervisors it requires the libvirt toolkit installed on the host systems. It can also be used to manage VMs that run on remote hosts. For this, the libvirt daemon has to be listening for new connections. In our target image the libvirtd daemon is configured to listen for new TCP connections. Authentication is disabled by default so no special credentials are required for the connection.
How to connect to the target ?
- Install virt-manager on the system.
- Start a new virt-manager instance by running virt-manager from the command line.
- Create a new connection : Select File -> Add Connection
- Check Connect to remote host
- Method : TCP
- Username: name of the user on the remote host. For the kvm image use root.
- Hostname: the IP address of the kvm image.
At this moment, you should have a new active connection in the main window. A practical tutorial with all the available options can be found here.