Creating KVM Images for QVD


Today we are going to look at creating a basic KVM image for QVD. It’s a surprisingly simple process! This guide will use Ubuntu, but it should be pretty simple to replicate with another distro.

We are going to use the lightweight Ubuntu variant Lubuntu as it fits our requirements nicely, it’s (relatively) small, and comes with the minimal desktop LXDE as standard. Let’s download that first. We will use the alternate download cd as it’s optimized for lower RAM installations and stick with the stable LTS release Precise Pangolin as QVD provides packages for this that we will need later on. It’s certainly not necessary to use the 64 bit iso if you are using KVM but it might save you another download next time when we go through the LXC setup. The iso can be found on the Lubuntu Precise Alternate download page, or using this direct link. You can check the md5sum of the download here.

Before we start, we also need to make sure we have qemu-kvm and qemu-utils installed.

$ sudo apt-get install qemu-kvm qemu-utils

Now, let’s make a qcow2 disk image file. We’ll set the maximum file size at 4.5GB is the minimum required by Lubuntu although initially the file will be a fraction of this size as it will grow dynamically to accomodate needs. Indeed the final result should be a couple of GB and, zipped up, less than 900MB.

$ kvm-img create -f qcow2 qvd.img 4.5G

That done, let’s get started with installing our operating system into the image:

$ kvm -hda qvd.img -cdrom lubuntu-12.04-alternate-amd64.iso -m 512

Obviously if your iso is in a different folder to this image, you will need to change your path accordingly. This will bring up the Lubuntu installer.

Select your language and in the next screen select Install Lubuntu.

Give it a few seconds and the Ubuntu install will have loaded up. Most of the install is pretty self explanatory, so we won’t cover it in too much depth. Work through the steps until you reach disk partitioning. As a rule we don’t want or need a swap partition within disk images in QVD, so let’s select the Manual option. Now scroll down to sda in the next screen and hit enter.

Yes to Create New Empty Partition Table On This Device? You’ll now be back in the main partition screen with a new, empty, partition table. Select this empty partition.

Next opt to create a new partition.

Agree to the partition size (it should be the full size of the disk).

Select Primary partition and you will be in the partition disks page with a bunch of sensible defaults. These look fine, so choose Done Setting Up The Partition

Back in the main screen, select Finish and ignore the warning about lack of swap and writing changes to disk. Thus will begin the installing of the core packages of the OS. This will take a few minutes. Once that is finished you will get a question about proxy setup which you will need to answer (or just Continue) and this will be followed by apt setup and software install.

At the end of the install, you will need to install GRUB to the MBR.

Finally, set up the time zone and the  installation is now complete!

Select Continue to boot into the new OS. Log in using the user credentials that you set during the install. This user will not be a desktop user, rather the administrative user that will maintain and install software on the image.

For QVD to be able to able to serve the image, it will need the QVD Virtual Machine Agent (VMA) installed, so start up a terminal and enter the following commands to add the QVD repositories and install the VMA.

$ sudo apt-add-repository ppa:qvd-qindel/qvd-3.1
$ sudo apt-get update
$ sudo apt-get install perl-qvd-vma

The VMAis controlled through the file /etc/qvd/vma.conf. This file is not created on install, so let’s create the directory, and copy the sample VMA configuration file into place.

$ sudo mkdir /etc/qvd
$ sudo cp -v /usr/lib/qvd/config/sample-vma.conf /etc/qvd/vma.conf

If you take a look at the vma.conf file it has a couple of sensible presets:

vma.audio.enable = 1
vma.printing.enable = 1

Other settings are detailed in the QVD Administration Guide. One additional configuration option is needed to get the X session running under Lubuntu, although it should be noted that this requirement isn’t necessary with a stock Ubuntu install:

command.x-session: /usr/bin/startlubuntu

Since we want audio and printing, let’s leave those as they are and start the VMA:

$ sudo service qvd-vma start

To administer the image once it’s been installed, let’s also install the openssh server:

$ sudo apt-get install openssh-server

When the image has been deployed in QVD, this can be accessed using the QVD admin tool for administration / troubleshooting:

$ qa vm ssh -f id=<vm_id> -- -l <user>

If you wish to have serial access to your VM, that too is readily set up. Within the DI, edit the file /etc/init/ttyS0.conf and add the following configuration:

# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 115200 ttyS0 xterm

Once the Serial Port has been configured, the default settings for any Server Node will allow you to access a running Virtual Machine using telnet or the QVD CLI Administration Utility with a command like:

$ qa vm console -f id=<vm_id>

From here, it’s up to you. Install updates if you wish, install packages that you would like available for your users, customize everything to your needs. Once you are happy with your disk image, power it down and it’s ready for use with QVD. Happily the image compresses substantially with gzip so it’s probably best to zip it up if you wish to transfer and install it on a remote QVD instance. You can do this as follows:

$ tar czvf qvd.img.tar.gz qvd.img

And unzip it on the destination server when you are ready to move it to staging:

$ tar xzvf qvd.img.tar.gz && sudo mv -v qvd.img /var/lib/qvd/staging

Once you’ve moved the image into staging, it will be available in the QVD Web Administration Tool. You can create a new set of runtime settings for the image (OSF) and add the disk image  to the database. Finally, you will need to create a new Virtual Machine for each user that will use this disk image and it’s ready to be used.

And that concludes our little introduction to creating KVM images for use with QVD. It’s pretty simple really, and the beauty of the KVM image is that any time you want to tweak an image, you can open it up in kvm and administer it as though it were a real desktop, shut down, copy the image to staging and deploy. Next time we will look at creating an LXC image.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.