calum.org:~#

Quick virtualisation guide

Tags: kvm, virtualisation, linux

Added: 2012-12-17 19:18
Last edited: 2012-12-20 13:22

Quick virtualisation guide

Share: Share on Facebook Share on Delicious Share on Twitter Share on Email Share on StumbleUpon Share on Yahoo Share on Technorati Share on MySpace Share on Digg Share on Reddit Share on Newsvine


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

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
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.3/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 4724206 here: