Create Virtual Machines (VM) in Linux Using KVM

Create VM in Linux using KVM
This tutorial discusses the introduction of KVM (Kernel-based Virtual Machine), features, and steps to create a VM (virtual machine) using KVM under RedHat-based-distributions, such as RHEL/CentOS7 and Fedora 21.

 

Kernel-based Virtual Machine (KVM) is a complete virtualization solution for Linux on AMD 64 and Intel 64 hardware. KVM has been included in the mainline Linux kernel since the 2.6.20 version. It is fast and stable for most workloads, and it allows users to use the kernel to function as a hypervisor. KVM provides hardware-assisted virtualization for a wide variety of guest operating systems, including Linux, Solaris, BSD, Windows, Haiku, Plan 9, ReactOS, AROS Research Operating System, and macOS. Additionally, it provides paravirtualization support for Linux, Plan 9, OpenBSD, NetBSD, FreeBSD, and Windows guests using the VirtIO API. In this tutorial, we will learn about the features of KVM and the steps to create a VM (virtual machine) using KVM under RedHat based-distributions, such as RHEL/CentOS7 and Fedora 21.

 

Features of Kernel-based Virtual Machine

Users will gain many useful features and advantages when they use KVM to deploy their virtual platforms or machines. KVM (Kernel-based Virtual Machine) hypervisor will support the following features:

1. Over-committing: This feature helps users allocate more virtualized memory or CPUs than the available resources on the system.

2. Thin provisioning: This feature allows flexible storage allocation and available space optimization for every guest virtual machine.

3. Disk I/O throttling: KVM allows users to set a limit on disk I/O requests sent from virtual machines (VMs) to the host system.

4. Automatic NUMA balancing: KVM helps to improve the performance of the applications running on the NUMA (Non-Uniform Memory Access) hardware systems.

5. Virtual CPU hot add capability: This feature offered by KVM can increase the processing power as needed on running VMs (virtual machines) without downtime.

 

Prerequisites 

Ensure that the user system has the hardware virtualization extensions:

For Intel-based hosts, verify the CPU virtualization extension [vmx] are available by executing the following command:

 

[root@server ~]# grep -e 'vmx' /proc/cpuinfo

 

For AMD-based hosts, verify the CPU virtualization extension [svm] are available by executing the following command:

 

[root@server ~]# grep -e 'svm' /proc/cpuinfo

 

If there is no output, make sure that virtualization extensions are enabled in BIOS. In order to verify that KVM modules are loaded in the kernel (it should be loaded by default) by executing the following command: 

 

[root@server ~]# lsmod | grep kvm

 

The output of the above command should contain kvm_intel for intel-based hosts or kvm_amd for amd-based hosts.

 

Before starting, the user will need the root account or non-root user with sudo privileges configured on their system and ensure that their system is up-to-date. For that, execute the following command: 

 

[root@server ~]# yum update

 

Make sure that Selinux is in Permissive mode by executing the following command:

 

[root@server ~]# setenforce 0

 

Step 1: KVM Installation and Deployment 

1. First, install qemu-img and qemu-kvm packages by executing the following command. These packages provide the disk image manager and user-level KVM.

 

[root@server ~]# yum install qemu-img qemu-kvm

 

2. Next, install the below tools to administrate the platform, such as:

  • virt-manager provides a graphical user interface (GUI) tool to administrate the user’s virtual machines.
  • libvirt-client offers a command-line tool to administrate the user’s virtual environment. This tool is called virsh.
  • virt-install provides the command “virt-install” to create virtual machines from the command-line interface (CLI).
  • libvirt offers the host-side and server-side libraries for interacting with hypervisors and host systems.

 

[root@server ~]# yum install virt-manager libvirt libvirt-python libvirt-client

 

3. RHEL/CentOS7 users also require additional package groups, such as Virtualization Platform, Virtualization Client, and Virtualization Tools to install.

 

[root@server ~]#yum groupinstall virtualization-client virtualization-platform virtualization-tools

 

4. The virtualization daemon that manages the platform is “libvirtd”. Execute the following command to restart libvirtd:

 

[root@server ~]#systemctl restart libvirtd

 

5. After restarting the daemon, then execute the following command to check its status:

 

[root@server ~]#systemctl status libvirtd

 

Step 2: Create Virtual Machines Using KVM 

1. Although virt-manager is a GUI-based tool, users could also launch/start virt-manager from the terminal and GUI.

 

[root@server ~]#virt-manager

 

Using GNOME:

Create VM in Linux using KVM 1

 

Using GNOME Classic: 

 

Create VM in Linux using KVM 2

 

2. After starting the tool, a window will open: 

3. By default, users will find the manager is connected directly to the local host. Fortunately, they could use the same tool to manage another host remotely. Select the Add Connection option from the File tab.

Check the Connect to remote host option, then provide the Hostname/IP of the remote server. If the user needs to establish the connection to the remote host every time the manager starts, just check the Auto Connect option.

4. Return to the localhost; before creating a new virtual machine, the user should decide where to store the files. Users should create the Volume Disk (Virtual disk / Disk image ) for their virtual machine.

Right-click on the localhost and select the Details option and then select the Storage tab.

 

Create VM in Linux using KVM 5

 

5. Next, press the New Volume button and enter the name of the user’s new virtual disk (Volume Disk). After that, enter the size that the user wants/needs in the Max Capacity section.

 

Create VM in Linux using KVM 6

 

6. After that, users can view a label of the new Volume Disk in the list, as shown below:

 

Create VM in Linux using KVM 7

 

 Also, note the new disk image (Volume Disk) path. By default, it will be under the /var/lib/libvirt/images directory. Users can verify it by executing the following command:

 

[root@server Downloads]# ls -l /var/lib/libvirt/images
-rw-------. 1 root root 10737418240 Aug  3 16:47 vm1Storage.img

 

7. Now, press the VM button in the main window to create a new VM. This will open the below wizard window: 

 

Create VM in Linux using KVM 8

 

8. Select the installation method which we will be using to create the virtual machine from the list. In this tutorial, we will be selecting the Local install media option.

 

9. Next, specify the type of Local install media. There are two types: From ISO image and From physical [CDROM/DVD]. In this tutorial, we will be using the ISO image method. Then, enter or browse the path of the ISO image: 

 

Create VM in Linux using KVM 9

 

 >> Note: Unfortunately, there’s a silly bug for those using RHEL/CentOS7. This bug prevents the users from installing VM using physical [CDROM/DVD]; they will find this option greyed out.

 

10. In the storage section, use the virtual disk that we have created early, as shown below: 

 

Create VM in Linux using KVM 10

 

 11. Finally, enter the virtual machine name. 

 

Create VM in Linux using KVM 11

 

If the user wants to change some configuration or do some customization, check the ‘Customize configuration before install’ option. Then, click the Finish button and wait seconds. After the installation, a control console will appear for the Guest operating system to manage.

 

Conclusion 

This tutorial presents the introduction of KVM (Kernel-based Virtual Machine) and the steps to create a VM (virtual machine) using KVM under RedHat-based-distributions, such as RHEL/CentOS7 and Fedora 21. Hope this tutorial was helpful, and do reach out to us if you have any queries or suggestions.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

KVM Management Services

Focus on your business, and let us take care of your KVM Servers!
From what you are reading, it seems you are interested in KVM and related technologies. If you have a moment to spare, please take a look at our KVM Management plan, which might interest you even more!
KVM Management Plan

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

ServerHealers uses cookies.