Setting Up a KVM Virtual Machine
This guide walks you through installing KVM and Libvirt tools on your Linux desktop, and creating a virtual machine.
Step 1: Install KVM, Libvirt, and Virt-Manager
Check that your hardware supports virtualization:
grep -E -c '(vmx|svm)' /proc/cpuinfo
The output of that command should reflect the total number of logical CPU cores available.
This command is taking a count of the number of CPU cores that support hardware virtualization:
vmx=Intel VT-x support (for Intel CPUs)svm=AMD-V support (for AMD CPUs)
Install the necessary packages to enable virtualization and manage VMs:
sudo yum install virt-manager libvirt libvirt-daemon-kvm qemu-kvm
virt-manageris a desktop user interface for managing virtual machines throughlibvirtlibvirtis an open-source API, daemon, and management tool for managing platform virtualization across different hypervisors like KVMslibvirt-daemon-kvmrefers to thelibvirtddaemon, which is part of the libvirt virtualization management system, and is specifically configured to manage KVMs (Kernel-based Virtual Machine).qemu-kvmis a package that integrates QEMU (Quick Emulator) and KVM to enable efficient virtualization on Linux systems.
Enable
libvirtdby running:
sudo systemctl enable libvirtd
Step 2: Verify Installation
Check if KVM is available:
lsmod | grep kvm
Check if
libvirtdis running:
sudo systemctl status libvirtd
Step 3: Create a Virtual Machine
Open the
virt-managerGUI by running:
virt-manager
By default, virt-manager is connected directly to localhost. By right clicking on the localhost (QEMU/KVM), selecting “details”, and then the “storage” tab, you can add a new storage volume and allocate space for files stored on your virtual machine.
Once you have created a new storage volume, you can begin creating a new virtual machine from the main window.
Follow the steps prompted by the wizard window and specify which local install media you will use. For this project you can use the same ISO image as what is installed on your laptop, or choose a different image.
Step 4: Enable Networking Between Host and VM
To allow SSH access, configure virtual networking:
Refer to: Libvirt Virtual Networking
By default, virt-manager may already have NAT forwarding enabled.
Resources
How to Install KVM and Libvirt: Step by step in-depth installation guide for KVM and Libvirt tools
How to Create Virtual Machines in Linux Using KVM: Step by step in-depth installation guide for installing and configuring virt-manager application and machines
Installing KVM Ubuntu: Guide for installing KVM tools and using KVM and virt-manager with Ubuntu
Libvirt Virtual Networking: Create a bridged interface so your VM can access the network and internet