網頁

2015年11月29日 星期日

KVM 2.0.0 --- How to install KVM and Virtual Machine Manager on Lubuntu 14.04

In Linux environment, we have other choice to create virtual machines besides VirtualBox or VMware. That is KVM.
KVM (Kernel-based Virtual Machine) is a virtualization extension for the Linux Kernel. We can use KVM to run both Windows and Linux in virtual machines.

The following guide will explains how to install and use KVM for creating and running virtual machines on an Lubuntu 14.04 LTS Desktop.

  1. Preprequisite Check
KVM will work only if the CPU is suitable for Intel VT or AMD-V hardware virtualization. We can run the sudo egrep -c '(vmx|svm)' /proc/cpuinfo command to find whether the cpu supports virtualization features
※ The 0 value means the processor doesn't support VT-x extensions, but values greater than 1 mean it does.



Check the hardware compatible by using sudo kvm-ok command (# 1)

To see what kernel is 32-bit or 64-bit by using uname -ri command (# 2)
※ In 32-bit kernel, the memory size of a VM will be limited to 2GB and only can install 32-bit guest VM.

  1. Install KVM and other packages
    1. By doing sudo apt-get update command, downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies.

    1. Install Qemu package
      1. For enabling KVM hypervisor, we can install Kernal based Virtual machine(qemu-kvm) and CPU emulator(qemu) by using the sudo apt-get install qemu-kvm qemu command.

    1. Install libvirt library
      1. For interacting with the virtualization capabilities of recent versions of Linux, we can install libvirt package by using sudo apt-get install libvirt-bin command

    1. Install network utility
      1. For setting up networks on VM, we can install the bridge-utils package by using sudo apt-get install bridge-utils command

    1. Install graphical interface
      1. For managing KVM based virtual machines, we can install Virt-Manager(Virtual Machine Manager) graphical tool by using the sudo apt-get install virt-manager command.

※ On Lubuntu/Ubuntu, we can directly install another tool “ubuntu-vm-builder” that can be used for provisioning Ubuntu builds by using the sudo apt-get install ubuntu-vm-builder command.


  1. Delegate permission
In the moment, only the root user and users in the libvirtd group have permission to use KVM virtual machines. So that we have to add the specifial user account to the libvirtd group by using the sudo adduser libvirtd command
or using sudo adduser ‘id -un’ libvirtd command for logon account.

After do it, we have to log off and log on so that the user can run virtual machine now.

  1. Verify Installation
    1. Verify whether the KVM daemon is up and running by using the lsmod | grep kvm command.
    1. Check kvm daemon version by using the kvm --version command
    1. Verify whether the libvirt-bin daemon is up and running by using the sudo service libvirt-bin status command.
    1. Check libvirt-bin daemon version by using the libvirtd --version command
    1. Check whether kvm and libvirtd exist in /etc/group by using sudo cat /etc/group command
    1. Check whether libvirt-qemu and libvirt-dnsmasq exist in /etc/passwd by using sudo cat /etc/passwd command
    1. Check KVM installation status by using the sudo virsh -c qemu:///system list command

  1. Network Setup (virbr0 NAT interface)
The default network mode is the User mode and uses a predefined virbr0 (# 3) brigge which is NAT routed to the guest computer. The NAT routing uses the kernel's ip_forwarding feature and iptables.

To see the default User network setting by using the sudo virsh net-dumpxml default command
When the libvirt default network is running, you will see an isolated bridge device. This device explicitly does *NOT* have any physical interfaces added, since it uses NAT + forwarding to connect to outside world.

  1. Create a new VM
Once the installation completes, we can lanuch Virtual Machine Manager in GUI mode by using the sudo virt-manager command. (# 4)
To right-click the localhost(QEMU) and click New in menu, it will start a wizard for creating the new virtual machine.

Reference:
(# 1)     If we run the kvm-ok command, we can realize whether VT-x funciton is switched on and need to enable VT-x in the BIOS setting.
If this commad never be installed, we can install cpu-checker package by using the sudo apt-get install cpu-checker command to help evaluate the CPU feature.

(# 2)    Because KVM is not compatible with Xen, make sure Linux is not running a Xen kernel by running the uname -a command.
If you see output similar to “2.6.18-164.el5Xen”, a Xen kernel is running and must be stopped or remove before install KVM.

(# 3)   To disable virbr0 NAT interface by using the following command
# virsh net-destroy default
# virsh net-undefine default
# service libvirtd restart

(# 4)   If you don't want to run as root, the user you want to use needs to have rw access to /dev/kvm
(# 5)   After installing the libvirt and its GUI front-end virt-manager, the defalut location of VM image will be created on /var/lib/libvirt/images directory.

沒有留言:

張貼留言

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.