Virtualization (LXC Containers): Difference between revisions

From CSCWiki
Jump to navigation Jump to search
(Major LXC update, remove linux vserver)
m (Fix New CSC Machine link)
Line 19: Line 19:
lxc-attach -n containername
lxc-attach -n containername

Now you're ready to [[New CSC Machine|configure your machine]].
Now you're ready to [[New CSC Machine#After Installing|configure your machine]].

== Networking ==
== Networking ==

Revision as of 15:59, 28 July 2015

As of Fall 2009, we use Linux containers to maintain virtual machines, most notably caffeine, which is hosted on glomag. The various commands to manipulate Linux containers are prefixed with "lxc-"; see their individual manpages for usage.

Creating a new container

Create a new container using `lxc-create`:

# Create new container "containername" with root fs located at /vm/containername
lxc-create --dir=/vm/containername -n containername --template download

This will prompt you for distribution, release, and architecture. (Architecture *must* match host machine.)

# List containers

to ensure that your container has been successfully created; it should be listed. You can also list its root directory if you like. To start it in the background and obtain a root shell, do

# Start and attach a root shell
lxc-start -d -n containername
lxc-attach -n containername

Now you're ready to configure your machine.


Networking might not be enabled on your container by default. If this is the case (easily checked with `ifconfig`), you'll need to modify its config file, located at /var/lib/lxc/containername/config:

# Network configuration = veth = up

# that's the interface defined above in host's interfaces file = br0

# name of network device inside the container,
# defaults to eth0, you could choose a name freely
# = lxcnet0 = DE:AD:BE:EF:70:10 # your favourite fake MAC

# the ip may be set to or skip this line
# if you like to use a dhcp client inside the container = 129.97.134.XXX/24

# define a gateway to have access to the internet =

Management Quick Guide

To manage containers, use the lxc-* tools, which require root privilege. Some examples (replace caffeine with the appropriate container name):

# check if caffeine is running
lxc-info -n caffeine

# start caffeine in the background
lxc-start -d -n caffeine

# stop caffeine gracefully
lxc-halt -n caffeine

# stop caffeine forcefully
lxc-stop -n caffeine

# launch a TTY console for the container
lxc-console -n caffeine

To install Linux container support on a recent Debian (squeeze or newer) system:

  • Install the lxc and bridge-utils packages.
  • Create a bridged network interface (this can be configured in /etc/network/interfaces as though it were a normal Ethernet device, with the additional bridge_ports parameter. This is usually called br0 (can be created manually with brctl). LXC will create a virtual Ethernet device and add it to the bridge when each container starts.

To start caffeine, run the following command as root on glomag:

lxc-start -d -n caffeine

Containers are stored on the host filesystem in /var/lib/lxc (root filesystems are symlinked to the appropriate directory on /vm).