Setting up KVM - tikk3r/flocs GitHub Wiki
Obtain the operating system to virtualize
Before setting up the virtual machine, download the operating system of choice. Here we will use a minimal install of CentOS 7, which can be found here. Save the ISO somewhere on the system where you can find it later. That's all.
Installing KVM
We will be using the Kernel-based Virtual Machine (KVM) for virtualization. This guide assumes a CentOS host system on the HPC Cloud. A quick check if your virtualization is possible is
egrep -o '(vmx|svm)' /proc/cpuinfo
If there is output, you're good to go. If not, inquire if nested VMs can be enabled. Next we can install KVM with
sudo yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils
Finally, to start KVM now and on startup we enable the libvirt service with
sudo systemctl start libvirtd
sudo systemctl enable libvirtd
If everything succeeded, you should be able to run virt-manager to see a graphical interface to create virtual machines.
Creating a virtual machine
To set up a new VM, go through the following steps:
- Go to
File > New Virtual Machine. - Select "Local install media (ISO image or CDROM)".
- Select "Use ISO image" and browse to where you stored the image earlier. Let KVM automatically detect the OS.
- Dedicate a certain amount of CPU and RAM to the VM, leaving a little for the host. This all depends on how much resources the host system has.
- For storage, either select the default storage location or go to "Select or create custom storage", click "Manage":
- Add a new pool in the left side bar.
- Add a new volume in the main screen.
- Click "Choose Volume" when happy.
- Check "Customize configuration before install" and hit "Finish".
- Under "CPUs" select "Sandy Bridge" in the Configuration subsection.
- Under "Display Spice" select "VNC server" as the type. This will solve an issue later on with keyboard forwarding, due to the VM being nested.
- Hit "Finish" and start the installation.
Internet access in the VM
This isn't as straightforward as it looks apparently...
Troubleshooting
Weird text or symbols in virt-manager
If text looks like gibberish, it is likely due to some X11 packages missing. Install these with
sudo yum -y install "@X Window System" xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils -y
Unable to connect to libvirt when starting virt-manager
If the error Unable to connect to libvirt occurs when running virt-manager, try
sudo usermod --append --groups libvirt $USER
It is apparently caused by a conflict in the VM between it being installed as root and using it as a user.