Monthly Archives: September 2015

Setting up KVM On CentOS7/RHEL7.0

Raw Steps –

 

1- Checkcing if system does support Intel VT and AMD-V for Virtualization Support.

This is hardware accelerated virtualization platform to support multiple unmodified OS version to run simultaneously on x86 platform without any issue.

Checking the following parameter on system to ensure if we do have the following features avaiable for virtualization

vmx — Intel VT-x, virtualization support enabled in BIOS.
svm — AMD SVM,virtualization enabled in BIOS.
lm – Can run 64-bit machines.
aes – Applications performing encryption and decryption using the Advanced Encryption Standard on Intel and AMD cpus.
[root@ip-172-31-14-165 ~]# egrep –color -i “vmx|svm” /proc/cpuinfo

2- Installing KVM package

[root@ip-172-31-14-165 ~]# yum -y install kvm virt-manager libvirt virt-install qemu-kvm xauth

 

3- Networking –

(i) Enabling IP forwarding for ethernet.
[root@ip-172-31-14-165 ~]# echo -e “net.ipv4.ip_forward = 1\n” >> /etc/sysctl.d/99-sysctl.conf
[root@ip-172-31-14-165 ~]# sysctl -p /etc/sysctl.d/99-sysctl.conf
net.ipv4.ip_forward = 1
[root@ip-172-31-14-165 ~]#

(ii) Creating virbr0 interface

Commenting out IPADDR, NETMASK, GATEWAY & added BRIDGE element as below. you can have multiple nics, can create bond for redundency purpose. I have chosen single nic as I dont have infrastrcture available with me

[root@ip-172-31-14-165 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=”eth0″
ONBOOT=”yes”
#IPADDR=”172.31.14.165″
#NETMASK=”255.255.255.0″
#GATEWAY=”172.31.14.161″
BRIDGE=virbr0
[root@ip-172-31-14-165 ~]#
(iii) Creating BRIDGE INTERFACE virbr0 to enabling communciation of guest VMs to Hypervhost KVM. it would be NAT communicatation

[root@ip-172-31-14-165 ~]# cat /etc/sysconfig/network-scripts/ifcfg-virbr0
DEVICE=”virbr0″
TYPE=BRIDGE
ONBOOT=yes
BOOTPROTO=static
IPADDR=”172.31.14.165″
NETMASK=”255.255.255.0″
GATEWAY=”172.31.14.161″
4- check if kernal has loaded KVM module
[root@ip-172-31-14-165 ~]# lsmod | grep -i kvm
[root@ip-172-31-14-165 ~]# modprobe kvm
[root@ip-172-31-14-165 ~]# lsmod | grep -i kvm
kvm                   461126  0
[root@ip-172-31-14-165 ~]#

5- You can use the following command to check if bridge interface is enabled.

[root@ip-172-31-14-165 ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
[root@ip-172-31-14-165 ~]#
6- checking the KVM virtual list –

1- You might get the following issue. Enable libvirtd services and rest would be ok.

[root@ip-172-31-14-165 yum.repos.d]# virsh -c qemu:///system list
error: failed to connect to the hypervisor
error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock’: No such file or directory
[root@ip-172-31-14-165 yum.repos.d]# systemctl enable libvirtd
[root@ip-172-31-14-165 yum.repos.d]# systemctl start libvirtd
[root@ip-172-31-14-165 yum.repos.d]# virsh -c qemu:///system list
Id    Name                           State
—————————————————-

[root@ip-172-31-14-165 yum.repos.d]#

7 – checking what OS variant is supported on KVM. if this command does not work by any reason,you could use ‘osinfo-query os’ and it provides the list of template KVM support to host as virtual machine
[root@ip-172-31-14-165 ~]#virt-install –os-variant=list
[root@ip-172-31-7-80 ~]# osinfo-query os

Short ID             | Name                                               | Version  | ID
———————-+—————————————————-+———-+—————————————–
altlinux1.0          | Mandrake RE Spring 2001                            | 1.0      | http://altlinux.org/altlinux/1.0
altlinux2.0          | ALT Linux 2.0                                      | 2.0      | http://altlinux.org/altlinux/2.0

 

————————————————————————————-
8- Creating Virtual Machine –

[root@ip-172-31-7-80 ~]# virt-install –connect qemu:///system -n satyawin8 -r 2048 –vcpus=2 –disk path=/var/lib/libvirt/images/vmwin8.img,size=20 –graphics vnc,listen=0.0.0.0 –noautoconsole –os-type windows –os-variant win8 –accelerate –network=bridge:virbr0 –hvm –cdrom /var/X19-12345.iso
Starting install…
Allocating ‘vmwin.img’ | 20 GB 00:00:00
Creating domain… | 0 B 00:00:00

Domain installation still in progress. Waiting for installation to complete.

 

 

OVIRT is comming soon 🙂

WMI Script – Generating Physical Host Name for Virtual Machines running on Hyper-v

‘——————————————————————————————————
‘——————————————————————————————————
‘   Author         : Satyendra Singh
‘   Last Modified  : 12 Sep 2015
‘   Description    : This script will generate the physicalhostname for virtual machines ( hyper-v host)
‘   Prerequisite   : servernames.txt needs to be populated with targeted Windows server host name
‘   Version        : 1.0
‘   Outout    : This will generate ‘hypervhostout.csv’ for output
‘——————————————————————————————————
‘——————————————————————————————————

Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2

Const PATH_TO_INPUT = “servernames.txt”

Dim fso
Set fso = WScript.CreateObject(“Scripting.FileSystemObject”)

Dim shl
Set shl = WScript.CreateObject(“WScript.Shell”)

Dim input1
Set input1 = fso.OpenTextFile(PATH_TO_INPUT)
‘——————————————————————————————————————————

Dim oReg
Dim input
Dim strKeyPath
Dim strValueName
Dim strValue
Dim arrComputers
Dim output
DIm wmiService

Dim hostname
Dim line
Dim exec
Dim pingResults
Set output = fso.OpenTextFile(“hypervhostoutput.csv”,ForWriting,True)

arrComputers = Split(fso.OpenTextFile(“servernames.txt”).ReadAll, vbNewLine)
output.WriteLine “Server(P/V):” & “Hyper-v Host(Y/N):” & “Server Comment(if Applicable):”

On Error Resume Next

for each input in arrComputers

Set exec = shl.Exec(“ping -n 2 -w 1000 ” & input)
pingResults = LCase(exec.StdOut.ReadAll)

If InStr(pingResults, “reply from”) Then

WScript.Echo “Reply From: ” & input
On Error Resume Next

Set wmiService = GetObject(“winmgmts:\\” & input & “\root\CIMV2”)

If Not Err.Number = 0 Then
output.WriteLine input & “:Error: ” & Err.Description
‘output.WriteLine input & “:Error: ”
WScript.Echo input & “:Error: ” & Err.Description
On Error GoTo 0
Else
On Error GoTo 0
hostname = input
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & input & “\root\default:StdRegProv”)
strKeyPath = “SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”
strValueName = “PhysicalHostName”
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then

output.writeline input & “:” & “Physical Host”
else
output.WriteLine input & “:” & strValue
end if

End If

Else
output.WriteLine input & “:No Response”
WScript.Echo input & “:No Response”

End If

next
output.writeline vbCrLf
‘output.Close
input1.Close
Set wmiService = Nothing