LXC (Linux Containers) For Debian Squeeze

Today i migrated my vservers to LXC. LXC is similar to Linux VServers and OpenVZ but with one big difference. You don’t need to install a custom/patched Kernel for LXC since the support is included within the Kernel Mainline. As for Debian Linux VServers support will be dropped in future releases. This means LXC is the way to go. Okay enough talking. Lets get to work.<a id="more"></a><a id="more-554"></a>

Setup

  1. Install Linux Containers

apt-get install lxc
  1. Add cgroup mount point:

mkdir -p /var/local/cgroup
echo "cgroup  /var/local/cgroup  cgroup  defaults  0  0" >> /etc/fstab
mount -a
  1. Install bridge utils

apt-get install bridge-utils
  1. Convert your eth0 configuration into a br0 bridge configuration:

# The primary network interface
#auto eth0
#allow-hotplug eth0
#iface eth0 inet static
#address 192.168.10.1
#netmask 255.255.255.0

auto br0
iface br0 inet static
   bridge_ports eth0
   bridge_fd 0
   address 192.168.10.1
   netmask 255.255.255.0

Please keep in mind that this change might also affect your firewall settings and/or other connections.

  1. Enable IP forwarding

echo 1 > /proc/sys/net/ipv4/ip_forward
  1. Create a new container. I used a modified version of the lxc-debian template script from Daniel Lezcano which is included in the LXC debian package. It can be found here /usr/lib/lxc/templates/lxc-debian. The modfied version can be downloaded <a href="/downloads/lxc/lxc-debian">here</a>.

wget http://www.jotschi.de/downloads/lxc/lxc-debian
chmod +x lxc-debian
./lxc-debian
./lxc-debian squeeze test 2

Your container with the name test will be installed at /var/lib/lxc/test.

  1. Adapt container network configuration For my configuration i had to adapt the resolv.conf and the /etc/network/interfaces file. I changed the nameserver to 192.168.10.1 since my nameserver is running of that ip.

nameserver 192.168.10.1

I also adapted the container /etc/network/interfaces file.

auto eth0
iface eth0 inet static
    address 192.168.10.26
    netmask 255.255.255.0
    gateway 192.168.10.1

You can edit those file outside of your conainer by editing:

/var/lib/lxc/test/rootfs/etc/network/interfaces
/var/lib/lxc/test/rootfs/etc/resolv.conf
  1. Start the container

lxc-start -n test -d
  1. Enter the conainer

lxc-console -n test

The default login is root/root.

Use this manual for migrating linux vservers to lxc: