You are not logged in.

#1 2012-06-24 14:58:43

dlin
Member
From: Taipei,Taiwan
Registered: 2005-09-21
Posts: 265

How to setup linux container(lxc)

I'm trying to setup LXC (refer the wiki) to let me try my network client/server programs in one machine.
But, I can not get the points in the messy wiki.
Can any one give me some hints?  It is much difficult than virtualbox.

Here are my steps.

1. Kernel configuration:
  I think it is not necessary, just use linux 3.4.3-1 (x86_64)  is enough.
  just skip the warning in output of lxc-checkconfig:
    File capabilities: missing

2. Host configuration:
   I've setup cgroup, lxc, bridge.

3. Container setup:
* Creating the filesystem - I don't know how to creat it, lxc package don't contain /usr/bin/lxc-debian.  I just want arch linux, or minimal linux, like puppy,slitaz.
* Creating the device nodes - require it or not?  on the previous filesystem or where?

4.Container configuration:
* Configuration file: is there any example?  I don't understand the long description. 

5. Container Creation and Destruction:

I've tried '''lxc-create -n v1''',  it just create a zero length file in /var/lib/lxc/v1/config.


Running 4 ArchLinux including sh4twbox,server,notebook,desktop. my AUR packages

Offline

#2 2013-01-02 18:53:50

glemt9
Member
From: Slovenija
Registered: 2011-11-28
Posts: 10
Website

Re: How to setup linux container(lxc)

I created my first container long time ago and now I just switched to systemd and it is... well... strange... but...

...here is my example, hope it helps, almost the same as wiki:

1. I use netcfg for network (server is also a router) - br0 is my network bridge device

2. create config /etc/lxc/lxc-kanta.conf

lxc.utsname = kanta
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.network.hwaddr = FF:FF:FF:FF:FF:FF (change it to something else)
# use 0.0.0.0 below for DHCP
lxc.network.ipv4 = 192.168.1.5/24 (or something else)
lxc.mount = /etc/lxc/lxc-kanta.fstab
lxc.rootfs = /lxc-pool/kanta (where you container will be located)
lxc.tty = 3 (read below)

after switching to systemd, I don't know how to control tty, with sysinit I disabled other getty on host to avoid conflicts:
Host (old version - with initab):

c0:2345:respawn:/sbin/agetty 115200 ttyS0 linux
c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
#c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
#c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
#c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
#c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

Guest, just enable:

c1:2345:respawn:/sbin/agetty -8 38400 tty2 linux

3. create another config /etc/lxc/lxc-kanta.fstab

none /lxc-pool/kanta/dev/pts devpts defaults 0 0
none /lxc-pool/kanta/proc    proc   defaults 0 0
none /lxc-pool/kanta/sys     sysfs  defaults 0 0
none /lxc-pool/kanta/dev/shm tmpfs  defaults 0 0

4. filesystem and directories
I assume, that you already created/chrooted/installed another system (NON-SYSTEMD!!) on location /lxc-pool/kanta? No?
Well just install one Linux on another disk (USB stick for example) and copy the content of it to location on host system: /lxc-pool/kanta (or somewhere else).

Now create missing directories:

chmod 666 /lxc-pool/kanta/dev/null
mknod -m 666 /lxc-pool/kanta/dev/random c 1 8
mknod -m 666 /lxc-pool/kanta/dev/urandom c 1 9
mknod -m 600 /lxc-pool/kanta/dev/console c 5 1
mkdir -m 755 /lxc-pool/kanta/dev/pts
mkdir -m 1777 /lxc-pool/kanta/dev/shm
mknod -m 666 /lxc-pool/kanta/dev/tty2 c 4 3

5. remove /lxc-pool/kanta/etc/rc.sysinit, cleanup rc.conf and other things as described in wiki, create new rs.sysinit:

#!/bin/bash
# Whatever is needed to clean out old daemon/service pids from your container
rm -f $(find /var/run -name '*pid')
rm -f /var/lock/subsys/*

# Configure network settings
## You can either use dhcp here, manually configure your
## interfaces or try to get the rc.d/network script working.
## There have been reports that network failed in this
## environment.
#route add default gw 192.168.1.1
ip route add default via 192.168.1.1
echo > /etc/resolv.conf search your-domain.net
echo >> /etc/resolv.conf nameserver 192.168.1.1

# Initally we do not have any container originated mounts
rm -f /etc/mtab
#touch /etc/mtab
grep -v rootfs /proc/mounts > /etc/mtab

6. create container

lxc-create -f /etc/lxc/lxc-kanta.conf -n kanta

7. start it... etc...etc...
8. login to console:

lxc-console -n kanta -t 2

Last edited by glemt9 (2013-01-02 19:09:17)

Offline

#3 2013-02-05 15:48:02

starfry
Member
From: Surrey, UK
Registered: 2010-08-18
Posts: 230

Re: How to setup linux container(lxc)

Hello. It isn't often you see anyone on here discussing LXC smile

I have been using it ever since Ubuntu dropped support for OpenVZ (that was actually the catalyst for me moving to Arch at the same time as well - If I needed to change I might as well move to a distro mor suitable to my needs. Another story, anyway.)

My understanding (and I would love for somebody who knows better to correct me), after much discussion  with the LXC and systemd people, is this: LXC does not work with systemd inside the container.

First off, I'll say that I had to put this down due to other commitments but I desparately need to pick it up again because I have about 20 containers that really need to be brought up to the new world of systemd.

My system currently uses systemd on the host but all my containers are stuck using the initscripts.

What I understand is that you need to have "lxc.autodev = 1" in your LXC configuration and this causes LXC to create a 100Kb tmpfs for /dev, overmounting any existing /dev. It creates a pts subdirectory plus the some device nodess (from a hard-coded list) - null, zero, full, urandom, random, tty and console. The question now is how do you create other devices on that tmpfs.

I am prepared to write a patch for LXC to help this work but I need to get my finger out and get on with it.

I'd love to hear other peoples' experiences with LXC inside a container using systemd.

update: interested parties may read the wiki to discover how to run systemd inside an LXC container smile

Last edited by starfry (2013-05-14 10:02:10)

Offline

Board footer

Powered by FluxBB