Differences between revisions 33 and 34
Revision 33 as of 2012-10-29 16:34:24
Size: 4957
Editor: TpO
Comment: document creating a new lxc in wheezy
Revision 34 as of 2012-10-29 19:00:03
Size: 4932
Editor: TpO
Comment: make fstab entry more likely to be rendered on one line
Deletions are marked like this. Additions are marked like this.
Line 28: Line 28:
cgroup         /sys/fs/cgroup        cgroup defaults     0       0 cgroup /sys/fs/cgroup cgroup defaults 0 0

Translation(s): none


Linux Containers (LXC) provide a Free Software virtualization system for computers running GNU/Linux. This is accomplished through kernel level isolation. It allows one to run multiple virtual units simultaneously. Those units, similar to chroots, are sufficiently isolated to guarantee the required security, but utilize available resources efficiently, as they run on the same kernel.

For all related information visit : http://lxc.sourceforge.net/

LXC is available starting with Debian 5.0 - Lenny (Kernel 2.6.26), however the LXC userspace tools are not packaged for Lenny, so they would have to be built from source. Debian 6.0 - Squeeze has full support for LXC.

Installation

  • Install required packages

aptitude install lxc
  • Install optional packages

aptitude install bridge-utils libvirt-bin debootstrap

Prepare the host

  • Required: Mount cgroup reboot save (since 595964 /sys/fs/cgroup is prepared to mount cgroup, see also 601757)

Add this line to /etc/fstab

cgroup  /sys/fs/cgroup  cgroup  defaults  0   0

Try to mount it (a reboot solves an eventual "resource busy problem" in any case)

mount /sys/fs/cgroup
  • Optional: Enable memory cgroup support (534964) (CONFIG_CGROUP_MEM_RES_CTLR) - Since 2.6.39-bpo60-2 for Squeeze the memory cgroup support is built in, so lxc-checkconfig will give you a green result about this point. At the same time, it is deactivated by default. You need to activate memory cgroup support with a kernel parameter. When using grub2, this can be easily done by adding GRUB_CMDLINE_LINUX="cgroup_enable=memory" in /etc/default/grub and running update-grub2. Same for CONFIG_CGROUP_MEM_RES_CTLR_SWAP - see http://lists.debian.org/debian-kernel/2012/01/msg00804.html .

RootFS creation

Debian Squeeze

  • In theory you may use any tool to create a rootfs (debootstrap, multistrap, rootstock) as long as you are sure, that the result will run inside a container.
  • For the first time and as an example, use the provided creation script of the lxc package.

cp -a /usr/lib/lxc/templates/lxc-debian /usr/lib/lxc/templates/lxc-squeeze
  • (lxc-debian is designed to install lenny, which is no longer accessible from the specified archive.) Edit lxc-squeeze, replacing "lenny" with "squeeze" and "dhcp-client" with "isc-dhcp-client"

lxc-create -n myfirstcontainer -t squeeze

Debian Wheezy

lxc-create -n myfirstcontainer -t debian

This will prompt you on what distribution to install.

Setup networked containers

Start and stop containers

  • To start a container and stay attached to the console run:

lxc-start -n myfirstcontainer
  • To start a container in the background and attached to the console at any time later run:

lxc-start -n myfirstcontainer -d
lxc-console -n myfirstcontainer
  • To halt a container cleanly by the containers initv-system:

lxc-halt -n myfirstcontainer
  • To stop a container without proper halt inside the container:

lxc-stop -n myfirstcontainer
  • To have containers automatically started on booting the host, edit the host's /etc/default/lxc

References

See also :

Known bugs and "got to know issues"

  • 600466 - "Respawning too fast" messages due to missing tty(1234) nodes in generated container rootfs (workaround: remove from container's /etc/inittab}} or {{{mknod -m 660 dev/tty1 c 5 1 for each device)

See also