In this guide, we demonstrate how to install KVM on RHEL 9.
KVM, short for Kernel Virtualization Machine, is an open-source virtualization platform designed for the Linux kernel. It’s a type 1 hypervisor, commonly referred to as a bare-metal hypervisor. It allows users to create and manage multiple guest machines, which can be spun from either Linux or Windows operating systems.
Table of Contents
- Prerequisites
- Verify if Hardware Virtualization is Enabled
- Install KVM on RHEL 9
- Start and Enable the libvirtd Daemon
- Setup the Bridge Interface
- Create a Virtual Machine
- Conclusion
Prerequisites
- Pre-installed RHEL 9
- User with admin rights
- Internet connectivity
1. Verify if Hardware Virtualization is Enabled
To start off, you need to verify if your system has the virtualization feature enabled. On most modern systems, this feature comes already enabled in the BIOS. But just to be sure, you can verify if virtualization is enabled as shown:
# cat /proc/cpuinfo | egrep "vmx|svm"
2. Install KVM on RHEL 9
Once you have ensured that virtualization is enabled, the next step is to install KVM and management tools. Run the following command:
# dnf install qemu-kvm virt-manager libvirt virt-install virt-viewer virt-top libguestfs-tools -y
After installation, check if the required KVM modules have been loaded:
# lsmod | grep kvm
You should see output confirming that the necessary modules have been loaded.
3. Start and Enable the libvirtd Daemon
The libvirtd
daemon is a server-side component that manages tasks on virtualized guests. To start the daemon, run:
# systemctl start libvirtd
Enable the service to start at boot:
# systemctl enable --now libvirtd
Verify that the daemon is running:
# systemctl status libvirtd
4. Setup the Bridge Interface
To access VMs from outside the hypervisor network, create a bridge interface.
Identify Network Interfaces
List the network interfaces:
# nmcli connection show
Example output:
NAME UUID TYPE DEVICE
ens160 f09c953d-b837-3a17-a308-ba348a89014d ethernet ens160
lo 4d52caf2-8920-4f41-a900-13df07831c16 loopback lo
virbr0 99e0354a-6745-432d-8669-3ca32db7e663 bridge virbr0
Delete Existing Connection
Delete the existing connection using its UUID:
# nmcli connection delete f09c953d-b837-3a17-a308-ba348a89014d
Create a New Bridge Interface
Create a bridge interface:
# nmcli connection add type bridge autoconnect yes con-name br1 ifname br1
Specify the IP subnet, gateway, and DNS values:
# nmcli connection modify br1 ipv4.addresses 192.168.2.150/24 ipv4.method manual
# nmcli connection modify br1 ipv4.gateway 192.168.2.1
# nmcli connection modify br1 ipv4.dns 192.168.2.1
Add the bridge slave:
# nmcli connection add type bridge-slave autoconnect yes con-name ens160 ifname ens160 master br1
Activate the bridge:
# nmcli connection up br1
Verify the bridge:
# ip addr | grep br1
Edit the bridge configuration file:
vi /etc/qemu-kvm/bridge.conf
Add the following line:
allow all
Restart the virtualization daemon:
# systemctl restart libvirtd
5. Create a Virtual Machine
Assign necessary ownership rights to the logged-in user:
# chown -R $USER:libvirt /var/lib/libvirt/
To create a virtual machine using an RHEL 9 ISO image:
# virt-install \
--name rhel-9 \
--ram 1024 \
--vcpus 1 \
--disk path=/var/lib/libvirt/images/rhel-9.img,size=8 \
--os-variant rhl9 \
--network bridge=br1,model=virtio \
--graphics vnc,listen=0.0.0.0 \
--console pty,target_type=serial \
--cdrom /iso-home/
rhel-9.4-x86_64-dvd.iso
A graphical session will launch, and the guest OS installation will commence.
Conclusion
This concludes our guide on how to install KVM on RHEL 9. We’ve covered everything from verifying hardware virtualization to creating a bridge interface and spinning up a virtual machine. Your feedback is highly welcome!
No comments:
Post a Comment