Quick virtualisation guide

Tags: kvm, virtualisation, linux, howto, centos, vm, qemu,

Added: 2012-12-17T00:00

Quick virtualisation guide

If you run Linux, and have a recentish CPU, then setting up KVM virtual machines should be a complete doddle.

I am running CentOS 6.7, and the installed guest will be 6.7 as well.

Two quick pre-flight checks first.

grep -E '(vmx|svm)' /proc/cpuinfo >/dev/null && echo "KVM will work for me" || echo "I need to buy a new computer"
dmesg | grep "kvm: disabled by bios" >/dev/null && echo Enable virtualisation in the BIOS
OK, install the stuff you need.
yum install libvirt virt-manager python-virtinst libvirt-client qemu-kvm
Insert the right kernel modules
modprobe -v kvm-intel
Start libvirtd.
/etc/init.d/libvirtd start
Make a new disk-image. This will be 1GB, but you can make it more if you prefer. You can always mount other images later though, so you don't need to go wild now.
dd bs=1G count=1 if=/dev/zero of=/var/lib/libvirt/images/test.img
Grab an example kickstart file. A kickstart file is sort of a list of the answers to the questions you would get asked while installing.
wget http://files.calum.org/basic.ks
Now make a new VM. This will download images and RPMs over the internet, so might take a little while. This example uses 1 CPU, and 1GB RAM.
virt-install -n test -r 1024 --vcpus=1 --disk path=/var/lib/libvirt/images/test.img -l http://www.mirrorservice.org/sites/mirror.centos.org/6.7/os/x86_64/ --initrd-inject=/path/to/basic.ks --extra-args "ks=file:/basic.ks"
The password is password.
You should be able to manage your virtual machine with
virt-manager
This is a nice simple way to build machines locally.
If you need it to be faster, think about setting up a local mirror, so that you don't have to download all the files over the internet. It should be possible to get a VM built from scratch in 2 minutes with a local mirror.

If you need to build hundreds of machines, look into using PXE-booting. Cobbler is a nice system for managing this, although you can do it all without.
Add a comment

Your IP:
Please enter 7463366 here: