LXC on Ubuntu

This small howto describes a basic installation Linux Containers on Ubuntu 10.04 Lucid (or on Debian Sid).

A good howto, which describes and explains many things, but Archlinux specific: http://wiki.archlinux.org/index.php/Linux_Containers#Host_device_access_settings

$ apt-get install lxc

$ mkdir -p /var/lib/lxc/cgroup && up  /var/lib/lxc/cgroup  cgroup  defaults  0  0′ >> /etc/fstab

/etc/networ/interfaces:

auto eth0

auto br0
iface br0 inet static
    address 1.2.3.4
    netmask 255.255.255.0
    gateway 1.2.3.254
    bridge_ports eth0
    bridge_stp off
    bridge_maxwait 5

$ mkdir /var/lib/lxc/containers/1

/var/lib/lxc/containers/1/config:

lxc.utsname = <hostname>
lxc.tty = 4
lxc.pts = 1024
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.network.mtu = 1500
lxc.rootfs = /var/lib/lxc/containers/1/rootfs
lxc.cgroup.cpuset.cpus = 0
lxc.network.ipv4 = 1.2.3.5/24
#lxc.network.hwaddr = 4a:49:43:49:79:bf
lxc.cgroup.devices.deny = a # Deny all access to devices

lxc.cgroup.devices.allow = c 1:3 rwm # /dev/null
lxc.cgroup.devices.allow = c 1:5 rwm # /dev/zero
lxc.cgroup.devices.allow = c 5:1 rwm # /dev/console
lxc.cgroup.devices.allow = c 5:0 rwm # /dev/tty
lxc.cgroup.devices.allow = c 5:1 rwm # /dev/console
lxc.cgroup.devices.allow = c 4:0 rwm # /dev/tty0
lxc.cgroup.devices.allow = c 4:1 rwm # /dev/tty1
lxc.cgroup.devices.allow = c 1:9 rwm # /dev/urandon
lxc.cgroup.devices.allow = c 1:8 rwm # /dev/random
lxc.cgroup.devices.allow = c 136:* rwm # /dev/pts/*
lxc.cgroup.devices.allow = c 5:2 rwm # /dev/pts/ptmx
lxc.cgroup.devices.allow = c 254:0 rwm # /dev/rtc0

OpenVZ templates can be used or own templates can be created.
Also precreated templates are available:
http://www.stgraber.org/download/lxc-ubuntu-8.04-amd64.tar.gz
http://www.stgraber.org/download/lxc-ubuntu-8.04-i386.tar.gz

$ chroot /var/lib/lxc/containers/1/rootfs passwd

$ lxc-create -f /var/lib/lxc/containers/1/config -n
$ lxc-start [-d] -n
$ lxc-console -n

avatar

About tompos

Hungary, Budapest
This entry was posted in IT, Linux, Ubuntu. Bookmark the permalink.

Leave a Reply