The Caffeinated Penguin

musings of a crackpot hacker

lxc basic howto

Posted By on February 20, 2010

largely from:

With additional notes from:

  1. Note that you likely want to create a separate partition for machines and put the machines there.
  2. apt-get install lxc debootstrap (Note – this is pretty inefficient in terms of space. The lxc setup does allow for read-only mounts of things. So, it can have its own /etc and html docs but share binaries and libraries with the host. But, I didn’t do it that way for ease of backups)
  3. Set up cgroup

    mkdir /var/cgroup
    mount -t cgroup cgroup /var/cgroup
    • probably want to add it to /etc/fstab as well:
      cgroup          /var/cgroup     cgroup      defaults              0       0
  4. Add a bridged network interface:

    brctl addbr br0
    brctl setfd br0 0
    • bring up the bridge with a given IP
      ifconfig br0  promisc up
    • add the existing interface and set it to a bad
      brctl addif br0 wlan0
      ifconfig wlan0 0.0.0.0 up
  5. Bootstrap a basic system

    mkdir machine
    sudo debootstrap --arch i386 karmic machine
  6. Create a config file:

    lxc.utsname = my_ssh_container
    lxc.network.type = veth
    lxc.network.flags = up
    lxc.network.link = br0
    lxc.network.ipv4 = 192.168.9.151/24
    lxc.network.name = eth0
    lxc.mount = /var/lxc-machines/machine/fstab
    lxc.rootfs = /var/lxc-machines/machine/rootfs
    
  7. Create the machine:

    lxc-create -n trac -f /var/lxc-machines/machine/config
  8. edit the appropriate files on the guest

    /etc/fstab:
    none    /dev/shm    tmpfs  defaults 0 0
    none    /proc       proc   defaults 0 0
    none    /dev/pts    devpts defaults 0 0
    none    /sys        sysfs  defaults 0 0
    • /etc/resolv.conf
    • /etc/hosts
    • /etc/hostname
    • Set them up correctly
  9. remove the following files:
    rm control-alt-delete.conf hwclock.conf \
    hwclock-save.conf mountall.conf mountall-net.conf \
    mountall-reboot.conf mountall-shell.conf \
    networking.conf procps.conf rsyslog-kmsg.conf \
    tty2.conf tty3.conf tty4.conf tty5.conf \
    tty6.conf upstart-udev-bridge.conf
    
  10. Create lxc.conf to generate things:
    start on startup
    script
        >/etc/mtab
        mount -a
        initctl emit virtual-filesystems
        initctl emit local-filesystems
        initctl emit remote-filesystems
        initctl emit filesystem
        ifdown eth0
        ifup eth0
    end script
    
  11. /etc/apt

    grab the sources.list from the host (if guest is same as host) or make one

  12. /etc/init/rc.sysinit.conf
  13. bootstrap a basic bash so the various nice utilities work:

    lxc-start -n trac bash
    • add user.
    • add admin group
    • set sudoers to allow admin group
    • add user to admin group
    • Generate locale:
      sudo locale-gen en_US.UTF-8
  14. Start the machine:

    lxc-start -n machine init &
  15. Start for real:

    lxc-start -n machine
  16. Notes:

    • Console:

      sudo lxc-console -n machine
    • Debugging:
      lxc-start -l DEBUG -o $(tty) --name machine

Comments

Loading Facebook Comments ...

Leave a Reply

Please note: Comment moderation is currently enabled so there will be a delay between when you post your comment and when it shows up. Patience is a virtue; there is no need to re-submit your comment.