How to Install KVM on Rocky Linux 9 / AlmaLinux 9

This tutorial will walk you through how to install KVM on Rocky Linux 9 or AlmaLinux 9.

Kernel Virtual Machine (KVM) is an open-source Type1/bare-metal hypervisor that enables users to host and run multiple isolated virtual environments on their Linux machine.

Like most virtualization solutions, KVM abstracts hardware resources, including CPU, memory, storage, network, and graphics, and assigns them to guest machines that run in an isolated environment.

KVM provides numerous functionalities such as resource control, scheduling, scalability, high performance, low latency, live migration, memory management, and more. In addition, you can use Ansible and other automation tools to automate KVM deployments.


  • An active and running Rocky Linux 9 / AlmaLinux 9 system.
  • Sudo or root privilege
  • Internet Connection
  • Basic understanding of Linux networking and commands.

Without any delay, let’s deep dive into KVM installations steps.

1. Confirm Hardware Virtualization

Ensure that your system has hardware virtualization extensions enabled. For Intel-based hosts, Use the following command to confirm if the CPU virtualization extension (vmx) is available:

$ sudo grep -e 'vmx' /proc/cpuinfo

For AMD-based hosts, confirm if the CPU virtualization extension (svm) is available by running the following command:

$ sudo grep -e 'svm' /proc/cpuinfo

If virtualization is not enabled, you can enable it in the BIOS settings of your machine.

2. Install KVM on Rocky Linux 9 / AlmaLinux 9

Run the following command to install the KVM packages, which are located in the default repository of Rocky Linux 9:

$  sudo dnf install qemu-kvm libvirt virt-manager virt-install


Install other KVM management tools as shown:

$ sudo dnf install epel-release -y


$ sudo dnf -y install bridge-utils virt-top libguestfs-tools bridge-utils virt-viewer


The following is a brief explanation of the above packages:

  • virt-manager provides graphical user interface for managing virtual machines.
  • libvirt-client offers CL utility to administer the virtual environment.
  • virt-install is the command line tool used to create virtual machines.
  • libvirt provides the host-side libraries for interacting with host systems and hypervisors.

After the installation is complete, run the following command check whether KVM module is loaded into the kernel or not.

$ sudo lsmod | grep kvm

3. Start and Enable libvirtd daemon

libvirtd is a daemon component that operates on the server side and controls tasks on virtualized guests. It is employed in managing virtualization technologies, including ESXi, KVM, and Xen.

To start and enable the libvirtd daemon, run:

$ sudo systemctl start libvirtd
$ sudo systemctl enable libvirtd

To check if the libvirtd daemon is running, run the following command:

$ sudo systemctl status libvirtd


You must also add your system user to the KVM group to execute virt-install commands without sudo.

$ sudo usermod -aG libvirt $USER
$ newgrp libvirt

4. Create Network Bridge for KVM Instances

A network bridge with the name virbr0 is automatically created to offer Network Address Translation (NAT). Virtual machines using this bridge lack external connectivity.

Existing bridge networks can be listed using the brctl command:

$ sudo brctl show


In this section, we’ll create a network bridge for external connections using NMCLI. To get started, run the following command to list the network interfaces available on your machine:

$ sudo nmcli connection show


To start creating the bridge, first, delete the existing connection using the following command:

$ sudo nmcli connection delete bf2bae34-5130-309a-b84d-a3c56dec9ed8

Before moving on, it would be important to have the following information at hand:

  • Bridge name: This is the new bridge’s preferred name (e.g., br1).
  • Device name: This is the network interface’s name. This is going to be the bridge slave (e.g., ens160).
  • IP address/subnet: This is the bridge network’s IP address and subnet, for example, This should match your network subnet IP address.
  • gateway:  This is the network’s default gateway address, for example,
  • DNS1 and DNS2: These are the preferred DNS addresses (e.g., and

To create a new bridge, run the following command:

$ sudo nmcli connection add type bridge autoconnect yes con-name br1 ifname br1


Next, add the IP, gateway, and DNS to the bridge, as shown below:

$ sudo nmcli connection modify br1 ipv4.addresses ipv4.method manual
$ sudo nmcli connection modify br1 ipv4.gateway
$ sudo nmcli connection modify br1 ipv4.dns +ipv4.dns


Now, run the following command to add the bridge slave:

$ sudo nmcli connection add type bridge-slave autoconnect yes con-name ens160 ifname ens160 master br1


To verify the bridge creation, run the following command:

$ sudo nmcli connection show


Next, start the network bridge:

$ sudo nmcli connection up br1


To verify if the bridge is active, run:

$ sudo nmcli connection show br1


To enable KVM to use this bridge, edit the below file,

$ sudo vim /etc/qemu-kvm/bridge.conf

Add the line:


Then restart libvirtd service

$ sudo systemctl restart libvirtd

5. Creating Virtual Machine using KVM

Now that KVM is set up and the bridge connection is established, let’s create a virtual machine. You need an ISO file to continue with the VM creation.

It’s easy to spin a virtual machine via the CLI, especially if you understand the fundamentals of KVM. To get started, set the right ownership of the libvirt directory:

$ sudo chown -R $USER:libvirt /var/lib/libvirt/

Using the following syntax, we will create a virtual machine on the command line using the Rocky9 Linux image.

$ virt-install \
--name Rocky9 \
--ram 2048 \
--vcpus 1 \
--disk path=/var/lib/libvirt/images/rocky-9.img,size=20 \
--os-variant centos-stream9 \
--network bridge=br1,model=virtio \
--graphics vnc,listen= \
--console pty,target_type=serial \
--location /home/rocky9/Downloads/Rocky-9.0-x86_64-minimal.iso


  • -disk path=/var/lib/libvirt/images/rocky-9.img,size=20  – It is  the path to create the disk and disk size in GBs.
  • -vcpus 1 is the number of CPUs to be allocated.
  • -ram 2048 is the memory allocated.
  • network bridge=br1 specifies the network bridge to use.
  • graphics vnc,listen= shows the VNC listen address.
  • location /home/rocky9/Downloads/Rocky-9.0-x86_64-minimal.iso is the path of your ISO file.

When the above command is executed, VNC will launch and the guest operating system installation will begin, as shown below.


You can also create virtual machines using Virt-Manager GUI. To get started, head over to the application menu and click the icon as shown:


Click on the highlighted icon to create a virtual machine.


Here, select how you would like to install the ISO, choose the default option, and proceed.


In this window, select the ISO image.


Set up the virtual machine’s memory and CPU.


Here, configure the hard disk size.


Now, click the finish button for the installation to begin.




That’s it! We have shown you how to install KVM on Rocky Linux 9 or AlmaLinux 9. We hope you find this tutorial useful and informative. Feel free to post your queries and feedback in below comments section.

Leave a Comment

thirteen − seven =