Creating KVM guests with automatic installation of Debian Squeeze 6.0.5

Pre-requisite

You need to have a Linux-kernel with kvm installed. To verify, type


lsmod | grep kvm

Sample output:


kvm_intel xxxx 0
kvm xyzxyz 1 kvm_intel

If you don’t observe any output similar to the above, try to verify whether your kernel has kvm installed as a module or not using


modprobe -l | grep kvm

Most of the recent OS comes with a kernel that has kvm installed. If you are using some of the old ones, try to compile your Linux-kernel with kvm either as loadable kernel module or as part of the kernel binary. See here.

Next you have to install libvirt and python-virtinst packages. For Ubuntu, type


apt-get install libvirt-bin python-virtinst

Automatic installation from ISO image

First we create a bootable ISO image that triggers automatic installation of Debian Squeeze (Click here). Now the following script can be used to create a KVM guest.

#!/bin/sh

# A script to install debian squeeze on a KVM guest
# using automatic installation ISO image

if [ $# -ne 1 ]
then
echo "Usage: $0 guest-name"
exit 1
fi

virt-install \
--connect=qemu:///system \
--name=${1} \
--ram=512 \
--vcpus=1 \
-f YOUR-PATH-TO-IMG-DIR/${1}.img \
-s 5 \
--cdrom=YOUR-PATH-TO-ISO-IMAGE \
--vnc \
--os-type=linux \
--virt-type=qemu \
--noautoconsole \
--hvm \
--network=network:default \
--extra-args="auto text console=tty1 console=ttyS0,115200"

Automatic installation from online Debian image

First upload your debian-preseed.cfg file on a publicly available webserver and then execute the following script to install the kvm guest.


#!/bin/sh
#
# A script to install Debian Sequeeze on a KVM guest
# using automatic installation from installable distribution
# image on an HTTP server

if [ $# -ne 1 ]
then
echo "Usage: $0 guest-name"
exit 1
fi

virt-install \
--connect=qemu:///system \
--name=${1} \
--ram=1024 \
--vcpus=1 \
-f PATH-TO-IMG-DIR/${1}.img \
-s 5 \
-l http://ftp.debian.org/debian/dists/squeeze/main/installer-i386/ \
--vnc \
--os-type=linux \
--virt-type=qemu \
--noautoconsole \
--hvm \
--network=network:default \
--extra-args="auto=true hostname=${1} domain=   url=URL-TO-YOUR-debian-preseed.cfg text console=tty1 console=ttyS0,115200"

Advertisements

2 Comments

  1. […] Of course, this can all be done through the virt-manager GUI as well, but when working remote, without an X-server or VNC at your disposal, it’s handy to know some command-line as well. And to reduce typing the same thing over and over (although it’s not bad to get the commands in your muscle memory), let’s put it in a small script. (Inspiration was found here) […]

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s