Virtualization using KVM
Overview
"Virtual Machine Manager" is an application that provides a GUI tool for managing virtual machines via libvirt. The Main features are:
- Creating of virtual disks using the the following formats: raw, qcow, qcow2, cow, qed, vmdk, and vpc
- Managing the "virtual hardware" including dedicated RAM and CPUs
- Controlling of local and remote machines either in graphical or text mode
- State saving/restoration, pausing and rebooting through the GUI
- Monitoring CPU load, memory usage and disk and network I/O
- Adding various types of hardware to the virtual machine (including USB devices and disks)
- Connecting a USB storage device
- Bidirectional clipboard (host<->guest)
The back end of virt-manager uses libvirt for managing Xen, QEMU & KVM virtual machines. The GUI is primarily tested with Xen and QEMU, but is intended to be portable to any virtualization backend that libvirt supports.
Preparation
First of all, check your hardware for virtualization support if you are not sure about it. Virtualization support is necessary to adapt this documentation on your computer.
Run the following command on your terminal:
$ grep -E 'svm|vmx' /proc/cpuinfoIf you don't get any output check if your BIOS configuration during boot time allows you to enable virtualization as some device come with this feature. If your BIOS has no such option, your computer's CPU may not support virtualization.
Installation and Setup
First, install the required packages:
$ sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-viewer virt-managerAfter the required packages are installed, start your libvirt daemon by running the following command:
$ sudo service libvirtd startNote: start and stop are the available options.
The installation process already did some jobs for you, like adding the user to the "libvirt" group and bridging the network interface, so now you are ready to start installing your virtual machine.
Virtual Machine Manager
Starting the "Virtual Machine Manager" can be done by opening the Main Menu and selecting Other->Virtual Machine Manager or by running:
$ virt-managerYou do not need to run the above command as root or as "super user".
The screenshots below will guide you through the creation of a simple virtual machine. This guide is an example and only purposed to be a quick overview of "Virtual Machine Manager".
Access Control
To be able to access the libvirt socket and manage the virtual machines the user needs to belong to the "libvirt" group or have superuser privileges. Alternatively, you can use the session URL links that look like "qemu:///session" for viewing.
File sharing
SFTP, FTP and CIFS are all very accessible ways of sharing files when networks are involved. Otherwise, check the Project's Official Documentation for clarification on adding a pass-through file system.
Troubleshooting
Core2Duo CPUs
Some Intel Core2Duo CPU models do not support virtualization. Run the following command:
$ grep name /proc/cpuinfoIn this case it is recommended to verify on manufacturer's website if your CPU supports virtualization. It would be something like "VT" for Intel.
Slow graphics performance
This can greatly depend on your configuration, hardware and hardware load, but using the SPICE protocol and QXL graphics over VNC can moderately improve graphical performance. See "Enabling bidirectional clipboard" in this page on how to make this change. See "Missing characters when using the SPICE protocol with QXL" in this page. It is also a good idea to disable compositors unless it is desired. See "Enabling bidirectional clipboard" in this page(GNOME Flashback).
Missing characters when using the SPICE protocol with QXL (at least [?])
Frequently, some of the letters on all windows, panels and Desktop will go missing without a specific pattern, which coincides with a spike in CPU usage. It seems not depend on resolution as it will happen on 1920x1080 and 860x600. This modification also seems to moderately improve graphical performance.
This has been verified to happen at least on Trisquel 7.0 (LXDE and GNOME) and Ubuntu 14.04 hosts using SPICE and QXL (spice-vdagent was installed on the guest in all cases).
Edit the grub configuration file with your favorite text editor:
$ sudo nano /etc/default/grubChange the value of the "GRUB_CMDLINE_LINUX_DEFAULT=" directive to include the "nomodeset" parameter, such as:
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet nomodeset"Finally, update grub:
$ sudo update-grubAfter rebooting, the issue seems to no longer affect the guest.
See Ubuntu Forums (Discussion)
There is also a bug report on Ubuntu 15.05 as of 29/01/2015.
Resolution, scaling and graphical performance
The following results come from the following environment: Trisquel 7.0 host (GNOME Flashback), Trisquel 7.0 guest (Mini - LXDE), local guest, bridged networking on eth0, 2500 MB of RAM and 2 CPUs on the guest, Samsung NP530-U4B. I did not compare Network I/O, CPU load nor RAM usage. Cirrus seems to be limited to 1280x768 and is only compatible with VNC. VGA seems to be limited to 1280x768 , but it seems smoother than Cirrus. QLX is both compatible with VNC and SPICE. It seems smoother than the previous two. It also seems more responsive in VNC than SPICE, but there is more tearing in the former. The white mouse does not really look good over GNOME Flashback's grey windows. Could not change mouse cursor. The resolution goes at least up to 1920x1080 on both protocols. The mouse seemed to disappear on occasion, but it still interacted with the Desktop. I did not test Xen or VMVGA due to technical issues.
TODO
Test and optimize graphical performance.
VFIO
(HIGH PRIOTRITY) This module/tool/concept allows to achieve as much as 99% of benchmark results on virtual machines than on the host. It is required to have two graphics cards. The concept resides on passing-through one of the cards to the guest so it can have direct control over the hardware. There are a other requirements including kernel and boot parameters, but Trisquel 7.0's default kernel seems to have everything to setup this environment. Here are some resources to get you started:- Kernel.org Documentation (very complete)
- Debian Wiki (seems a bit incomplete)
- Arch Forums (160 pages, very dense)
- Gaming Example with Nvidia
- Blog Post on setting up VFIO
- Wikipedia IOMMU Briefing
To check if your CPU supports the correct type of virtualization you can check the manufacturer's website or Wikipedia. "My device has an Intel(R) Core(TM) i5-2467M, which has the proper requirements for virtualization, but not for VFIO. One thing to be is aware that VFIO needs VT-d and not VT-x(mine) to be able to forward PCI devices. Do not be surprised if you read in dmesg that IOMMU was enabled after adding the intel_iommu=yes line to the grub parameters." - Trisquelian