
# Accompanying Notes for LXC Tutorial

## Arch Linux LXC packages

Pre-built LXC packages for Arch Linux for i686 and x86_64
are in directory "archlinux/lxc". Use at your own risk!!!

    lxc-0.7.5-1-i686.pkg.tar.xz
    lxc-0.7.5-1-x86_64.pkg.tar.xz

## Networking

A brief explanation of how to set up a bridge
on Arch Linux:

  * install "netcfg" package (pacman -S netcfg)
  * create file /etc/network.d/bridge:

    DESCRIPTION="Bridged Network (DHCP host)"
    CONNECTION="bridge"
    INTERFACE="br0"
    BRIDGE_INTERFACES="eth0"
    IP="dhcp"
    FWD_DELAY=0

  * see examples in archlinux/network/*

  * create file /etc/conf.d/netcfg

    echo "NETWORKS=(bridge)" > /etc/conf.d/netcfg

  * Start bridge "netcfg up bridge", or reboot.

For further information:
https://wiki.archlinux.org/index.php/Netcfg#Configuring_a_bridge_for_use_with_virtual_machines_.28VMs.29

## Startup Files

The "archlinux/mycontainer" directory contains suitable startup
files for use in an Arch Linux container. There are four files:

    /etc/rc.sysinit
    /etc/rc.conf
    /etc/rc.shutdown
    /etc/inittab

After creating /srv/mycontainer, copy these files across.

## Precreated Template Examples

The "precreated" directory contans some example configurations 
to demonstrate use of precreated templates from OpenVZ and Ubuntu.

The below have been briefly tested on an
ArchLinux host to ensure they start up ok.

### ubuntu_openvz

This is an example showing how to create a container from an
OpenVZ precreated template.

  * File /etc/lxc/ubuntu_openvz.conf

  * Download template:
    http://download.openvz.org/template/precreated/ubuntu-12.04-x86.tar.gz

  * Extract to /srv/lxc/ubuntu_openvz 
    (or edit configuration for different location)

  * Create Container and start:

    $ lxc-create -n ubuntu_openvz -f /etc/lxc/ubuntu_openvz
    $ lxc-start -n ubuntu_openvz

### ubuntu_cloud

This is an example showing how to create a container from an
Ubuntu Cloud precreated template.

  * File /etc/lxc/ubuntu_cloud.conf

  * Download template from:
    https://cloud-images.ubuntu.com/releases/precise/release-20120424/ubuntu-12.04-server-cloudimg-i386.tar.gz

  * Extract to /srv/lxc/ubuntu_cloud

  * Create Container and start:

    $ lxc-create -n ubuntu_cloud -f /etc/lxc/ubuntu_cloud
    $ lxc-start -n ubuntu_cloud

## VESA Desktop Files

In directory "desktop" there are configuration files for a container
to run a VESA desktop: 

    mycontainer.conf

Also a variant with adjusted network settings for VirtualBox:

    mycontainer-virtualbox.conf

And the XOrg configuration file for input devices:

    10-input.conf

Devices needed by the VESA display driver:

    /dev/vga_arbiter
    /dev/mem

Decice needed by the NVidia display driver:

    /dev/nvidia

## VirtualBox

In case you are tempted to try this out inside a VirtualBox guest:

  * VirtualBox does not support bridging inside a guest.

This means that you can't precicely follow the standard setup
described in the tuturial. Instead, for the networking piece,
do the following:

  * Create a second nic for the vm, call this "eth1", that is
    bridged in the same way as eth0 (i.e to the host's "br0".

  * Arch Linux netcfg examples in network/eth0 and network/eth1.

  * echo "NETWORKS=(eth0 eth1)" > /etc/conf.d/netcfg

  * Configure the networking for the container as follows:

    lxc.utsname = mycontainer
    lxc.network.type = phys
    lxc.network.flags = up
    lxc.network.link = eth1
    lxc.network.link = eth0

This will give the container a nic called eth0 that uses its
host's eth1 (which, as the host is a vm, is liked to its host's
bridge).

VT switching inside the VirtualBox guest is done using the
VirtualBox "host" key (by default the right-hand CTRL key) and
the relevant function key (e.g. for VT3, press the right-hand
CTRL key and the F3 key).

## Tips:

### To change a password inside a container from the host:

    $ chroot /srv/lxc/mycontainer
    $ echo myuser:mypassword | chroot
    $ exit

### To Launch a container using "screen":

If you use the "screen" command to launch a container:

    $ screen -dmS mycontainer  lxc-start -n mycontainer

then you can press "Control+a" then "d" to detach.

To reattach:

    $ screen -r mycontainer

### Backup a container

    cp -a /srv/lxc/mycontainer{,.bak}

End.
