Setting Up Linux LXC Virtualization

LXC virtualization is included in the 2.6.29 Linux kernel, so many recent distributions support it without the need to install a custom kernel. In particular Debian Squeeze and Ubuntu 10 and later include an LXC-capable kernel and tools.

LXC is a kernel-level virtualization type, in which each virtual system's files are stored under a directory on the host system, typically under /var/lib/lxc . All virtual systems share the same kernel with the host and each other, which reduces per-system overhead.

For LXC containers to access the host system's network, you must setup a network bridge. These instructions assume that your host system has only one network interface, and it is eth0 .

Setting up LVM

Recently LXC versions support creation of containers whose filesystem is stored on an LVM logical volume, which puts a limit on the amount of space the container can consume on the host. The limit can be adjusted by Cloudmin by increasing and decreasing the size of the LV. Without an LVM volume group to create LVs in, you will not be able to create containers with a disk limit, so keep this in mind when installing the host system OS. Ideally the host's filesystem will be in a logical volume that does not consume all the disk space available in the volume group.

Setting up a Fedora Host System

To setup a Fedora 12 or later system to host KVM instances, the steps to follow are :

  1. SSH in as root and install the LXC packages with the command yum install lxc bridge-utils
  2. In the /etc/sysconfig/network-scripts directory, copy ifcfg-eth0 to ifcfg-br0.
  3. Edit the new file and change the DEVICE line to DEVICE=br0.
  4. Edit the ifcfg-eth0 file, and at the bottom add the line BRIDGE=br0
  5. Apply the network settings with the command service network restart . This should be done at the console, as it will break network access to the host system if anything goes wrong.

Setting up a Debian or Ubuntu Host System

  1. SSH in as root and install the LXC packages with the command apt-get install lxc bridge-utils
  2. Edit the /etc/network/interfaces file and change it to be like :
    auto eth0 lo br0

    iface lo inet loopback

    iface eth0 inet manual

    iface br0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    broadcast 192.168.1.255
    network 192.168.1.0
    gateway 192.168.1.10
    bridge_ports eth0
    bridge_fd 9
    bridge_hello 2
    bridge_maxage 12
    bridge_stp off

  3. Apply the network settings with the command /etc/init.d/networking restart or by rebooting . This should be done at the console, as it will break network access to the host system if anything goes wrong.

Adding a New Host System

  1. Install Webmin on the host system, if it isn't already.
  2. Add the host system to Cloudmin at Add System -> Add physical system, if it isn't already.
  3. Go to Host Systems -> LXC Host Systems, click the Register a system for LXC hosting link and select your new host machine.
  4. Enter an IP range to allocate to virtual systems, and a DNS domain to add new systems to.
  5. Click the Register button.