HomeHOWTOSHow To Install KVM on Rocky Linux 9|AlmaLinux 9

How To Install KVM on Rocky Linux 9|AlmaLinux 9

This guide will help you Install KVM on Rocky Linux 9|AlmaLinux 9. KVM (Kernel Virtualization Manager) is an open-source virtualization technology designed for the Linux operating system.
It transforms your system into a type 1 hypervisor, allowing users to create virtual machine instances via the GUI or command line.

Virtualization is a popular technology for hosting applications in cloud-based services and modern data centers. So, exactly what is virtualization? A hypervisor is used to create virtual machines (VMs) from the hardware components of a PC. Virtual machines, also known as guests, are isolated environments that operate independently of the host system, which is the physical hardware.
The hypervisor adds a layer on top of the physical system that allows for the abstraction of hardware components such as CPU, RAM, disk space, USB controllers, keyboard, mouse, NICs, and many more.

You can create multiple virtual machines from a single PC hardware, as long as it has enough resources to run the virtual machines.

Advantages of Virtualization

Virtualization has the following advantages;

  • Lower operational costs.
  • Increased efficiency.
  • Productivity.
  • Faster service and application provisioning.

Feature of KVM

KVM has the following cool features;

  • Unless specified differently, VMS can be transferred while it’s running and without disrupting the network.
  • KVM is compatible with every Linux kernel, hence it may also be used with Windows.
  • Can use any storage format employed by Linux systems.
  • Uses secure virtualization (sVirt) and security-enhanced Linux (SELinux) to ensure the isolation and security of virtual machines.
  • KVM has the ability to fairly manage and control resources like memory and storage that are allotted to various instances.

Install KVM on Rocky Linux 9|AlmaLinux 9

This section will demonstrate installing of KVM on Rocky Linux 9|AlmaLinux 9. Simply follow the steps below very carefully to accomplish this.

1. Update the system

First, perform the following software package updates.

sudo dnf update 

Install KVM and other management tools for managing the virtual machines when the update is finished.

sudo dnf install epel-release -y
sudo dnf install qemu-kvm qemu-img libvirt virt-manager virt-install virt-viewer libvirt-client

Sample output:

Installing:
 libvirt                                           x86_64         8.0.0-8.1.el9                                appstream          14 k
 libvirt-client                                    x86_64         8.0.0-8.1.el9                                appstream         372 k
 qemu-img                                          x86_64         17:6.2.0-11.el9_0.5                          appstream         2.2 M
 qemu-kvm                                          x86_64         17:6.2.0-11.el9_0.5                          appstream          56 k
Installing weak dependencies:
 libvirt-daemon-kvm                                x86_64         8.0.0-8.1.el9                                appstream          14 k

Transaction Summary
=======================================================================================================================================
Install  85 Packages

Total download size: 35 M
Installed size: 144 M
Is this ok [y/N]: y

2. Start and Enable libvirtd service

Start and enable the libvirtd service, which is a virtualization daemon and toolkit for managing virtualization platforms such as KVM, Xen, and ESXi, once it has been installed.

sudo systemctl start libvirtd
sudo systemctl enable libvirtd

Check the libvirtd status;

systemctl status libvirtd

Output:

 libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)
     Active: active (running) since Fri 2022-11-04 15:42:40 EAT; 33s ago
TriggeredBy:  libvirtd-ro.socket
             ○ libvirtd-tcp.socket
              libvirtd.socket
             ○ libvirtd-tls.socket
              libvirtd-admin.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
   Main PID: 13365 (libvirtd)
      Tasks: 21 (limit: 32768)
     Memory: 34.6M
        CPU: 916ms
     CGroup: /system.slice/libvirtd.service
             ├─13365 /usr/sbin/libvirtd --timeout 120
             ├─13462 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/lib>
             └─13463 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/lib>

3. Enable non-root Users to Execute KVM Commands

 Execute the commands below as a non-root user.

Add libvirtd group to Rocky Linux 9|AlmaLinux 9;

sudo groupadd --system libvirt

Now, add the user to the new group;

sudo usermod -a -G libvirt $(whoami)

4. Launch KVM on Rocky Linux 9|AlmaLinux 9

KVM and all of its associated packages required for virtual machine installation and management are now installed.
The virt-manager utility is a graphical tool for creating and launching virtual machines with the libvirt service.

There are two methods for starting virt-manager. You can look for it in the application manager.

Alternatively, run the command below in the command line;

$ virt-manager

As shown, this will launch the virt-manager desktop interface.

Click on the highlighted icon to create a new VM and begin the installation.

Follow the steps provided to complete the installation of the VM.

5. Create a VM on CLI on KVM

Alternatively, you can install a VM on KVM on the command line interface(CLI). Make a directory for the upload of our ISO files for VM installation. At this stage, we’ll also set up the storage domains where the virtual machines will be placed.

Create a directory;

sudo mkdir -p /kvm/images/iso

Create virtual storage for VMs;

$ sudo qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu.qcow2 10G                                                                                         Formatting '/var/lib/libvirt/images/ubuntu.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=10737418240 lazy_refcounts=off refcount_bits=16

Run the command below to install the VM on KVM using CLI.

$ sudo virt-install 
--virt-type kvm 
--name UbuntuServer 
--ram 1024
--disk /var/lib/libvirt/images/ubuntu
--network network=default 
--graphics vnc,listen=0.0.0.0 
--noautoconsole 
--os-type=linux 
--os-variant=generic –cdrom=/kvm/images/iso/ubuntu-20.04.6-live-server-amd64.iso

After running the above command successfully, launch Virt-Manager to confirm the above-created UbuntuServer VM.

From the above screenshot. Ubuntu Server VM is running.

You can use the following virsh commands to manage VMs on Command Line Interface.

#Start VM
sudo virsh start VM_name

#Stop VM
sudo virsh stop VM_name

#Reboot
sudo virsh reboot VM_name

#Pause/Suspend VM
sudo virsh suspend VM_name

#Resume Suspended VM
sudo resume VM_name

#Save current state of running VM
sudo virsh save VM_name VM_name_save

#Restore saved VM
sudo restore VM_name_save

#Shutdown
sudo virsh shutdown VM_name

#Expunge
sudo virsh destroy VM_name

Conclusion

The installation and use of KVM Virtualization on Rocky Linux 9|AlmaLinux 9 have successfully been demonstrated. I hope you found this to be informative. KVM is easy to use and increases efficiency.

Read more about KVM.

See more:

- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here