Install KVM In Rocky Linux 9.0

How To

Step 1 : Check CPU Virtualization Extensions

cat /proc/cpuinfo | egrep "vmx|svm"


lscpu | grep Virtualization

Step 2 : Install KVM Tools

dnf install qemu-kvm libvirt virt-manager virt-install -y
dnf install epel-release -y
dnf install bridge-utils virt-top libguestfs-tools bridge-utils virt-viewer -y

Step 3 : Start libvirtd And Enable That

systemctl start libvirtd
systemctl enable libvirtd

Step 4 : Create Network Bridge

Show Bridge Network

brctl show

bridge name	bridge id		STP enabled	interfaces
virbr0		8000.5254009de646	yes

Show Connect Info

nmcli connection show

NAME                UUID                                  TYPE      DEVICE
enp2s0              3ed4465d-7f61-48c3-9ec6-59fb4aedfd22  ethernet  enp2s0
virbr0              0535364e-982c-4ee0-b2ce-bfd1ff6e47d4  bridge    virbr0

export These Var

export BR_NAME="br0"
export BR_INT="enp2s0"
export SUBNET_IP=""
export GW=""
export DNS1=""
export DNS2=""

Run Command nmcli Setting Bridge Network

# add bridge 
nmcli connection add type bridge autoconnect yes con-name ${BR_NAME} ifname ${BR_NAME}

# add ip address, gateway and dns 
nmcli connection modify ${BR_NAME} ipv4.addresses ${SUBNET_IP} ipv4.method manual
nmcli connection modify ${BR_NAME} ipv4.gateway ${GW}
nmcli connection modify ${BR_NAME} ipv4.dns ${DNS1} +ipv4.dns ${DNS2}

Add The Identified Network Device As A Slace To The Bridge

nmcli connection delete ${BR_INT}
nmcli connection add type bridge-slave autoconnect yes con-name ${BR_INT} ifname ${BR_INT} master ${BR_NAME}

Start Network Bridge

nmcli connection up br0

Verify Network

nmcli connectiob show br0 


$ ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether fc:aa:14:e3:09:0e brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:9d:e6:46 brd ff:ff:ff:ff:ff:ff
    inet brd scope global virbr0
       valid_lft forever preferred_lft forever
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether fc:aa:14:e3:09:0e brd ff:ff:ff:ff:ff:ff
    inet brd scope global noprefixroute br0
       valid_lft forever preferred_lft forever

Add Bridge For KVM Use

vim /etc/qemu-kvm/bridge.conf

Add This

allow all

Restart libvirtd

systemctl restart libvirtd

Step 5 : Create VM

virt-install --name vm-temp --ram 2048 --vcpu 1 \
--disk <vm-disk-path-folder>.img,size=10 \
--os-variant centos-stream9 --os-type linux \
--network bridge=br0,model=virtio \
--graphics vnc,listen= \
--console pty,target_type=serial \
--location <iso-folder-path>.iso