Saturday, 21 January 2012

Xen Part 1: Beyond *nix: Running a Hypervisor

It's an ugly fact: most people run Windows.

They run one computer, with one monitor, and one Operating System. Yet the simplicity of the setup belies its power: with the move to cloud computing well and truly underway, one could argue that the host OS is becoming little more than a middleman, shuffling requests back and forth between server and client, and finally rendering the results on-screen. All that one needs is a web browser, and thanks to cloud computing services (such as Google Docs, for example), the world is their oyster.

Virtualisation in Enterprise

Cloud computing providers, much like other large institutions which heavily rely on technology, make use of virtualisation technologies. The idea is to provide greater flexibility and reliability through the abstraction of the OS from the underlying hardware. An OS doesn't need to run directly on hardware: an OS can run on an OS, which itself runs on hardware. Alternatively, an OS can run on a special kernel, capable of running other OSs simultaneously. We are of course talking about hypervisors.

The world of high performance grid computing, on-demand hardware provisioning and bare-metal virtualisation can seem a world removed from our day-to-day home computing requirements. Who wants to go through all the hassle of setting up an enterprise-grade hypervisor, when a web browser (like we get on our phones and tablets) offers us all we need?

Virtualisation and Us

The thing is, not all of us fit into the single-OS thin-client paradigm. Some of us have more demanding hardware requirements. Others have pronounced security concerns. Some people simply need to run multiple OSs (such a *nix for work & reliability, and Windows for play & Photoshop - or are they one and the same thing?). Others are seeking a solution to poor reliability.

Hypervisors provide a base to run multiple operating systems simultaneously and switch between them seamlessly. It's a very similar concept to Virtual Machine software such as Virtualbox and VMWare. Windows crashed again and need to reboot? Don't reach for the power switch - just click the button. Reload the previous snapshot. Assign your Solaris installation some more RAM so it can handle an increase in requests. Switch back to Linux. Then maximise your Windows window so you can load that darned .pptx file some ignoramus sent you via e-mail.

Virtual Machines

If you haven't spun up a VM before, try it now - it's free, easy and, above all, impressive to behold. Download and install Virtualbox (my preference), and then download a copy of whichever OS you'd care to try - the latest version of Ubuntu, for example. You'll then need to start Virtualbox, create a new VM, and finally start the VM pointing to the Ubuntu disk image (or CD if you burnt it). You will then install Ubuntu into the VM, all the time running it inside a window on your desktop, which you can resize, minimise and maximise like any other. Googling "Virtualbox tutorial" will throw up hundreds of walkthroughs to guide you through the process, and a similar search on Youtube will provide ample video walkthoughs too. The process doesn't take very long.

In this case, the "guest OS" (Ubuntu in the above example) is running as a VM. It is being executed by the Virtualbox code, which itself is running on your "host OS". This is all very cool, but it has a few limitations. One of the limitations is that the guest OS will be relatively slow (fast enough for most tasks, but it's going to be considerably slower than your host OS). This is because the guest OS code first has to be processed by Virtualbox before being passed to the host OS's kernel. It would be better if we could skip the middleman. This is one of the many benefits of hypervisors.

Virtual Machine Monitors 

Hypervisors (i.e. VMMs) take the VM concept and go the extra mile. They run on what is known as "bare metal" - i.e. your physical hardware. Instead of me lecturing on about them, you may as well read this excellent Wikipedia article which expresses it better than I'd be likely to.

Read that? Good. (In case you've gone down the schoolboy route of assuming you'll read it later, I'll reiterate the main point I wanted to you take from it). As you've undoubtedly noted already, there are two main types of hypervisor. One runs on top of another operating system (much like Virtualbox), and one is a cut down version of an operating system itself (like the Linux kernel). There are many good examples of each, but of particular note, KVM is taking off in the case of the former, and Xen is the primary open-source player in the latter. However, there are many good choices, and your choice will depend on your particular requirements. It may be that the excellent OpenVZ would suit your purposes just fine. Or perhaps you might feel like VMWare's proprietary ESX is what is required. Whatever the case, you'll need to do your research: as ever, Google is your big brother.

The Case for Xen

If, like me, you determine that:
  • You want a highly performant solution - Virtualbox isn't going to be the answer
  • You want the ability to run games/advanced 3D rendering, i.e. perform. VGA passthrough - that unfortunately rules out KVM for the time being (unless you have a lot of spare time)
  • You want an open source solution - scratch all of VMWare's products off the list
  • You want to run OSs other than Linux - OpenVZ isn't going to cut it
  • You've done your research
  • Xen seems to offer everything you need
then keep reading, as I try to untangle the process of setting up Xen on a Linux host, installing multiple guest OSs (Windows included), getting the management tools working, and finally preparing PCI passthrough - dedicating graphics cards to particular guests.

The final outcome - which I hope you'll be able to duplicate - will be a PC running Linux, with another Linux virtual machine for daily usage, and a Windows virtual machine for gaming. It will sit on a RAID1 redundant base, have rock-solid stability, display across a number of monitors, and generally solve the problems of the world.

So sit back, grab a beer, and guffaw at my expense as I try to walk you through this daunting process.

If it all runs like clockwork, I'll eat your hat.

Next > Part 2: Hardware Requirements for Xen