Step-by-Step Guide on Rocky Linux / CentOS 8.5
Virtualization allows multiple isolated OS environments—Virtual Machines (VMs)—to run on a single physical host. KVM (Kernel-based Virtual Machine) is built into the Linux kernel, turning your Rocky Linux or CentOS server into a full-featured Type 1 hypervisor.
Type 1 vs. Type 2 Hypervisors
| Type 1 (Bare Metal) | Type 2 (Hosted) |
|---|---|
| Installed directly on hardware. Maximum performance and security. | Runs on top of an existing OS like Windows or macOS. |
| Analogy: Architect designing a skyscraper from scratch. | Analogy: Renting an office in an existing building. |
| Examples: VMware ESXi, Hyper-V, Rocky Linux KVM. | Examples: VirtualBox, VMware Workstation. |
KVM turns Rocky Linux/CentOS 8.5 into a powerful Type 1 hypervisor.
KVM Software Stack
Management Tools (virsh, virt-manager)
User-friendly command-line and GUI tools.
Libvirt API
Standard API to manage hypervisors.
QEMU
Emulates CPU, memory, disks, and network devices.
KVM Kernel Module
Provides hardware acceleration (Intel VT-x / AMD-V).
- KVM: Core virtualization engine.
- QEMU: Hardware emulator.
- Libvirt: Management API for VMs.
Step 1: Prepare the Host
- Check CPU Virtualization:
$ lscpu | grep Virtualization Virtualization: VT-x - Install KVM and Management Packages:
sudo dnf groupinstall -y "Virtualization Host" sudo dnf install -y virt-manager libvirt libvirt-python libguestfs-tools qemu-kvm - Enable libvirtd Service:
sudo systemctl enable --now libvirtd sudo systemctl start libvirtd - Verify Installation:
$ virsh list --all Id Name State --------------------------------------
Step 2: Create a VM (CLI)
sudo virt-install \
--name rocky8-vm1 \
--ram 2048 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/rocky8-vm1.qcow2,size=20 \
--os-variant rhel8.5 \
--network bridge=virbr0 \
--graphics none \
--console pty,target_type=serial \
--location /home/user/isos/Rocky-8.6-x86_64-dvd1.iso \
--extra-args 'console=ttyS0,115200n8 serial'This launches the text-based installer automatically.
Step 3: Manage VMs with virsh
- List all VMs:
sudo virsh list --all - Start VM:
sudo virsh start rocky8-vm1 - Shutdown VM:
sudo virsh shutdown rocky8-vm1 - Force off VM:
sudo virsh destroy rocky8-vm1 - Connect console:
sudo virsh console rocky8-vm1 - Delete VM definition:
sudo virsh undefine rocky8-vm1
Step 4: Advanced Management
- Create a Snapshot:
sudo virsh snapshot-create-as rocky8-vm1 snap1 "Snapshot before update" - List Snapshots:
sudo virsh snapshot-list rocky8-vm1 - Restore Snapshot:
sudo virsh snapshot-revert rocky8-vm1 snap1 - Attach a Disk:
sudo virsh attach-disk rocky8-vm1 /var/lib/libvirt/images/data.qcow2 vdb --persistent - Networking (Bridge):
sudo nmcli connection add type bridge con-name br0 ifname br0 sudo nmcli connection add type bridge-slave con-name br0-port1 ifname enp1s0 master br0
Step 5: GUI Management with virt-manager
- Run
virt-manageror search "Virtual Machine Manager". - Create a new VM, select ISO, assign CPU/RAM/disk.
- Finish, boot VM, install OS graphically.
- Use
virshto manage lifecycle even for GUI-created VMs.
Create multiple VMs, experiment with snapshots, networking, and automation scripts. Confirm everything works via virsh list --all.