Ubuntu 12 + lxc + Rackspace

First let’s build an Ubuntu 12 server

cloud> servers create
Server name: lxc-host
Image ID: 125
Flavor ID: 3
   "server" : {
      "status" : "BUILD",
      "progress" : 0,
      "name" : "lxc-host",
      "imageId" : 125,
      "addresses" : {
         "private" : [
         "public" : [
      "flavorId" : 3,
      "hostId" : "c395c82dd1963e52098e77819fda2b86",
      "metadata" : {},
      "id" : 20898849

Make sure everything is up-to-date

root@lxc-host:~# apt-get update
root@lxc-host:~# apt-get upgrade

Install some necessary utilities for this.

root@lxc-host:~# apt-get install lxc debootstrap bridge-utils screen

Now we need to make the bridge in /etc/network/interfaces

# lxc bridge
auto lxcbr0
iface lxcbr0 inet static
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
        pre-down echo 0 > /proc/sys/net/ipv4/ip_forward
        pre-down iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
        bridge_ports none
        bridge_stp off

Activating the bridge…

root@lxc-host:~# ifup lxcbr0

Now it’s time to create the first container. The available templates should be listed here:

root@lxc-host:~# ls /usr/lib/lxc/templates/
lxc-busybox  lxc-debian  lxc-fedora  lxc-opensuse  lxc-sshd  lxc-ubuntu  lxc-ubuntu-cloud

To be special let’s make a fedora guest

root@lxc-host:~# vim /etc/lxc/auto/fedora.conf
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.ipv4 =
lxc.network.name = eth0
lxc.cgroup.cpu.shares = 512
lxc.cgroup.memory.limit_in_bytes = 1024M
lxc.cgroup.memory.memsw.limit_in_bytes = 3072M

But we might need something first

root@lxc-host:~# apt-get install yum

The actual lxc-create syntax

root@lxc-host:~# lxc-create -n fedora-guest -t fedora -f /etc/lxc/auto/fedora.conf 
root@lxc-host:~# vim /var/lib/lxc/fedora-guest/rootfs/etc/sysconfig/network-scripts/ifcfg-eth0
root@lxc-host:~# screen -dmS init-fedora-guest lxc-start -n fedora-guest
root@lxc-host:~# screen -ls
There is a screen on:
	19959.init-fedora-guest	(06/06/2012 09:55:39 AM)	(Detached)

And voila! I’ll admit this fedora install seems somewhat messed up, but that’s a problem with the template itself. You can correct the install or use something else like ubuntu/ubuntu-cloud for better results. Let me know if you have questions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.