Monday, March 17, 2014

Kernel Based Virtual Machine

Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.

The kernel component of KVM is included in mainline Linux, as of 2.6.20.
KVM is open source software.

Needed packages to set up KVM:
qemu-kvm - The main KVM package
python-virtinst - Command line tools and libraries creating VMs
virt-manager - GUI VM administration tool
virt-top - Command for VM statistics
virt-viewer - GUI connection to configured VMs
libvirt - C language toolkit with the libvirtd service
libvirt-client - C langiuage toolkit for VM clients

# yum install qemu-kvm python-virtinst virt-manager virt-top virt-viewer libvirt libvirt-client -y

# lsmod |grep kvm    - to check if kvm module is loaded

[root@tester1 ~]# lsmod |grep kvm
kvm_intel              54285  0 
kvm                   332980  1 kvm_intel

--if you do not get the output above you can use this command below:

# modprobe kvm      - load kvm module
# service libvirtd restart

From the GUI mode go to -Applications -> System Tools -> Open Virtual Machine Manager. GUI (Graphical User Interface) is easy to install kvm. (you will need one Centos ISO image.)

If you would like to install KVM which we will be doing during our class you will need to run following command.

[root@tester1 ~]# virt-install --prompt
What is the name of your virtual machine? 
testing.prod.example.com
How much RAM should be allocated (in megabytes)? 
700
What would you like to use as the disk (file path)? 
/var/lib/libvirt/images/testing.prod.example.com
How large would you like the disk (/var/lib/libvirt/images/testing.prod.example.com) to be (in gigabytes)? 
15
What is the install CD-ROM/ISO or URL? 
/root/Downloads/CentOS-6.5-x86_64-minimal.iso

From the command line we use 'virsh' to manage the VMs of KVM.

# /etc/init.d/libvirtd restart - to make sure service is running
# virsh list --all   - to list all the VMs
# virsh destroy VM's name - to shutdown the VM  (virsh shutdown VM name will not work)
# virsh start VM's name
# virsh autostart VM's name  - to make it persistent to reboot

9 comments:

  1. Please comment here extra things you know and learned about KVM here. Post problems you have faced while installing KVM or your success. As I have said at least one comment each person.

    ReplyDelete
  2. [root@tester1 ~]# virt-install --prompt
    What is the name of your virtual machine?
    testing.prod.bek.com
    How much RAM should be allocated (in megabytes)?
    700
    What would you like to use as the disk (file path)?
    /var/lib/libvirt/images/testing.prod.bek.com
    How large would you like the disk (/var/lib/libvirt/images/testing.prod.bek.com) to be (in gigabytes)?
    7
    No read access to directory ' /var/lib/libvirt/images/testing.prod.bek.com

    I've this kind of error not going further. Should I change anything in VM?

    ReplyDelete
  3. Demak, read access berish kerak directoryga :) it is that simple

    ReplyDelete
  4. Why nobody is commenting here? Were you able to install KVM or not? What about feedback? Could we do better? Please comment here and contribute.

    ReplyDelete
  5. I have a lil issue but I will post the answer as soon as I find a solution

    ReplyDelete
  6. yum install qemu-kvm python-virtinst virt-manager virt-top virt-viewer libvirt libvirt-client -y
    Loaded plugins: rhnplugin, security
    This system is receiving updates from RHN Classic or RHN Satellite.
    Setting up Install Process
    No package qemu-kvm available.
    No package python-virtinst available.
    No package virt-manager available.
    No package virt-top available.
    No package virt-viewer available.
    No package libvirt available.
    No package libvirt-client available.
    Nothing to do

    ReplyDelete
  7. root@vm1 ~]# yum repolist
    Loaded plugins: rhnplugin, security
    This system is receiving updates from RHN Classic or RHN Satellite.
    repo id repo name status
    rhel-x86_64-server-5 Red Hat Enterprise Linux (v. 5 for 64-bit x86_64) 16,021
    repolist: 16,021

    ReplyDelete