LXC Linux Containers for fun and profit

Last edited
LXC Linux Containers provide a great and fast virtualisation solution

Linux a great platform for virtualisation

Linux offers a number of solutions to different levels of virtualisation.

  • KVM: full virtualisation, part of the stock kernel
  • XEN: full virtualisation, needs a modified kernel
  • LXC Linux Containers: operating system-level virtualisation, part of the stock kernel
  • OpenVZ: operating system-level virtualisation, needs a modified kernel

A stock kernel is allways to be preferred above a modified kernel. Kernel modification will introduce new and unexpected problems. So whenever is it possible, stick to unmodified, stock kernels. That is why we use KVM virtual machines and LXC Linux Containers.

LXC Linux Containers, FreeBSD Jails and Solaris Zones are all implementations of operating system-level virtualisation.

LXC Linux Containers the other route to virtualisation

When thinking about virtualisation, probably the first thought will be about virtual machines. Running a virtual machine on top of a host requires at the loading and executing of least two kernels: the host-kernel and the guest-kernel. Virtual machines require lots of resources.

Very often full virtualisation is not needed and containers virtualisation will do fine. Containers virtualisation or operating system-level virtualisation is very efficient and very fast. Also it is easy to implement and a can provide a lot of fun.

The container technology is part of the Linux kernel. It is actively being worked on. LXC Linux Containers aims to use these new functionalities to provide an userspace container object which provides full resource isolation and resource control for an application or a system. It can be used to isolate one application or a complete system.

Light weight virtualisation

Because LXC Linux Containers offers a light weight virtualisation no special hardware is needed.

Containers virtualisation add almost no extra load on the host. This makes it possible to run LXC Linux Containers effectively on low power machines. I do run several LXC Linux Containers on a 600 MHz VIA EPIA ME6000 LVDS Mini-ITX motherboard!

I do run a few containers with Debian Lenny or Debian Squeeze systems. But most of my containers run dedicated systems build around busybox.

Busybox inside a Linux container

It is not difficult to build a dedicated system based on busybox. First choose your application carefully. Do you really need Apache, PHP and tons of libraries to run that website? Think about running a light weight http-server. The less libraries and helper applications your system needs, the easier it is to build a dedicated system for it.

Start with downloading busybox. First run a defconfig followed by a menuconfig. Turn the unneeded options off. Now build your busybox and put that in a container. Add the needed libraries. Add the dropbear light weight sshd server. Create an inittab and a rcS. Put it in a container and start it up. Amaze yourself with ps aux: only four (4 !) processes!

ps aux
    1 root       0:00 init
    7 root       0:00 -sh
    8 root       0:00 /sbin/dropbear
    9 root       0:00 ps aux

Now add the application you need, by adding the binary and the libs you need. Ldd can provide information about the needed libs.

Green, energy efficient virtualisation

Because LXC Linux Containers offers a light weight virtualisation it is a great solution to provide green, energy efficient virtualisation. So help to safe the planet and kill a few of your boxes and replace them by virtual systems running inside a LXC container.

Last updated: $Date: 2010-08-25 19:33:42 $