Prepare a Host for KVM Virtualization

Hands-On Lab

 

Photo of Matthew Pearson

Matthew Pearson

Linux Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

In order to start creating virtual machines with KVM, it is important to properly set up the host machine. In this lab, you will need to install KVM and the related packages, configure a network bridge, and then create a virtual disk image for use with a KVM virtual machine.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Prepare a Host for KVM Virtualization

Introduction

In order to start creating virtual machines with KVM, it is important to properly set up the host machine. In this lab, you will need to install KVM and the related packages, configure a network bridge, and then create a virtual disk image for use with a KVM virtual machine.

Solution

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS
  2. Become the root user:

    sudo su -

Install KVM, libvirt (including virt-install and virt-viewer), and bridge utility packages

  1. Install the necessary packages:

    yum -y install qemu-kvm libvirt virt-install virt-viewer bridge-utils

Create a network bridge name kvmbr0

  1. Change directories to network-scripts:

    cd /etc/sysconfig/network-scripts/
  2. Edit the ifcfg-eth0 file:

    vi ifcfg-eth0

    Update to:

    DEVICE=eth0
    HWADDR=AA:BB:CC:DD:EE:FF
    TYPE=Ethernet
    ONBOOT=yes
    BRIDGE=kvmbr0
    NM_CONTROLLED=no

    > Note: Use MAC address provided

  3. Edit the ifcfg-kvmbr0 file:

    vi ifcfg-kvmbr0

    Update to:

    DEVICE=kvmbr0
    TYPE=Bridge
    BOOTPROTO=dhcp
    ONBOOT=yes
    DELAY=0
    NM_CONTROLLED=no
  4. Restart the network service:

    systemctl restart network

Using the QEMU disk image utility, create an 8 GB virtual disk named disk1.img in /var/lib/libvirt/images using qcow2 format

  1. Create an 8 GB virtual disk:

    qemu-img create -f qcow2 /var/lib/libvirt/images/disk1.img 8G

Conclusion

Congratulations — you've completed this hands-on lab!