In our previous blog post we have seen How to Install Rocky Linux 8 and now in this blog post let us see how To Install KVM on Rocky Linux 8 using Command Line Method.
Introduction
Kernel-based Virtual Machine (KVM) is an open source virtualization technology built into Linux®. Specifically, KVM lets you turn Linux into a hypervisor that allows a host machine to run multiple, isolated virtual environments called guests or virtual machines (VMs).
KVM is part of Linux. If you’ve got Linux 2.6.20 or newer, you’ve got KVM. KVM was first announced in 2006 and merged into the mainline Linux kernel version a year later. Because KVM is part of existing Linux code, it immediately benefits from every new Linux feature, fix, and advancement without additional engineering
Install and Configure KVM on Rocky Linux 8
Before you start the installation, ensure that your machine has hardware virtualization and if you are installing on a virtual machine ensure that nested virtualization is enabled. If you need help on getting the Rocky Linux 8 installed please refer our previous blogs
Step 1: Check if hardware or nested virtualization is enabled
Check if hardware virtualization is enable using command below.
cat /proc/cpuinfo | egrep "vmx|svm"
If using VM running in virtual-box use command below to enable nested virtualization.
egrep --color -i "svm|vmx" /proc/cpuinfo
If the command below has no output go a head and enable with help of commands below. Make sure you shutdown of the VM.
List all VMS installed in Virtualbox.
Vboxmanage list vms
Output
"rocky-linuxu-8" {8c977920-b8e7-4edb-8e0d-26a453facb40}
Enable nested virtualization to rocky Linux 8
vboxmanage modifyvm "rocky-linux-8" --nested-hw-virt on
Verify;
egrep --color -i "svm|vmx" /proc/cpuinfo
output:
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq monitor vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx rdrand hypervisor lahf_lm pti tpr_shadow vnmi flexpriority vpid fsgsbase md_clear flush_l1d
At this point our environment is good to install KVM on Rocky Linux 8. Power on the VM to continue to installation stage
Step 2: Install KVM Virtualization software on Rock Linux-8
Run command bellow to install KVM.
sudo dnf -y install epel-release
sudo dnf install @virt virt-top libguestfs-tools virt-install bridge-utils libvirt-devel
Screen output;
...
Transaction Summary
====================================================================================
Install 28 Packages
Total download size: 15 M
Installed size: 55 M
Is this ok [y/N]: y
Press Y and Continue
Start and enable libvirtd service:
sudo systemctl enable --now libvirtd
Confirm that necessary kernel modules are loaded.
$ sudo lsmod | grep kvm
kvm_intel 303104 0
kvm 798720 1 kvm_intel
irqbypass 16384 1 kvm
Step 3: Configuring KVM Virtualization on Rocky Linux 8
Next we have to create a directory where we will upload our ISO files for installation of VMs. At this part we are also going to configure storage domains where VM will be installed.
sudo mkdir -p /kvm/images/iso
Create virtual storage.
$ sudo qemu-img create -f qcow2 /var/lib/libvirt/images/linuxmint.qcow2 20G
Allow non-root user to run KVM commands. Run commands below as a non root user.
Add libvirtd group to Rocky Linux 8 followed by adding user to the new group
sudo groupadd --system libvirt
sudo usermod -a -G libvirt $(whoami)
Step 4: Install Virtual Machine on KVM in Rocky Linux 8
Run command below to install VM on KVM using CLI.
sudo virt-install
--virt-type kvm
--name Linuxmint
--ram 2024
--disk /var/lib/libvirt/images/Linuxmint
--network network=default
--graphics vnc,listen=0.0.0.0
--noautoconsole
--os-type=linux
--os-variant=generic –cdrom=/kvm/iso/linuxmint-20.1-cinnamon-64bit.iso
Use virsh command to confirm that VM has started.
$ sudo virsh list --all
#output
ID Name State
--------------------------------
1 Linuxmint Running
You view and manage VM on GUI with help of Virt-Manger
Step 5: Install Virt-Manager on Rocky Linux 8 (Optional)
$ sudo dnf install virt-manager
Output
Dependencies resolved.
====================================================================================
Package Architecture Version Repository Size
====================================================================================
Installing:
virt-manager noarch 2.2.1-3.el8 appstream 368 k
Transaction Summary
====================================================================================
Install 1 Package
Total download size: 368 k
Installed size: 2.3 M
Is this ok [y/N]: y
Press y then click Enter to continue.
When installation is complete logout and login using the normal user & launch virt-manager
virt-manager