RHEL6 – KVM Administration CookBook – Part 1

I believe, this is one of the long pending post from me. Anyway, before proceeding with the actual cook book first let’s briefly recollect the concept of virtualization. 

Virtualization is noting but creating an abstraction layer in between the Operating System and Hardware , so that the physical hardware resources can be utilized efficiently across multiple instances of operating systems running on the same hardware.

Note : Sorry about the poor Handwriting, I am still finding my comfort with the doodle :)

 We need to take a moment to discuss the hardware requirements for running virtual machines within a KVM environment. Firstly, KVM virtualization is only available on certain processor types. These processors include either Intel-VT or AMD-V technology.

To check for Intel-VT support, run the following command in a terminal window to check for the presence of vmx:

[root@gurkullinux01 ~]# grep vmx /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid

 Preparing RHEL 6 for KVM Virtualization

 

Unlike Xen, it is not necessary to run a special version of the kernel in order to support KVM. As a result KVM support is already available for use with the standard kernel via the installation of a KVM kernel module, thereby negating the need to install and boot from a special kernel.

The tools required to setup and maintain a KVM based virtualized system are not installed by default unless specifically selected during the RHEL 6 operating system installation process. To install KVM from the command prompt, execute the following command in a terminal window with root privileges:

[root@gurkullinux01 ~]# yum install kvm virt-manager libvirt
Loaded plugins: refresh-packagekit, security
ol6_UEK_latest | 1.2 kB 00:00
ol6_UEK_latest/primary | 9.7 MB 00:14
ol6_UEK_latest 218/218
ol6_latest | 1.4 kB 00:00
ol6_latest/primary | 31 MB 03:02
ol6_latest 22065/22065
virtualbox | 951 B 00:00
virtualbox/primary | 5.0 kB 00:00
virtualbox: [####################################################################################### ] 18/22Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package libvirt.x86_64 0:0.9.10-21.0.1.el6_3.7 will be updated
—> Package libvirt.x86_64 0:0.10.2-18.0.1.el6_4.9 will be an update
–> Processing Dependency: libvirt-client = 0.10.2-18.0.1.el6_4.9 for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
–> Processing Dependency: libvirt.so.0(LIBVIRT_0.9.13)(64bit) for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
–> Processing Dependency: libvirt.so.0(LIBVIRT_0.10.0)(64bit) for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
–> Processing Dependency: libvirt-qemu.so.0(LIBVIRT_QEMU_0.10.0)(64bit) for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
–> Processing Dependency: libvirt.so.0(LIBVIRT_PRIVATE_0.10.2)(64bit) for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
–> Processing Dependency: libvirt.so.0(LIBVIRT_0.10.2)(64bit) for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
–> Processing Dependency: libvirt.so.0(LIBVIRT_0.9.11)(64bit) for package: libvirt-0.10.2-18.0.1.el6_4.9.x86_64
—> Package qemu-kvm.x86_64 2:0.12.1.2-2.355.el6_4.2 will be updated
—> Package qemu-kvm.x86_64 2:0.12.1.2-2.355.el6_4.7 will be an update
–> Processing Dependency: qemu-img = 2:0.12.1.2-2.355.el6_4.7 for package: 2:qemu-kvm-0.12.1.2-2.355.el6_4.7.x86_64
—> Package virt-manager.x86_64 0:0.9.0-14.el6 will be updated
—> Package virt-manager.x86_64 0:0.9.0-18.el6 will be an update
–> Running transaction check
—> Package libvirt-client.x86_64 0:0.9.10-21.0.1.el6_3.7 will be updated
–> Processing Dependency: libvirt.so.0(LIBVIRT_PRIVATE_0.9.10)(64bit) for package: libvirt-python-0.9.10-21.0.1.el6_3.7.x86_64
–> Processing Dependency: libvirt-client = 0.9.10-21.0.1.el6_3.7 for package: libvirt-devel-0.9.10-21.0.1.el6_3.7.x86_64
–> Processing Dependency: libvirt-client = 0.9.10-21.0.1.el6_3.7 for package: libvirt-python-0.9.10-21.0.1.el6_3.7.x86_64
—> Package libvirt-client.x86_64 0:0.10.2-18.0.1.el6_4.9 will be an update
—> Package qemu-img.x86_64 2:0.12.1.2-2.355.el6_4.2 will be updated
—> Package qemu-img.x86_64 2:0.12.1.2-2.355.el6_4.7 will be an update
–> Running transaction check
—> Package libvirt-devel.x86_64 0:0.9.10-21.0.1.el6_3.7 will be updated
—> Package libvirt-devel.x86_64 0:0.10.2-18.0.1.el6_4.9 will be an update
—> Package libvirt-python.x86_64 0:0.9.10-21.0.1.el6_3.7 will be updated
—> Package libvirt-python.x86_64 0:0.10.2-18.0.1.el6_4.9 will be an update
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Updating:
libvirt x86_64 0.10.2-18.0.1.el6_4.9 ol6_latest 2.3 M
qemu-kvm x86_64 2:0.12.1.2-2.355.el6_4.7 ol6_latest 1.3 M
virt-manager x86_64 0.9.0-18.el6 ol6_latest 1.0 M
Updating for dependencies:
libvirt-client x86_64 0.10.2-18.0.1.el6_4.9 ol6_latest 4.0 M
libvirt-devel x86_64 0.10.2-18.0.1.el6_4.9 ol6_latest 863 k
libvirt-python x86_64 0.10.2-18.0.1.el6_4.9 ol6_latest 463 k
qemu-img x86_64 2:0.12.1.2-2.355.el6_4.7 ol6_latest 472 k

Transaction Summary
================================================================================================================================
Upgrade 7 Package(s)

Total size: 10 M
Total download size: 9.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): libvirt-0.10.2-18.0.1.el6_4.9.x86_64.rpm | 2.3 MB 00:12
(2/6): libvirt-client-0.10.2-18.0.1.el6_4.9.x86_64.rpm | 4.0 MB 00:27
(3/6): libvirt-devel-0.10.2-18.0.1.el6_4.9.x86_64.rpm | 863 kB 00:06
(4/6): libvirt-python-0.10.2-18.0.1.el6_4.9.x86_64.rpm | 463 kB 00:04
(5/6): qemu-img-0.12.1.2-2.355.el6_4.7.x86_64.rpm | 472 kB 00:02
(6/6): qemu-kvm-0.12.1.2-2.355.el6_4.7.x86_64.rpm | 1.3 MB 00:09
——————————————————————————————————————————–
Total 131 kB/s | 9.4 MB 01:13
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : libvirt-client-0.10.2-18.0.1.el6_4.9.x86_64 1/14
Updating : 2:qemu-img-0.12.1.2-2.355.el6_4.7.x86_64 2/14
Updating : libvirt-python-0.10.2-18.0.1.el6_4.9.x86_64 3/14
Updating : virt-manager-0.9.0-18.el6.x86_64 4/14
Updating : 2:qemu-kvm-0.12.1.2-2.355.el6_4.7.x86_64 5/14
Updating : libvirt-0.10.2-18.0.1.el6_4.9.x86_64 6/14
Updating : libvirt-devel-0.10.2-18.0.1.el6_4.9.x86_64 7/14
Cleanup : virt-manager-0.9.0-14.el6.x86_64 8/14
Cleanup : libvirt-devel-0.9.10-21.0.1.el6_3.7.x86_64 9/14
Cleanup : libvirt-0.9.10-21.0.1.el6_3.7.x86_64 10/14
Cleanup : libvirt-python-0.9.10-21.0.1.el6_3.7.x86_64 11/14
Cleanup : 2:qemu-kvm-0.12.1.2-2.355.el6_4.2.x86_64 12/14
Cleanup : 2:qemu-img-0.12.1.2-2.355.el6_4.2.x86_64 13/14
Cleanup : libvirt-client-0.9.10-21.0.1.el6_3.7.x86_64 14/14
Verifying : libvirt-devel-0.10.2-18.0.1.el6_4.9.x86_64 1/14
Verifying : virt-manager-0.9.0-18.el6.x86_64 2/14
Verifying : 2:qemu-img-0.12.1.2-2.355.el6_4.7.x86_64 3/14
Verifying : libvirt-client-0.10.2-18.0.1.el6_4.9.x86_64 4/14
Verifying : 2:qemu-kvm-0.12.1.2-2.355.el6_4.7.x86_64 5/14
Verifying : libvirt-0.10.2-18.0.1.el6_4.9.x86_64 6/14
Verifying : libvirt-python-0.10.2-18.0.1.el6_4.9.x86_64 7/14
Verifying : libvirt-0.9.10-21.0.1.el6_3.7.x86_64 8/14
Verifying : 2:qemu-kvm-0.12.1.2-2.355.el6_4.2.x86_64 9/14
Verifying : libvirt-client-0.9.10-21.0.1.el6_3.7.x86_64 10/14
Verifying : 2:qemu-img-0.12.1.2-2.355.el6_4.2.x86_64 11/14
Verifying : libvirt-devel-0.9.10-21.0.1.el6_3.7.x86_64 12/14
Verifying : virt-manager-0.9.0-14.el6.x86_64 13/14
Verifying : libvirt-python-0.9.10-21.0.1.el6_3.7.x86_64 14/14

Updated:
libvirt.x86_64 0:0.10.2-18.0.1.el6_4.9 qemu-kvm.x86_64 2:0.12.1.2-2.355.el6_4.7 virt-manager.x86_64 0:0.9.0-18.el6

Dependency Updated:
libvirt-client.x86_64 0:0.10.2-18.0.1.el6_4.9 libvirt-devel.x86_64 0:0.10.2-18.0.1.el6_4.9
libvirt-python.x86_64 0:0.10.2-18.0.1.el6_4.9 qemu-img.x86_64 2:0.12.1.2-2.355.el6_4.7

Complete!
[root@gurkullinux01 ~]# lsmod|grep kvm
kvm_intel 55356 0
kvm 372790 1 kvm_intel
[root@gurkullinux01 ~]#
[root@gurkullinux01 ~]# service libvirtd status
libvirtd (pid 7218) is running…
[root@gurkullinux01 ~]#

A KVM virtual machine running on RHEL 6 has two options in terms of networking connectivity.

One option is Host only internal network, that means the virtual machines can connect to each other with separate IPs within themselves but from the outside world they have will communicate by Host IP Using Network Adress Translation (NAT). 

Second Option is having a separate IP for each individual virtual machine. To achieve this The host system will have a network bridge interface to which all the guest VMs will connect using their own IPs.

 

 

 How do we create A network bridge?

[root@gurkullinux01 ~]# yum install bridge-utils
Loaded plugins: refresh-packagekit, security
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package bridge-utils.x86_64 0:1.2-9.el6 will be updated
—> Package bridge-utils.x86_64 0:1.2-10.el6 will be an update
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Updating:
bridge-utils x86_64 1.2-10.el6 ol6_latest 29 k

Transaction Summary
================================================================================================================================
Upgrade 1 Package(s)

Total download size: 29 k
Is this ok [y/N]: y
Downloading Packages:
bridge-utils-1.2-10.el6.x86_64.rpm | 29 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : bridge-utils-1.2-10.el6.x86_64 1/2
Cleanup : bridge-utils-1.2-9.el6.x86_64 2/2
Verifying : bridge-utils-1.2-10.el6.x86_64 1/2
Verifying : bridge-utils-1.2-9.el6.x86_64 2/2

Updated:
bridge-utils.x86_64 0:1.2-10.el6

Complete!
[root@gurkullinux01 ~]#

Network Configuration Before Virtual Networking:

[root@gurkullinux01 ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 44:1E:A1:D9:DA:30
inet addr:192.168.1.50 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::461e:a1ff:fed9:da30/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:51894 errors:0 dropped:0 overruns:0 frame:0
TX packets:51528 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:56119776 (53.5 MiB) TX bytes:13818556 (13.1 MiB)
Interrupt:46

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:30 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1920 (1.8 KiB) TX bytes:1920 (1.8 KiB)

virbr0 Link encap:Ethernet HWaddr 52:54:00:0B:96:21
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST 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)

In the above output, the entry for eth0 represents a physical network adaptor on the host computer. This is the connection currently used by this host to access the external network. The virbr0 entry represents the virtual network to which guest operating systems will connect if configured to do so. In order to provide the option for guest operating systems to share the eth0 connection of the host it is necessary to establish a network bridge between eth0 and the virtual machines.

If the interface to be bridged is currently running it should be taken down before proceeding:

The next step is to modify the script file for the physical network device. In this example the device is eth0 so we need to edit the ifcfg-eth0 file to add a BRIDGE= line. For the purposes of this example we will name the interface bridge0:

[root@gurkullinux01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
HWADDR=44:1e:a1:d9:da:30
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID=”e261551a-c11f-40d7-84ce-c2a7a10cc3ef”
IPV6INIT=no
USERCTL=no
BRIDGE=”bridge0″

 

The next step is to create a script file for the bridge interface. The name of this file must take the form ifcfg-<bridgename> where <bridgename> matches the name of the bridge defined in the BRIDGE= directive outlined above. Given this requirement, we will name the file ifcfg-bridge0. The contents of this file for this example will read as follows:

[root@gurkullinux01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bridge0
DEVICE=”bridge0″
TYPE=”Bridge”
BOOTPROTO=”none”
IPADDR=192.168.1.50
GATEWAY=192.168.1.254
DNS1=192.168.1.254
ONBOOT=”yes”
DELAY=0

Note that the DEVICE= line must refer to the bridge name previously specified (i.e. bridge0 in this instance). Save the file and then start up both interfaces :

Note : you will lose the network connection with this command, please perform this task from the console session.

           # Server network restart

 

Networking Configuration after the Bridge network Configuration

[root@gurkullinux01 ~]# ifconfig -a
bridge0 Link encap:Ethernet HWaddr 44:1E:A1:D9:DA:30
inet addr:192.168.1.50 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::461e:a1ff:fed9:da30/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4438 (4.3 KiB) TX bytes:8159 (7.9 KiB)

eth0 Link encap:Ethernet HWaddr 44:1E:A1:D9:DA:30
inet6 addr: fe80::461e:a1ff:fed9:da30/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:54712 errors:0 dropped:0 overruns:0 frame:0
TX packets:55851 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:56515070 (53.8 MiB) TX bytes:18686228 (17.8 MiB)
Interrupt:46

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:46 errors:0 dropped:0 overruns:0 frame:0
TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3392 (3.3 KiB) TX bytes:3392 (3.3 KiB)

 

Now, from the external network we communicate to the host using the bridged interface which is actually built on top of a physical interface eth0.

Now Enable firewall Settings Rules to access connection on bridge interface by adding below rule on /etc/sysconfig/iptables, before the commit statement

# Rule to Enable incoming connections on Bridge Interface
-A GURKUL-Firewall-1-INPUT -i bridge0 -j ACCEPT

 

Once you have configured the bridge interface, you can start the virtual manager and start installing the Guest Virtual Machine as shown in the below video.

 

 

Ok.. you will have second part of the Cook book very soon…. keep following. 

 

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

2 Responses

  1. sahil says:

    Dear Sir,

    I am getting error please help me..

    [root@vinay ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    HWADDR=50:E5:49:56:E2:37
    TYPE=Ethernet
    UUID=03dab609-d7ce-45a2-bd56-f756bd2d9156
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=none
    IPV6INIT=no
    USERCTL=no
    IPV6INIT=no
    USERCTL=no
    BRIDGE=”bridge0″
    [root@vinay ~]# cat /etc/sysconfig/network-scripts/ifcfg-bridge0
    DEVICE=”bridge0″
    TYPE=”Bridge”
    BOOTPROTO=”none”
    IPADDR=192.168.1.21
    GATEWAY=192.168.1.1
    DNS1=8.8.8.8
    DNS2=202.159.217.198
    ONBOOT=”yes”
    DELAY=0
    [root@vinay ~]# /etc/init.d/network restart
    Shutting down interface eth0: [ OK ]
    Shutting down loopback interface: [ OK ]
    Bringing up loopback interface: [ OK ]
    Bringing up interface eth0: Error: Connection activation failed: Master connection not found or invalid
    [FAILED]
    Bringing up interface bridge0: Error: Connection activation failed: Failed to determine connection’s virtual interface name
    [FAILED]
    [root@vinay ~]# /etc/init.d/network restart^C
    [root@vinay ~]#

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us