You have a pc that is just doing nothing? You have a dedicated server and want to play around without messing things up? Enable KVM on your linux kernel to create one/view virtual servers.
- Check if your cpu has Intel VT-x or AMD-V
egrep -c '(vmx|svm)' /proc/cpuinfo1 means that your cpu does have support for hardware virtualization. 0 means you might create quite slow vps. But you are able to run virtual servers. 2. Check if you have installed a 64bit kernel
uname -mSomething like amd64 or x86_64 indicates your are running a 64-bit kernel. You do not want to run a 32-bit kernel. That would limit your RAM usage to 2GB. 3. Install KVM tools (I am using Ubuntu/Debian commands here)
sudo apt-get install qemu-kvm libvirt-bin bridge-utils
- Add user that runs virtual servers to group (user has to re-login to get new group permissions)
sudo adduser [username] libvirtd
- Test your installation
virsh -c qemu:///system list Id Name State ----------------------------------An output like "libvir: Remote error : Permission denied" or "error: failed to connect to the hypervisor" says that something went wrong. 6. Fix ownership
sudo chown root:libvirtd /dev/kvmI do not know why, but for me /dev/kvm did not had the correct ownership. 7. Restart kernel modules - or restart the server
rmmod kvm modprobe -a kvm
- Optional: Install GUI for virtual server mangment
sudo apt-get install virt-manager
Well per default KVM has it’s own network - called usermode networking. Works like OpenVPN. You have your own subnet - e.g. 10.0.1.0/24 and every KVM gets one ip address out of it. Enough for me. I once need a connection to one of my webservers out of the KVM. I used port forwarding (iptables) to forward a connection from my host to the KVM.
- Create a virtual server
There are quite a view options. I prefer a python script called “virt-install”.
sudo apt-get install python-virtinstFirst look to the man page of virt-install
man virt-installAnd create your first vps:
sudo virt-install –connect qemu:///system -n kvm1 -r 2048 –vcpus=2Name: “kvm1”, RAM: 2 GB, CPUs: 2, HDD: 20GB and a defined vnc port you can connect to (127.0.0.1:5951)
-c /isos/ubuntu-min-install.iso –vnc –noautoconsole –os-type linux
–accelerate –network=network:default –hvm –vncport=5951
- Managing your virtual servers
start managing console
virsh –connect qemu:///system
List virtual servers
start virtual server
start [name of virtual server]
stop virtual server
shutdown [name of virtual server]
That’s it. I know there are a lot of additional topics. Maybe someone wants to explain bridged networking and ip/gateway assignment. Did not need it and therefore did not play around with it.
Please feel free to add additional steps to this mini guide.