This guide runs through installing KVM and setting up a first VM on a CentOS (8) server, with no GUI.
Install QEMU & KVM
virt module and some additional helper packages:
dnf install @virt dnf install virt-install virt-viewer libguestfs-tools
Now validate everything is OK:
Start & enable
systemctl enable libvirtd.service systemctl start libvirtd.service
If VMs are to be available on public internet, this requires setting up bridged networking. Roughly:
NetworkManagerif using CentOS <8
- Take the current public interface, copy IP information to a new bridge (
- Remove IP information from the public interface, make it bridge onto the
- Remove default KVM network
virsh net-destroy default
The default setup is suitable, where each VM gets assigned an IP via DNSMasq and there are NAT rules which enable them to reach the internet.
Create a VM
Start the Install
First, get the install media/ISO from wherever.
virt-install \ --name my-magical-server \ --virt-type=kvm \ --vcpus=4 \ --memory=4096 \ --graphics=vnc \ --disk size=100 \ --os-variant=ubuntu20.04 \ --cdrom=/tmp/ubuntu-20.04.1-live-server-amd64.iso
disk: size is in GB
os-variant: this comes from
osinfo-query os, selected closest available
The command will do some stuff and then hang waiting for the install - at this point you need to get the VNC port, SSH forward it from your laptop and use a VNC client to complete the install.
# On the server: virsh dumpxml my-magical-server | grep vnc # Locally: ssh host-server-address -L 5900:127.0.0.1:8000 <-- any port can do locally
Now fire up a VPC client (TigerVNC works/is cross platform), point it at the local address (
127.0.0.1:8000) and follow the install. Once complete, the
virt-install command running on the server will exit.
Connect to the VM
You can repeat the VNC method to gain access, but SSH is a much better option. Install SSH daemon on the box and use that for access (via the host if private network only).