Home > other > Virtualization With KVM On A CentOS 6.0 Server

Virtualization With KVM On A CentOS 6.0 Server

August 27Hits:0
Advertisement

Virtualization With KVM On A CentOS 6.0 Server

Version 1.0
Author: Falko Timme
Virtualization With KVM On A CentOS 6.0 Server

Follow me on Twitter

This guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.0 server. I will show how to create image-based virtual machines and also virtual machines that use a logical volume (LVM). KVM is short for Kernel-based Virtual Machine and makes use of hardware virtualization, i.e., you need a CPU that supports hardware virtualization, e.g. Intel VT or AMD-V.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

I'm using a CentOS 6.0 server with the hostname server1.example.com and the IP address 192.168.0.100 here as my KVM host.

I had SELinux disabled on my CentOS 6.0 system. I didn't test with SELinux on; it might work, but if not, you better switch off SELinux as well:

vi /etc/selinux/config

Set SELINUX=disabled...

# This file controls the state of SELinux on the system.  # SELINUX= can take one of these three values:  #     enforcing - SELinux security policy is enforced.  #     permissive - SELinux prints warnings instead of enforcing.  #     disabled - No SELinux policy is loaded.  SELINUX=disabled  # SELINUXTYPE= can take one of these two values:  #     targeted - Targeted processes are protected,  #     mls - Multi Level Security protection.  SELINUXTYPE=targeted

... and reboot:

reboot

We also need a desktop system where we install virt-manager so that we can connect to the graphical console of the virtual machines that we install. I'm using a Fedora 15 desktop here.

2 Installing KVM

CentOS 6.0 KVM Host:

First check if your CPU supports hardware virtualization - if this is the case, the command

egrep '(vmx|svm)' --color=always /proc/cpuinfo

should display something, e.g. like this:

[[email protected] ~]# egrep '(vmx|svm)' --color=always /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
[[email protected] ~]#

If nothing is displayed, then your processor doesn't support hardware virtualization, and you must stop here.

Now we import the GPG keys for software packages:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

To install KVM and virtinst (a tool to create virtual machines), we run

yum install kvm libvirt python-virtinst qemu-kvm

Then start the libvirt daemon:

/etc/init.d/libvirtd start

To check if KVM has successfully been installed, run

virsh -c qemu:///system list

It should display something like this:

[[email protected] ~]# virsh -c qemu:///system list
Id Name State
----------------------------------

[[email protected] ~]#

If it displays an error instead, then something went wrong.

Next we need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.

To do this, we install the package bridge-utils...

yum install bridge-utils

... and configure a bridge. Create the file /etc/sysconfig/network-scripts/ifcfg-br0 (please use the IPADDR, PREFIX, GATEWAY, DNS1 and DNS2 values from the /etc/sysconfig/network-scripts/ifcfg-eth0 file); make sure you use TYPE=Bridge, not TYPE=Ethernet:

vi /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE="br0"  NM_CONTROLLED="yes"  ONBOOT=yes  TYPE=Bridge  BOOTPROTO=none  IPADDR=192.168.0.100  PREFIX=24  GATEWAY=192.168.0.1  DNS1=8.8.8.8  DNS2=8.8.4.4  DEFROUTE=yes  IPV4_FAILURE_FATAL=yes  IPV6INIT=no  NAME="System br0"

Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as follows (comment out BOOTPROTO, IPADDR, PREFIX, GATEWAY, DNS1, and DNS2 and add BRIDGE=br0):

vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"  NM_CONTROLLED="yes"  ONBOOT=yes  HWADDR=00:1E:90:F3:F0:02  TYPE=Ethernet  #BOOTPROTO=none  #IPADDR=192.168.0.100  #PREFIX=24  #GATEWAY=192.168.0.1  #DNS1=8.8.8.8  #DNS2=8.8.4.4  DEFROUTE=yes  IPV4_FAILURE_FATAL=yes  IPV6INIT=no  NAME="System eth0"  UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  BRIDGE=br0

Restart the network...

/etc/init.d/network restart

... and run

ifconfig

It should now show the network bridge (br0):

[[email protected] ~]# ifconfig
br0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:103 errors:0 dropped:0 overruns:0 frame:0
TX packets:79 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7434 (7.2 KiB) TX bytes:21398 (20.8 KiB)

eth0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:19511 errors:0 dropped:0 overruns:0 frame:0
TX packets:11592 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25980124 (24.7 MiB) TX bytes:1104371 (1.0 MiB)
Interrupt:28 Base address:0x6000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3608 (3.5 KiB) TX bytes:3608 (3.5 KiB)

virbr0 Link encap:Ethernet HWaddr 6A:12:69:18:2B:05
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

[[email protected] ~]#

3 Installing virt-viewer Or virt-manager On Your Fedora 15 Desktop

Fedora 15 Desktop:

We need a means of connecting to the graphical console of our guests - we can use virt-manager for this. I'm assuming that you're using a Fedora 15 desktop.

Become root...

su

... and run...

yum install virt-manager libvirt qemu-system-x86 openssh-askpass

... to install virt-manager.

(If you're using an Ubuntu 11.04 desktop, you can install virt-manager as follows:

sudo apt-get install virt-manager

)

4 Creating A Debian Squeeze Guest (Image-Based) From The Command Line

CentOs 6.0 KVM Host:

Now let's go back to our CentOS 6.0 KVM host.

Take a look at

man virt-install

to learn how to use virt-install.

We will create our image-based virtual machines in the directory /var/lib/libvirt/images/ which was created automatically when we installed KVM in chapter two.

To create a Debian Squeeze guest (in bridging mode) with the name vm10, 512MB of RAM, two virtual CPUs, and the disk image /var/lib/libvirt/images/vm10.img (with a size of 12GB), insert the Debian Squeeze Netinstall CD into the CD drive and run

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /dev/cdrom --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm

Of course, you can also create an ISO image of the Debian Squeeze Netinstall CD (please create it in the /var/lib/libvirt/images/ directory because later on I will show how to create virtual machines through virt-manager from your Fedora desktop, and virt-manager will look for ISO images in the /var/lib/libvirt/images/ directory)...

dd if=/dev/cdrom of=/var/lib/libvirt/images/debian-6.0.2.1-amd64-netinst.iso

... and use the ISO image in the virt-install command:

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.2.1-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm

The output is as follows:

[[email protected] ~]# virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.2.1-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm

Starting install...
Allocating 'vm10.img' | 12 GB 00:00
Creating domain... | 0 B 00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[[email protected] ~]#

Tags:

Related Articles

  • Virtualization With KVM On A CentOS 6.0 Server

    Virtualization With KVM On A CentOS 6.0 ServerAugust 27

    Virtualization With KVM On A CentOS 6.0 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.0 server. I will show how to create image-

  • Virtualization With KVM On A CentOS 6.2 Server

    Virtualization With KVM On A CentOS 6.2 ServerMarch 10

    Virtualization With KVM On A CentOS 6.2 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.2 server. I will show how to create image-

  • Virtualization With KVM On A CentOS 6.3 Server

    Virtualization With KVM On A CentOS 6.3 ServerMay 26

    Virtualization With KVM On A CentOS 6.3 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.3 server. I will show how to create image-

  • Virtualization With KVM On A CentOS 6.4 Server

    Virtualization With KVM On A CentOS 6.4 ServerFebruary 2

    Virtualization With KVM On A CentOS 6.4 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.4 server. I will show how to create image-

  • Virtualization With KVM On A CentOS 5.2 ServerSeptember 20

    Thank you for another excellent guide, Falko. I followed your directions on using KVM with CentOS, but with CentOS 5.3. I also used a Windows Vista guest in my testing. To do this I had to search for a newer RPM of KVM84, as the Vista installer would

  • Virtualization With KVM On An OpenSUSE 12.2 Server

    Virtualization With KVM On An OpenSUSE 12.2 ServerDecember 15

    Virtualization With KVM On An OpenSUSE 12.2 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on an OpenSUSE 12.2 server. I will show how to creat

  • Virtualization With KVM On A Mandriva 2010.0 Server

    Virtualization With KVM On A Mandriva 2010.0 ServerApril 6

    Virtualization With KVM On A Mandriva 2010.0 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a Mandriva 2010.0 server. I will show how to cre

  • Virtualization With KVM On An OpenSUSE 11.4 Server

    Virtualization With KVM On An OpenSUSE 11.4 ServerAugust 10

    Virtualization With KVM On An OpenSUSE 11.4 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on an OpenSUSE 11.4 server. I will show how to creat

  • Virtualization With KVM On An OpenSUSE 12.1 Server

    Virtualization With KVM On An OpenSUSE 12.1 ServerSeptember 3

    Virtualization With KVM On An OpenSUSE 12.1 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on an OpenSUSE 12.1 server. I will show how to creat

  • Virtualization With KVM On An OpenSUSE 11.3 Server

    Virtualization With KVM On An OpenSUSE 11.3 ServerNovember 23

    Virtualization With KVM On An OpenSUSE 11.3 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on an OpenSUSE 11.3 server. I will show how to creat

  • KVM Virtualization With Enomalism 2 On A Fedora 10 Server

    KVM Virtualization With Enomalism 2 On A Fedora 10 ServerJanuary 20

    KVM Virtualization With Enomalism 2 On A Fedora 10 Server Version 1.0 Author: Falko Timme Enomalism ECP (Elastic Computing Platform) provides a web-based control panel that lets you design, deploy, and manage virtual machines on one or more host syst

  • Virtualization With KVM On Ubuntu 12.10

    Virtualization With KVM On Ubuntu 12.10April 7

    Virtualization With KVM On Ubuntu 12.10 Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on an Ubuntu 12.10 server. I will show how to create image-base

  • Virtualization With KVM On A Debian Squeeze Server

    Virtualization With KVM On A Debian Squeeze ServerJuly 10

    Virtualization With KVM On A Debian Squeeze Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a Debian Squeeze server. I will show how to creat

  • Virtualization With KVM On A Fedora 14 Server

    Virtualization With KVM On A Fedora 14 ServerNovember 3

    Virtualization With KVM On A Fedora 14 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a Fedora 14 server. I will show how to create image-ba

  • Virtualization With KVM On A Fedora 17 Server

    Virtualization With KVM On A Fedora 17 ServerJanuary 31

    Virtualization With KVM On A Fedora 17 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a Fedora 17 server. I will show how to create image-ba

  • Virtualization With KVM On A Fedora 12 Server

    Virtualization With KVM On A Fedora 12 ServerMarch 12

    Virtualization With KVM On A Fedora 12 Server Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on a Fedora 12 server. I will show how to create image-ba

  • Virtualization With KVM On Ubuntu 10.10

    Virtualization With KVM On Ubuntu 10.10April 30

    Virtualization With KVM On Ubuntu 10.10 Version 1.0 Author: Falko Timme Follow me on Twitter This guide explains how you can install and use KVM for creating and running virtual machines on an Ubuntu 10.10 server. I will show how to create image-base

  • Re: Virtualization With KVM On Ubuntu 8.10 (Problems with LVM)

    Re: Virtualization With KVM On Ubuntu 8.10 (Problems with LVM)December 4

    This question is specific to part 6 of Virtualization With KVM On Ubuntu 8.10, specifically Creating an LVM based VM. I've followed the guide exactly and yet everytime after I've converted the qcow2 image to a LV using Code: qemu-img convert disk0.qc

  • Virtualization With KVM On Ubuntu 9.10

    Virtualization With KVM On Ubuntu 9.10February 9

    Virtualization With KVM On Ubuntu 9.10 Version 1.0 Author: Falko Timme Follow me on Twitter This guide explans how you can install and use KVM for creating and running virtual machines on an Ubuntu 9.10 server. I will show how to create image-based v

  • CentOS 6 KVM host with CentOS 6 guests kvm-clock enabled major time driftFebruary 13

    I have a CentOS 6 KVM host with CentOS 6 guests, all 64bit. The host syncs time from NTP and has remained bang on. All the guests have kvm-clock listed as current_clocksource but over the last 3 weeks they have drifted by about 4 hours from the host.

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.559 s.