Following on from our tutorial creating KVM images for QVD, we now move on to creating an LXC image for QVD. LXC is a lightweight virtualisation technology that enables the sharing of the host machine’s kernel with guest operating system. This provides a boost in performance over traditional technologies, as well as being less resource intensive. For VDI technology, that means greater density, or the ability to server more desktop environments per server core, and subsequent reductions in hardware that that suggests. All in all it’s pretty exciting technology that’s new to QVD 3.1 and one that we expect to go from strength to strength.
You will need at least 5GB of disk space to install the virtual machine that will used to create the LXC image. An internet connection is also needed to download the iso and also for the LXC userspace tools to fetch the core packages for the system. The process can be broken down into a few distinctive steps:
- Create an LXC container
- Add the QVD repositories and install the Virtual Machine Agent (VMA)
- Tailor the desktop to your requirements and add an administraive user
- Shut down and tar the image
- Ensure your QVD environment is set up for LXC
- Load the image in QVD
To create our LXC container, we will use a clean install of the Lubuntu Desktop to ensure our base environment is uncontaminated by configuration changes that may be problematic down the line. We will use Lubuntu 12.04 as it provides the excellent Lightweight X11 Desktop Environment (LXDE), and to ensure compatibility with the Ubuntu Ubuntu 12.04 LTS release which makes an ideal node server and for which we release QVD packages. As we will be sharing the kernel with the host machine, it is of course strongly advisable to ensure that our hosts and our guests are identical or near identical systems so using a different distro to the host machine is all but out of the question.
The Lubuntu iso can be found on the Lucuntu Precise Alternate download page , or using this direct link. Once downloaded, check the md5sum of the iso which should match a277a7d3b8a6fc1dd98e65adb5262493, and proceed with a basic install. You may of course do this inside the freely availableKVM or Virtualbox, that is beyond the scope of this guide. Let’s just assume that you have a fresh install of Lubuntu 12.04 , and the means to access it via the command line.
Log in to your fresh install and the LXC userspace tools. We will assume you are root throughout the course of this tutorial, so sudo -s before you start out.
# apt-get install lxc
That done, create a file called lxc.conf somewhere convenient, and populate it with the following network settings:
lxc.network.type=veth lxc.network.link=lxcbr0 lxc.network.flags=up
The first line will tell lxc that we wish to use a virtual ethernet device which is an ethernet-like device that can be used inside a container. The second line gives lxc the name of the network bridge that we want the container to utilise to connect to the network. Finally, we set the network as up.
Now let’s create a new Linux container:
# lxc-create -n qvd-vm -t ubuntu -f lxc.conf
This will download and cache the Ubuntu core packages into /var/cache/lxc/precise/rootfs-amd64 (assuming 64 bit). The first time you do this it will take a little extra time compared to subsequent builds as it will pull down the core packages from the Ubuntu servers to install inside the container. The next time you create a container using the same template (in this case ubuntu), these packages will be reused so it will be quite a bit quicker.
Once downloaded, lxc-create will install the packages into /var/lib/lxc/qvd-vm/rootfs which is effectively the root folder of the container. Above that folder, in /var/lib/lxc/qvd-vm you will find the file config which will contain the conf settings you created, lxc.conf, should you need to change anything.
When the install is complete, start the container:
# lxc-start -n qvd-vm
Log in using ubuntu as both username and password. This account has sudo rights, so go ahead and sudo -s to continue as root. Next you need to add the QVD 3.1 PPA so that you can install the QVD Virtual Machine Agent which enables each desktop to communicate with the client via the QVD node.
# apt-get install python-software-properties # apt-add-repository ppa:qvd-qindel/qvd-3.1 # apt-get update # apt-get install perl-qvd-vma
|Note||To add the PPA as per the previous step you will need to install python-software-properties. This will however add this will add about 27MB to the install, so if space is an concern, rather add the following to /etc/apt/sources.list.d/qvd-qindel-qvd-3_1-precise.list
deb http://ppa.launchpad.net/qvd-qindel/qvd-3.1/ubuntu precise main deb-src http://ppa.launchpad.net/qvd-qindel/qvd-3.1/ubuntu precise main
It is essential that the Virtual Machine Agent starts on boot or the desktop will not be accessible. To do that, we add a symlink to runlevel 2:
# ln -s /etc/init.d/qvd-vma /etc/rc2.d/S99qvd-vma
Although LXC has copied the rudimentary system over to the container, the template does not allow for a desktop environment, so we will need to install that.
# apt-get install lubuntu-desktop
This would also be a good time to install any additional desktop software that our users may need, so go ahead and install any office software, graphics software and so on using apt as above. That done, it’s time to configure the Virtual Machine Agent. Create the qvd directory:
# mkdir /etc/qvd
And then create the file /etc/qvd/vma.conf and populate it with the following options:
vma.audio.enable: 1 vma.printing.enable: 1 command.x-session: /usr/bin/startlubuntu
This will share the node’s printers with the desktops and enable audio. Finally, command.x-session uses the startlubuntu xsession script. This defaults to /etc/X11/Xsession for regular editions of Ubuntu and SUSE.
|Important||We have discovered that startlubuntu does not honour the /etc/default/locale settings, so if our locale needs to be changed from the default, we create the wrapper script /usr/local/bin/startlubuntu. In there, we source the /etc/default/locale variables, export them, only then invoking startlubuntu:
#!/bin/bash [ -r /etc/default/locale ] && . /etc/default/locale export LANG LANGUAGE LC_MESSAGES LC_ALL /usr/bin/startlubuntu
Before we log out, we will need to add a user other than the default ubuntu user on the container, and give that user sudo permissions for maintenance:
# adduser qvd # usermod -aG sudo qvd
Now we log out and back in with our new user and (as root) remove the default user and home directory:
# deluser ubuntu # rm -rf /home/ubuntu
|Note||At this point we could delete the user with the –remove-home switch but this requires the perl-modules package which brings, along with dependencies, another 32MB to the install. It’s up to to the use case and space constraints of course.|
Branding and customisation of the desktop environment is beyond the scope of this guide, but there is a list of resources at the end to assist with this.
Once you have desktop that you want for your users, you can close down the container in preparation for zipping up the image.
Back in your host machine we zip up (as root) the root file system of the container for deployment in QVD:
# tar czf ubuntu-12-04.tar.gz -C /var/lib/lxc/qvd-vm/root
We now have the our gzipped and tarred image. Upload it to your node server if you have built it on another machine, and then copy the file over to the directory /var/lib/qvd/storage/staging which it will be available as an image file in the QVD Web Administration Tool, ready for deployment as a Disk Image. You should also ensure that your QVD installation is set up for LXC virtualisation as it’s a binary decison, you cannot serve both KVM and LXC desktops at the same time. This can be achieved by invoking the QVD admin tool as follows:
# qa config set vm.hypervisor=lxc
And that concludes our creation of an LXC disk image for QVD. As you can see, it’s a really quick and easy process and allows for almost endless customisation of the desktop you wish to provide your end user. Another of the many benefits of choosing the QVD as your VDI solution.
To make your customisation and branding global, rather than use the home directory for your user account (which is really just your administrative account for the image), changes need to be made in the /etc/skel directory, which acts as a template for new users’ home directories when new users are added. QVD conforms to this practice, so each new Virtual Machine will create a home directory based on this folder in the Disk Image. For the PCManFM use /etc/skel/.config/pcmanfm/lubuntu/pcmanfm.conf and for LXPanel use /etc/skel/.config/lxpanel/Lubuntu/panels/panel. What follows are a couple of links to resources on configuring these components.
Guide to LXPanel on the LXDE:
Guide to PCManFM (the LXDE file manager but also used for wallpaper settings and other customisations) on the Arch Wiki