Install and Configuring KVM on Rocky Linux 8.

Install and Configuring KVM on Rocky Linux 8.

1. Checking if the VT is enabled/support on the KVM host

# grep -E 'svm|vmx' /proc/cpuinfo

2. Install kvm packages and enable the required services.

# dnf module install virt
# dnf install qemu-kvm libvirt virt-viewer virt-install libguestfs-tools -y
# virt-host-validate
# systemctl start libvirtd.service
# systemctl enable libvirtd.service
# systemctl status libvirtd.service

3. Configure the Networking for KVM.
Update the Base interface file. In this example ens33 is the interface connected to internet and will used as bridge interface for the VMs

# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="none"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
HWADDR=00:0c:29:02:07:ef
BRIDGE=virbr0

Create a new Interface config file for virbr0. Please note virbr0 is the virtual bridge interface to be used in the VMs

# cat /etc/sysconfig/network-scripts/ifcfg-virbr0
TYPE="BRIDGE"
BOOTPROTO="none"
NAME="virbr0
DEVICE="virbr0"
ONBOOT="yes"
IPADDR="192.168.2.115"
PREFIX="24"
GATEWAY="192.168.2.1"
DNS1="192.168.2.1"

Enable the IPv4 forwarding.
Add "net.ipv4.ip_forward = 1" entry in /usr/lib/sysctl.d/60-libvirtd.conf and load the file

# echo "net.ipv4.ip_forward = 1" >> /usr/lib/sysctl.d/60-libvirtd.conf
# sysctl -w /usr/lib/sysctl.d/60-libvirtd.conf
# sysctl -p /usr/lib/sysctl.d/60-libvirtd.conf

Update the Network Configuration/DHCP range of the virbr0 interface

# virsh net-edit default
<network>
<name>default</name>
<uuid>df65966e-31da-4b15-a710-8082c2151b9b</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:64:d3:2c'/>
<ip address='192.168.2.115' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.2.200' end='192.168.2.220'/>
</dhcp>
</ip>
</network>


# cat /etc/sysconfig/network-scripts/route-virbr0
192.168.2.0/24 via 192.168.2.115 dev virbr0


4. Restart the KVM host.

# reboot

5. Creating a virtual Machine from Command Line

Update the base interface file. In this example ens33 is the interface connected to internet and will be used as bridge interface for the VMs

# osinfo-query os | grep -i rocky

# virt-install --network bridge:virbr0 --name temp-vm1 --os-variant=rocky8 --ram=1024 --vcpu=1 --disk path=/kvmstore/temp-vm1.img,size=10 --graphics none --location=/tmp/Rocky-8.7-x86_64-minimal.iso --extra-args="console=tty0 console=ttyS0,115200"

No comments:

Post a Comment