This post describes how to use a CentOS 7 installation as hypervisor for a virtual machine running Ubuntu 14.04 LTS.
These examples is just to show the basics on getting KVM virtualization up and running and should not be put in to production before considering the added value SElinux gives.
Since this VM is planned to be a webserver, the VM will only have access to a text console (headless) and there will not be any graphical consoles available through VGA, VNC, Spice or QXL. The VM will be connected to the default network, meaning network traffic from the VM will be NAT based through the host.
Using virt-install to create a headless VM
$ sudo virt-install -n vm-name –description “server for example.com” –os-type=Linux –os-variant=generic –ram=2048 –vcpus=1 –disk path=/var/lib/libvirt/images/vm-hhj.qcow2,bus=virtio,size=10 –graphics none –console pty,target_type=serial –location=/var/lib/libvirt/images/ubuntu-14.04.2-server-amd64.iso –extra-args=console=ttyS0,115200n8 serial –network default
To exit this console view you can use the key combination CTRL + Alt gr + 9
If you are using Putty as SSH client from Windows you can use the key combination CTRL+5 on the Norwegian, Swedish and Finnish keyboard layout.
VM with graphical console available through SSH using port forwarding and VNC.
From your local workstation
Create a SSH tunnel from you workstation to the hypervisor server
$ ssh servername.example.com -L 5903:127.0.0.1:5903
Description of the SSH -L option
Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
On the hypervisor server
Create a VM with a graphical VNC console
$ sudo virt-install –graphics vnc,port=5903 –noautoconsole –network default –name TestVM –ram 2048 –vcpus=1 –disk path=/var/lib/libvirt/images/TestVM.img,size=5 –location=/var/lib/libvirt/images/ubuntu-14.04.2-server-amd64.iso -v –accelerate –noreboot
From your local workstation (while you have a active SSH session with port forwarding)
Start a VNC connection to localhost port 5903 using krdc or other VNC clients.
The VNC path would then be like
Or you can test virt-viewer
$ virt-viewer –connect qemu+ssh://email@example.com/system TestVM
[Remote libvirt SSH access]
You should now be able to install your desired operation system on your new VM.
Here is a list of useful virsh commands that might come handy when using CentOS as hypervisor.
# virsh start vm-name
Stop VM (ACPI)
# virsh shutdown vm-name
If shutdown does not work you can try the destroy command. It is like using the power button on a physical server.
# virsh destroy vm-name
Connecting to the VM and start the installation
# virsh console vm-name
# virsh net-list
If the network is not active, start it by doing:
# virsh net-start default
List all VMs
# virsh list –all
Remove VM from list
# virsh undefine vm-name