How to install KVM in RHEL7

kvm

KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.

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.

More info about KVM.

 

Prerequisites:

  1. 64-bit machine
  2. Virtualization is enabled in BIOS
  3. CPU supports VM-extension (AMD-V or Intel’s VT-X)

 

My environment:

[root@rhel7 ~]# hostnamectl status
   Static hostname: rhel7.jefrey.io
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 35025622daf04dff8104f45566d7e53a
           Boot ID: 42e1a45da6ac4a81ab38dc634a3fde3d
  Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64
[root@rhel7 ~]#
[root@rhel7 ~]# mount -o loop /dev/cdrom /mnt/iso
[root@rhel7 ~]#
[root@rhel7 ~]# cp /mnt/iso/media.repo /etc/yum.repos.d/dvd.repo
[root@rhel7 ~]# vi /etc/yum.repos.d/dvd.repo
[root@rhel7 ~]# cat /etc/yum.repos.d/dvd.repo
[InstallMedia]
name=RHEL-7.0 Server.x86_64
mediaid=1399449226.171922
metadata_expire=-1
gpgcheck=0
cost=500
enabled=1
baseurl=file:///mnt/iso
[root@rhel7 ~]#

Install KVM and related packages:

[root@rhel7 ~]# yum -y install qemu-kvm libvirt virt-install bridge-utils virt-manager virt-viewer libguestfs-tools
...
Complete!
[root@rhel7 ~]#
[root@rhel7 ~]# lsmod | grep kvm
kvm_intel             138567  0 
kvm                   441119  1 kvm_intel
[root@rhel7 ~]# 
[root@rhel7 ~]# 
[root@rhel7 ~]# systemctl start libvirtd
[root@rhel7 ~]# 
[root@rhel7 ~]# systemctl enable libvirtd

/kvm will be my VM datastore – need to set SELinux label:

[root@rhel7 ~]# rpm -qa | grep policycore
policycoreutils-python-2.2.5-11.el7.x86_64
policycoreutils-2.2.5-11.el7.x86_64
[root@rhel7 ~]# 
[root@rhel7 ~]# 
[root@rhel7 ~]# ls -lZ / | grep kvm
drwxr-xr-x. root root system_u:object_r:etc_runtime_t:s0 kvm
[root@rhel7 ~]# 
[root@rhel7 ~]# ls -lZ /kvm
[root@rhel7 ~]# 
[root@rhel7 ~]# semanage fcontext --add -t virt_image_t '/kvm(/.*)?'
[root@rhel7 ~]# 
[root@rhel7 ~]# semanage fcontext -l | grep virt_image_t
/kvm(/.*)?                                         all files          system_u:object_r:virt_image_t:s0 
/var/lib/imagefactory/images(/.*)?                 all files          system_u:object_r:virt_image_t:s0 
/var/lib/libvirt/images(/.*)?                      all files          system_u:object_r:virt_image_t:s0 
[root@rhel7 ~]# 
[root@rhel7 ~]# restorecon -R -v /kvm
restorecon reset /kvm context system_u:object_r:etc_runtime_t:s0->system_u:object_r:virt_image_t:s0
[root@rhel7 ~]# 
[root@rhel7 ~]# ls -laZ /kvm
drwxr-xr-x. root root system_u:object_r:virt_image_t:s0 .
drwxr-xr-x. root root system_u:object_r:root_t:s0      ..
[root@rhel7 ~]#

Check the new IP configuration:

[root@rhel7 ~]# ifconfig 
eno1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 2c:27:d7:ae:ea:f1  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 2405  bytes 1481070 (1.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2405  bytes 1481070 (1.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::fc54:ff:fe1e:123f  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:1e:12:3f  txqueuelen 0  (Ethernet)
        RX packets 467  bytes 43711 (42.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 231  bytes 125372 (122.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.118  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2404:e800:ea0a:f0:be77:37ff:feb8:2c75  prefixlen 64  scopeid 0x0<global>
        inet6 fd14:828:7c50:0:be77:37ff:feb8:2c75  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::be77:37ff:feb8:2c75  prefixlen 64  scopeid 0x20<link>
        ether bc:77:37:b8:2c:75  txqueuelen 1000  (Ethernet)
        RX packets 1576  bytes 477726 (466.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1634  bytes 846931 (827.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@rhel7 ~]#

Now I’m ready to create VMs!

Leave a Reply

Your email address will not be published. Required fields are marked *