Category Archives: Howto Tutorials (EN)

Knowledge Network for Tutorials, Howto’s, Workaround, DevOps Code for Professionals.

KVM Hypervisor on CentOS7

Installing KVM on CentOS


KVM is an open source hardware virtualization software that allows Linux-based and Windows-based virtual machines to run simultaneously. Called a Kernel-based Virtual Machine, KVM is an alternative to VMware ESXi and Xen, where by installing the KVM package, loading the KVM module into the current kernel and forming a hypervisor from a Linux machine.

KVM Hypervisor on CentOS7

This article shows how to install a KVM hypervisor on CentOS 7.x and RHEL 7.x to install virtual machines afterwards.

KVM Hypervisor Installation

Before proceeding with the KVM installation, check whether the CPU of the system supports hardware virtualization. To do this, perform the following command in the root shell

grep -E '(vmx|svm)' /proc/cpuinfo

The word vmx or svm should appear in the output, otherwise the CPU does not support virtualization. It may be worth going into the BIOS system to activate the VT-x boot setting.

The KVM packages and their modules are installed.

yum install -y qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils

The KVM service can now be activated and started.

systemctl enable libvirtd
systemctl start libvirtd

We check if the KVM modules have actually been started.

lsmod | grep kvm
kvm_intel 162153 0
kvm 525409 1 kvm_intel

If there is a Minimal CentOS 7 or RHEL 7 installation, the virt-manager does not start, so we still have to install X-Window.

yum install -y "@X Window System" xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils

Restart the server and then try to start the virtual manager.

virt-manager

Before we start deploying VMs, let’s first create a bridge interface. The bridge interface is required if you want to access virtual machines from outside the network to the hypervisor. In our example, the Ethernet interface is called ifcfg-eth0.

cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-br0

Now edit the interface file ifcfg-eth0 and enter the following:

vi ifcfg-eth0

TYPE=Ethernet
NM_CONTROLLED="no"
BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0

Edit the ifcfg-br0 bridge file and specify the following:

vi ifcfg-br0

TYPE=Bridge
NM_CONTROLLED="no"
BOOTPROTO=static
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.91.40
NETMASK=255.255.255.0
GATEWAY=192.168.91.1
DNS1=192.168.91.50

Restart the network service to activate the bridge.

systemctl restart network

Check the bridge interface with the following command:

ip addr show br0

If you prefer to make the Network Manager, you can create the bridge interface as follows:

nmcli c add type bridge autoconnect yes con-name br0 ifname br0
nmcli c modify br0 ipv4.addresses 192.168.91.40/24 ipv4.method manual
nmcli c modify br0 ipv4.gateway 192.168.91.1
nmcli c modify br0 ipv4.dns 192.168.91.50
nmcli c delete eth0
nmcli c add type bridge-slave autoconnect yes con-name eth0 ifname eth0 master br0
reboot
ip a

Virtual machines can now be created either from the command line with the virt-install command or from the GUI virt-manager.

In the GUI, go to the File option and click New virtual Machine.

The virtual machine is now created with the help of the wizard.

Create virtual machine

Create virtual machines from the command line:

virt-install --name=Ubuntu-16-04 --file=/var/lib/libvirt/images/ubuntu16-04.dsk --file-size=20 --nonsparse --graphics spice --vcpus=2 --ram=2048 --cdrom=ubuntu-16.04-server-amd64.iso --network bridge=br0 --os-type=linux --os-variant=generic
Starting install...
Allocating 'ubuntu16-04.dsk' | 20 GB 00:00:00
Creating domain...

From the virtual manager, the VMs are booted up and managed, the status and system load is displayed, similar to what you know from vSphere.

Illustration: KVM virtual Manager

Furthermore, virt-manager from Cygwin is executable in Windows 10, for this Cygwin64 must be installed with the Xorg server and virt-manager, with the virt-manager one connects to the KVM hypervisor.

Illustration: Cygwin virt-manager Inindung
Illustration: Cygwin virt-manager

Disable IPv6 on Ubuntu

How to disable IPv6 addresses on Ubuntu

IPv6 may be undesirable in certain situations, for systems that can run without IPv6 and only operate on IPv4, the IPv6 protocol stack can be disabled.

On Debian and Ubuntu IPv6 stack disable as follows.

sudo vi /etc/sysctl.d/99-sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

If only one certain interface should run without IPv6, e.g. ens160.

net.ipv6.conf.ens160.disable_ipv6 = 1

Save the sysctl.conf file and enable the setting.

sudo sysctl -p

If you want to deactivate IPv6 during operation, the following command applies.

echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6

Alternatively you can run this command in the terminal shell.

sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1

IPv6 is now disabled, a reboot is not necessary.

If the removal of IPv6 for running services is a disaster, e.g. SSH server, the configuration can be adjusted.

vi /etc/ssh/sshd_config

#AddressFamily any
AddressFamily inet
#or remove hash(#)
#ListenAddress 0.0.0.0
ListenAddress 0.0.0.0

Then restart the SSH daemon.

systemctl restart sshd

Postfix may also require to customize the ipv4 loopback interface.

vi /etc/postfix/main.cf

#inet_interfaces = localhost
inet_interfaces = 127.0.0.1

Checking for IPv6 addresses.

ifconfig | grep inet6

Internet Protocol version 6 (IPv6)

Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. IPv6 was developed by the Internet Engineering Task Force (IETF) to deal with the long-anticipated problem of IPv4 address exhaustion, and was intended to replace IPv4. In December 1998, IPv6 became a Draft Standard for the IETF, which subsequently ratified it as an Internet Standard on 14 July 2017.