DEV Community

ChungWei Wei
ChungWei Wei

Posted on • Originally published at kmp.tw on

[Linux] Rocky Linux Install KVM

Situation

Install KVM In Rocky Linux 9.0

How To

Step 1 : Check CPU Virtualization Extensions

cat /proc/cpuinfo | egrep "vmx|svm"
Enter fullscreen mode Exit fullscreen mode

or

lscpu | grep Virtualization
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Step 3 : Start libvirtd And Enable That

systemctl start libvirtd
systemctl enable libvirtd
Enter fullscreen mode Exit fullscreen mode

Step 4 : Create Network Bridge

Show Bridge Network

brctl show

bridge name bridge id       STP enabled interfaces
virbr0      8000.5254009de646   yes
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

export These Var

export BR_NAME="br0"
export BR_INT="enp2s0"
export SUBNET_IP="192.168.0.2/16"
export GW="192.168.0.254"
export DNS1="192.168.100.1"
export DNS2="192.168.100.6"
Enter fullscreen mode Exit fullscreen mode

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}
Enter fullscreen mode Exit fullscreen mode

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}
Enter fullscreen mode Exit fullscreen mode

Start Network Bridge

nmcli connection up br0
Enter fullscreen mode Exit fullscreen mode

Verify Network

nmcli connectiob show br0
Enter fullscreen mode Exit fullscreen mode

Or

$ 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 127.0.0.1/8 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 10.0.122.1/24 brd 192.168.122.255 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 192.168.0.2/16 brd 172.16.255.255 scope global noprefixroute br0
       valid_lft forever preferred_lft forever
Enter fullscreen mode Exit fullscreen mode

Add Bridge For KVM Use

vim /etc/qemu-kvm/bridge.conf
Enter fullscreen mode Exit fullscreen mode

Add This

allow all
Enter fullscreen mode Exit fullscreen mode

Restart libvirtd

systemctl restart libvirtd
Enter fullscreen mode Exit fullscreen mode

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=0.0.0.0 \
--console pty,target_type=serial \
--location <iso-folder-path>.iso
Enter fullscreen mode Exit fullscreen mode

Top comments (0)