installing kvm,
Lets check whether the host supports virtualization
# grep -E 'svm|vmx' /proc/cpuinfo
cpu supports virtualization lets install kvm now
#dnf install qemu-kvm qemu-img libvirt virt-install libvirt-client libvirt-python
verifying that that kernel is loaded with kvm
#lsmod | grep kvm
kvm_intel 200704 3
kvm 581632 1 kvm_intel
irqbypass 16384 4 kvm
we can control libvirtd daemon from virsh command.
# virsh list --all
Id Name State
----------------------------------------------------
4 cipher_default running
- centosext shut off
- centosext1 shut off
- centosext2 shut off
- centosext3 shut off
- centosext4 shut off
- centosext5 shut off
- chefnode1 shut off
- chefnode2 shut off
- chefnode3 shut off
- chefnode4 shut off
Enabling vnc access kvm hosts, when setup kvm hosts from -vnc option it will listen on loopback 127.0.0.1 to make vnc access available on all interfaces edit /etc/libvirt/qemu.conf and set vnc_listen=0.0.0.0.
#grep vnc_listen /etc/libvirt/qemu.conf
vnc_listen = "0.0.0.0"
Configuring firewalld to allow vnc ports,
#firewall-cmd --get-active-zones
public
interfaces: enp9s0
#firewall-cmd --zone=public --permanent --add-port=5900-6100/tcp
success
#firewall-cmd --zone=public --permanent --list-ports
5900-6100/tcp
Creating vms from virsh console
#virt-install --name centos7 --ram 512 --file=/var/lib/libvirt/images/centos.qcow2 --file-size=3 --vnc --cdrom=/home/cipher/centos.iso
Clone and sysprep of vms
#sudo virt-clone --original centosext --name centosext1 --file /var/lib/libvirt/images/centosext1.qcow2
Cloning multiple kvm guests at once
#for i in $(cat vms); do sudo virt-clone --original centosext --name centosext"$i" --file /var/lib/libvirt/images/centosext$i.qcow2; done
Sysprep will remove any initial configurations set on vm
#sudo virsh list --all | awk '{print $2}' | grep -v Name | tail -n 5 | xargs -I {} sudo virt-sysprep -d {}
Lets set hostnames and root passwords
#virt-sysprep -d centosext1 --hostname centosext.lab.com --root-password password:decipher
Renaming a virtual machine domain with virsh.
Related Articles
How We Set Up Our KVM Hypervisor: From Bare Metal to Production-Ready VM Host
Detailed walkthrough of building a dedicated KVM/libvirt hypervisor with XFS tuning, hugepages, 10GbE tuning, and automation.
Building a Predictable KVM Infrastructure: From Chaos to Control
How to engineer a predictable KVM-based infrastructure focusing on repeatability, observability, and operational safety.
Virt-sparsify
How to use virt-sparsify to reclaim unused disk space from qcow2 VM images.