Ubuntu as your hypervisor

Mon 27 February 2012

Ubuntu is a free server operating system that is easy to maintain and build on.  I'm a big fan; and recently, I've been using it to run our development environments at the office.  If, like us, you're looking to build a low-cost environment for non-production work, here's an article that may be a useful start.

Note that many production environments run on KVM - the setup I describe below would need some tweaking, especially from the hardware side, before it would be ready for that...  And while I do talk about production versus staging considerations throughout the article, there are some fundamental aspects that I do not talk about and which should be in the very least touched upon for production -- such as setting up your environment with redundant compute nodes and redundant gigabit switches that are separate from your LAN switches, enabling of jumbo frames, disabling of multicasting, use of an iSCSI SAN with snapshotting and replication capability, not to mention your hardware's scalability -- please do therefore be mindful of the fact that, while this article is sufficient for development and testing, you should consider it as incomplete for a production environment.  Ye be warned.

Getting Ubuntu up and running

  • To get started, you’ll need Ubuntu Server. If you’re planning to use the server for production, download the latest LTS; otherwise, you can just get the latest version.

  • You’ll need the hardware to run the hypervisor, of course. Make sure that the machine that you use has ample CPU’s (64-bit processors with hypervising instructions), memory, and storage space (RAID-1 15K SAS should be sufficient for a production environment as long are you’ve got a SAN for storage; if your physical host is also supposed to be storing the VM’s, I assume this is a test or dev environment -- I’d recommend at least two SATA drives in RAID-0). If you have spare hardware, I would definitely recommend setting up one machine as an iSCSI or NFS SAN instead.

  • Run the Ubuntu Server installation on your compute node. I won’t walk you through the installation, as this is not a KB article on setting up Ubuntu. However, do make sure you at least consider the following:

    • You may wish to set up your storage partitions as LVM so that you can add disks later (that is, if you’re using your compute node as a storage device as well)
    • When prompted for the services to install, you should at least set up openSSH and VM Server services.
  • Once your system is installed, you may wish to set up your public-key authentication. You can find information on how to do this in putty here: http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/pka-putty.html

  • Make sure that you have all the necessary libraries: apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils openssh-server virt-manager convirt

  • Set up your putty server profile (skip for Linux users):

    • Specify the host address
    • Specify the auto-login username in Connections > Data
    • Enable X11 forwarding in Connections > SSH > X11
    • Specify the private key file to be used in Connections > Auth (if applicable)
    • Make sure you have Xming installed. It needs to be running when you run putty.
  • If you’re using linux, when you connect via SSH be sure to specify the X11 parameters and public key parameters like so:ssh <host> -X -i <private key file> Private keys can be generated using ssh-keygen as described here:https://help.ubuntu.com/community/SSH/OpenSSH/Keys

  • At this point, your host should be ready to be used. You can create the VM in two ways:

    • run virt-manager and create the machine using the GUI
    • run ubuntu-vm-build with syntax like this:sudo ubuntu-vm-builder kvm hardy --addpkg vim --mem 256 --libvirt qemu:///system


The tools below are for Windows clients only -- they are not needed for linux as the functionality is built-in:

Putty-- Windows SSH client with some nifty advantages: you can create server profiles, set them to use public key authentication, enable X11 forwarding and TCP tunneling, all from a GUI.**

X-ming -- Windows X server that allows you to run Linux graphic applications remotely over SSH. Used with putty, you can run apps such as ghex or gedit from your Windows machine.

The tools  below are for managing the hypervisor. They are Linux applications, which is why you need the above tools if you’re running Windows

virt-manager -- GUI interface for creating, starting, stoping or moving VM’s.

virsh -- Command-line equivalent of virt-manager. Practical when you just want to start or shutdown a VM.

Useful commands:

virsh list --all → lists all machines running on the host

virsh start <machine name> → starts the machine

virsh shutdown <machine name> → attempts to gracefully shut down a VM

virsh suspend <machine name> → pauses the VM

virsh destroy <machine name> → forces the VM off

virsh can be used to migrate machines live from one host to another. Use this syntax:

virsh migrate --live<name of the machine> qemu+ssh://<destination/<physical host name>/system

convirt -- similar to virt-manager, this GUI tool purportedly allows you to drag & drop VM’s from one server to another. Still under evaluation.

Next Steps

Here are a few next steps that you may wish to consider for enhancing your hypervised environment:

Set up NFS4 shares, so that you can share VM’s and migrate them from one compute node to another: https://help.ubuntu.com/community/NFSv4Howto Set up a bridge so that your VM’s can use the LAN: https://help.ubuntu.com/8.04/serverguide/C/libvirt.html

NOTE FOR LINUX MACHINES: when cloning a linux machine, don't forget to delete /etc/udev/rules.d/70-persistent-net.rules:http://muffinresearch.co.uk/archives/2008/07/13/vmware-siocsifaddr-no-such-device-eth0-after-cloning/