
Step-by-Step Guide to KVM Virtualization on Rocky Linux 10
Harnessing the power of virtualization is a cornerstone of modern IT infrastructure, and KVM (Kernel-based Virtual Machine) stands out as a premier open-source solution. Built directly into the Linux kernel, KVM offers enterprise-grade performance, security, and stability. For users of Rocky Linux 10, a robust and reliable server operating system, installing KVM transforms your machine into a powerful hypervisor capable of running multiple isolated virtual machines (VMs).
This comprehensive guide will walk you through every step of installing and configuring KVM on Rocky Linux 10, from initial hardware checks to creating your very first virtual machine.
Step 1: Verify Hardware Virtualization Support
Before you begin, it’s crucial to confirm that your server’s CPU supports hardware virtualization. This feature, known as Intel VT-x for Intel processors or AMD-V for AMD processors, is essential for KVM to function.
You can check for this support by running a single command in your terminal:
lscpu | grep -i virtualization
If your hardware is compatible, the output will display either VT-x
or AMD-V
. If you see no output, you may need to enable virtualization technology in your system’s BIOS/UEFI settings. This is a common requirement on new hardware.
Step 2: Install KVM and Essential Management Tools
With hardware support confirmed, the next step is to install the necessary KVM packages and management tools using the dnf
package manager. These packages provide the core hypervisor functionality, the management daemon, and command-line utilities.
Execute the following command to install the entire virtualization group:
sudo dnf groupinstall "Virtualization Host" -y
This group install conveniently includes key components such as:
- qemu-kvm: The core backend hypervisor that runs the virtual machines.
- libvirt-daemon: The management service that controls and monitors the hypervisor and VMs.
- virt-install: A command-line tool for creating new virtual machines.
- libvirt-client: Provides the
virsh
command-line tool for managing VMs.
Step 3: Start and Enable the Libvirt Service
After the installation is complete, you must start the libvirtd
service and enable it to launch automatically at boot. This ensures your virtualization environment is always ready.
Use the systemctl
command for this:
sudo systemctl start libvirtd
sudo systemctl enable libvirtd
To verify that the service is running correctly, check its status:
sudo systemctl status libvirtd
You should see an active (running)
status in the output, confirming that the virtualization daemon is operational.
Step 4: Configure User Permissions for KVM Management
By default, only the root
user can manage virtual machines. For security and convenience, it’s best practice to add your regular user account to the libvirt
group. This grants you permission to create and manage VMs without needing to use sudo
for every command.
Add your user to the libvirt
group with this command, replacing your_username
with your actual username:
sudo usermod -aG libvirt your_username
Important: For this change to take effect, you must log out and log back in or start a new shell session.
Step 5: Create a Network Bridge for VM Connectivity
While KVM’s default NAT network is useful, a network bridge is often a better choice for servers. A bridge allows your VMs to appear as independent devices on your local network, obtaining their own IP addresses from your DHCP server and allowing direct access from other machines.
We will use nmcli
, the command-line tool for NetworkManager, to create a bridge named br0
.
Identify your primary network interface:
nmcli connection show
Note the name of your active wired connection (e.g.,
eno1
,eth0
).Create the bridge interface (
br0
):sudo nmcli connection add type bridge con-name br0 ifname br0
Configure the bridge with your network settings (use an appropriate static IP or set to DHCP):
- For DHCP (Recommended for simplicity):
bash
sudo nmcli connection modify br0 ipv4.method auto
- For a Static IP: (Replace values with your network’s details)
bash
sudo nmcli connection modify br0 ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8,1.1.1.1"
- For DHCP (Recommended for simplicity):
Add your physical network interface as a slave to the bridge:
sudo nmcli connection add type bridge-slave con-name br0-slave ifname eno1 master br0
Replace
eno1
with your actual interface name.Activate the bridge:
bash
sudo nmcli connection up br0
After running this, your physical interface’s original connection will be deactivated, and all traffic will flow through the newly created bridge. Your server should remain accessible on the network.
Step 6: Create Your First KVM Virtual Machine
You are now ready to create a virtual machine. The virt-install
tool provides a powerful command-line method for provisioning new VMs. You will need an ISO installation image for the operating system you wish to install.
Here is an example command to create a new Rocky Linux 10 VM. Adjust the parameters like name, RAM, CPU, and disk size to fit your needs.
virt-install \
--name rocky10-vm \
--ram 2048 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/rocky10-vm.qcow2,size=20 \
--os-variant rockylinux10 \
--network bridge=br0 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--cdrom /path/to/Rocky-10-x86_64-dvd.iso
Breaking down the command:
--name
: The name of your new VM.--ram
: Memory allocation in megabytes.--vcpus
: The number of virtual CPU cores.--disk
: Defines the path and size (in gigabytes) for the virtual disk.--os-variant
: Optimizes the VM for a specific guest OS. Useosinfo-query os
to see all options.--network bridge=br0
: Connects the VM to the network bridge we created.--graphics vnc
: Enables remote access to the VM’s console via a VNC client.--cdrom
: Specifies the path to your installation ISO file.
After running this command, the installation process for the guest OS will begin. You can connect to it using a VNC client pointed at your host server’s IP address.
Managing Your Virtual Machines with virsh
The virsh
utility is your primary command-line interface for managing all aspects of your VMs. Here are some of the most essential commands:
- List all VMs (running and stopped):
bash
virsh list --all
- Start a VM:
bash
virsh start rocky10-vm
- Gracefully shut down a VM:
bash
virsh shutdown rocky10-vm
- Forcefully stop a VM (power off):
bash
virsh destroy rocky10-vm
- Connect to the VM’s text console:
bash
virsh console rocky10-vm
- Set a VM to start automatically with the host:
bash
virsh autostart rocky10-vm
By following these steps, you have successfully deployed a powerful and flexible KVM virtualization host on Rocky Linux 10. You now have a solid foundation for creating, managing, and scaling your virtualized workloads with professional, open-source tools.
Source: https://centlinux.com/install-kvm-on-rocky-linux-10/