Monthly Archives: November 2009

In-flight internet and LXC working in libvirt

Interesting day, flying from Montreal, Quebec to Dallas, Texas for the Ubuntu Developer Summit.
I have been able to try American Airlines’ in-flight wireless, it works surprisingly well, I get a stable 80ms latency to my home server and a quick bandwidth test gives me some 100kB/s.

On a completely different topic but still somewhat related, on that same flight, I have been able to install the latest libvirt packages I uploaded this morning to my PPA.

It’s the first time I actually manage to get networking to work with LXC in libvirt using libvirt’s network configuration.

I’ll be trying to convert some of the UDS attendees so they try it out and help making it work just fine in Lucid. Having that and kvm supported by libvirt will make Ubuntu a rocking platform for virtualization/contextualization.

Quick quote from my first test (starting the container, entering it, setting up network with DHCP, pinging my home server):

root@castiana:~# sudo virsh --connect lxc:///
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # start shell
Domain shell started

virsh # console shell
Connected to domain shell
Escape character is ^]
root@castiana:/# dhclient3 eth0
There is already a pid file /var/run/dhclient.pid with pid 29
removed stale PID file
Internet Systems Consortium DHCP Client V3.1.1
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

Listening on LPF/eth0/52:54:00:d8:9b:96
Sending on   LPF/eth0/52:54:00:d8:9b:96
Sending on   Socket/fallback
DHCPREQUEST of 192.168.122.78 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.122.78 from 192.168.122.1
bound to 192.168.122.78 -- renewal in 1749 seconds.
root@castiana:/# ping athos.stgraber.org
PING athos.stgraber.org (24.200.46.78) 56(84) bytes of data.
64 bytes from modemcable078.46-200-24.mc.videotron.ca (24.200.46.78): icmp_seq=1 ttl=43 time=94.1 ms
^C
--- athos.stgraber.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 94.124/94.124/94.124/0.000 ms
root@castiana:/# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  17636  1772 pts/0    Ss   20:16   0:00 /bin/bash
root        29  0.0  0.0   6488   440 ?        Ss   20:16   0:00 dhclient3 eth0
root        31  0.0  0.0  14892  1028 pts/0    R+   20:16   0:00 ps aux
root@castiana:/# 

Posted in Planet Ubuntu | Leave a comment

LXC containers or extremely fast virtualization

Update: Added an hardy i386 template, mentioned the need of bridge-utils and fixed typo (s/addbr/brctl addbr/g)

This (quite long) post is about the LXC (Linux containers), an example of its usage on Karmic is provided after the introduction to contextualization.

Most of you are probably already familiar with “usual” virtualization as kvm/virtualbox/vmware/… These are now extremely fast ways to do “full” virtualization of an OS on a host running either the same OS or a completely different one.
In Ubuntu, the most widely used is probably KVM used with libvirt and virt-manager as frontend.

At Revolution Linux, we have literately hundreds of virtual machines for each of our customers and we noticed that they are all Ubuntu virtual machines running on Ubuntu hosts. Then, running them in a “full” virtualization environment adds unneeded overhead and makes resource assignment quite difficult (you can’t easily change the CPU/RAM/DISK/NIC of a running virtual machine).

So, what we are currently doing is using contextualization instead of regular virtualization.
Contextualization can (in a much simpler way) be seen as improved chroots, these “chroots” are called containers and work just like a regular virtual machine, inside them you have your own network interface, can apply disk/cpu/ram quotas and start/stop/suspend as many of them as you want.
All the quotas and restrictions can be changed on the fly without needing any restart, because it’s technically just a set of process running on the host, not a single process as with virtualization.
It also means that you can list/kill or execute a process in any of these containers, directly from the host (a container obviously can’t access another’s processes).

The technology we have been using for more then a year now has been OpenVZ (open source implementation of Virtuozo) which basically is a huge patchset on top of the Linux kernel and only exists in Ubuntu hardy (8.04 LTS).

What I’ve been looking at more recently and hope to have working correctly in Lucid (10.04 LTS) is LXC. LXC is basically the same as OpenVZ except that it’s in the upstream kernel and uses already existing kernel features such as “cgroups” for example.
LXC is also supported by libvirt although it’s not working in Karmic, that will let users play with it just like any other virtualization technology using their existing scripts and interfaces.

Here’s a quick howto to make it work on Karmic with an Ubuntu 8.04 amd64 container (I’ve had issues making Karmic to work in a container):

  • Install bridge-utils: sudo apt-get install bridge-utils
  • Install LXC from my PPA (upstream snapshot) : https://launchpad.net/~stgraber/+archive/ppa/+packages
  • Create /var/lib/lxc/: mkdir -p /var/lib/lxc/
  • amd64 template (if your computer is running Ubuntu 64bit): Get http://www.stgraber.org/download/lxc-ubuntu-8.04-amd64.tar.gz (Hardy amd64 image)
  • i386 users (if your computer is running Ubuntu 32bit): Get http://www.stgraber.org/download/lxc-ubuntu-8.04-i386.tar.gz (Hardy i386 image)
  • Uncompress it in /var/lib/lxc/ (will create an ubuntu directory containing a configuration file and a root directory)
  • Mount cgroups somewhere: sudo mkdir /dev/cgroup && mount -t cgroup none /dev/cgroup
  • Create a bridge with: sudo brctl addbr br0
  • Set an IP on the bridge: ifconfig br0 192.168.2.1 (VE will be 192.168.2.2 by default)
  • Start the VE: lxc-start -d -n ubuntu
  • Enter the VE: “lxc-console -n ubuntu” or “ssh root@192.168.2.2” (root password is “password”)

The VE (virtual environment) configuration file is in: /var/lib/lxc/ubuntu/config

Additional information can be found on:

Also, I plan to have a session about it at UDS-Lucid in Dallas

Posted in LXC, Planet Ubuntu | 19 Comments