First release is available.

Some assumptions :
- The daemon for cgmanager is running. you can find for s6 the package cgmanager-s6serv, just install and enable it. For runit you need to create your own by the classic way and put on you run file : exec /usr/bin/cgmanager. Or, you can start it on terminal by the command :
$ sudo cgmanager
- Cgroups is enabled on your s6.conf or rc.conf
- Iptables is enabled on your s6.conf or, if you use runit, having the iptables service running : This is optional. It's only needed if you let the script configure the network for you (see below).
- Your system is up to date.

File path location/explanation :
- /etc/obarun/build.conf : file configuration for the container e.g password used and the creation of the bridge .
- /var/lib/obarun/obarun-build/container.list : list of package installed by pacman onto the container.
- /var/lib/obarun/obarun-build/customizeCont : script used to configure the system onto the container after the fresh installation of the system with the packages define in container.list.
- /var/lib/obarun/obarun-build/pacman.conf : pacman.conf used for creating the container AND copied onto the container after the fresh installation
- /usr/lib/obarun/lxc-obarun : template used by the command lxc-create to build the container

How to configure the network :

The principal difficulty is to have a valid network onto the container.
Personnaly i don't use any "automatic program" dhcp-client, dhcpcd, network-manager or whatever to configure the network on my main system. I use iproute2 and my network is configured with static ip define in s6.local at boot time.
For example this is a part of my s6.local :
# network stuff
ip link set enp2s0 up
ip addr add 192.168.178.2/24 broadcast 192.168.1.255 dev enp2s0
ip route add default via 192.168.178.1
with these few line i have the network configured and i do not have any daemon running just for a network :). Obviously you can use dhcpd on your system if you want.

Anyway, the container can be created with a valid network automaticaly but some assumptions are made :
- All the variables concerning the network on build.conf are valid.
- You accept the fact that the script append your /etc/iptables.rules file with this e.g. :
-t nat -A POSTROUTING -o enp2s0 -j MASQUERADE
note : you can disable the auto-creation of the bridge into the file build.conf (see below)

The file /etc/obarun/build.conf need to be edited and change those variables :

create_bridge
# Allow script to create a bridge automaticaly
# 0 for no, 1 for yes
create_bridge=1
allow the script to create or not the bridge automaticaly

router_addr
# Address of the "router", meaning address of the box providing by your internet provider
router_addr="192.168.178.1" 
to find your own :
obarun@ obarunS6 ~ % ip route
default via 192.168.178.1 dev enp2s0 
192.168.178.0/24 dev enp2s0  proto kernel  scope link  src 192.168.178.2
the value after default via is your own

host_interface
# Name of the host interface to use
host_interface="enp2s0" 
nothing special here :)

host_addr
# Address of the host interface
host_addr='192.168.178.2/24' 
to fing your own
obarun@ obarunS6 ~ % ip addr | grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
    inet 192.168.178.2/24 brd 192.168.1.255 scope global enp2s0
    inet6 fe80::feaa:14ff:fe38:e0aa/64 scope link  
the value after inet is your own (read the line comporting the name of your card e.g enp2s0)

bridge_interface
# Name of the bridge
bridge_interface="lxc-nat" 
name of the bridge when is created, you don't need to change this

bridge_addr
# Address of the bridge
bridge_addr='192.168.178.3/24' 
as you can see the only difference between host_addr (192.168.178.2/24) and bridge_addr (192.168.178.3/24) is the last number before the /. So just increase your host_addr value e.g host_addr=192.168.100.3 bridge_addr=192.168.100.4

lxc_network_type, lxc_network_flags, lxc_network_link
# Variable defined on the container configuration file when it created
# Type of the connection
lxc_network_type="veth"

# Name of the bridge used
lxc_network_link="${bridge_interface}"

# Allow using it directly
lxc_network_flags="up" 
you don't need to change those variables.

lxc_network_ipv4
 # Address of the interface used onto the container
lxc_network_ipv4="192.168.178.4/24"
like made with bridge_addr, you just need to increase your bridge_addr value e.g bridge_addr=192.168.100.4 lxc_network_ipv4=192.168.100.5

lxc_network_ipv4_gateway, lxc_network_name
# Gateway used by the interface onto the container, it should the same as the router_addr
lxc_network_ipv4_gateway="${router_addr}"

# Name of the interface onto the container
lxc_network_name="eth0" 
you don't need to change those variables.

this is what the script do with this all variables :
ip link add name "${bridge_interface}" type bridge
	ip link set "${bridge_interface}" up
	ip addr add "${bridge_addr}" dev "${bridge_interface}" 
	ip link set "${host_interface}" master "${bridge_interface}" 
then append the /etc/iptables.rules files (see above).

How to create/start/destroy a container :

to create it
$ sudo lxc-create -n buildpkg -t /usr/lib/obarun/lxc-obarun
the arguments following the "-n" must be the same as defined /etc/obarun/build.conf buildpkg e.g
# Name of the container
name="buildpkg"
do not change the argument after "-t"



to start it
$ sudo lxc-start -n buildpkg


to log on it
$ sudo lxc-console -n buildpkg
note: (little bug here) you cannot connect directly with user privilegies on the login shell. you need to log with root user first.
When you are logged on it, you can works with it like a classic system :)
CTRL+a then press q to go out

to launch a command without logging on it
$ sudo lxc-attach -n buildpkg -- ping google.com


to stop it
lxc-stop -n buildpkg
or for kill it
lxc-stop -n buildpkg -k
A good practice is to shutdown the container with e.g. poweroff when you are logged on it or by the lxc-attach command before calling the lxc-stop command



to destroy it
$ sudo lxc-destroy -n buildpkg

The rootfs of the container can be found at /var/cache/obarun/pkgbuild/buildpkg/rootfs. This directory is the / of system container. You can easily transfer what you want between your host and the container e.g a PKGBUILD. This location can be modified into the file build.conf
Your /var/cache/pacman/pkg is automaticaly mounted on the container.

and
https://linuxcontainers.org/
https://github.com/lxc/lxc
https://wiki.archlinux.org/index.php/Linux_Containers
https://wiki.archlinux.org/index.php/Network_bridge

well, enjoy :)
As usual any feedback are welcome

Powered by Obarun