3 # This boot method runs a service subhost with a root filesystem that
4 # is an overlay of the subhost's root and an OS root. The service
5 # subhost is defined by a configuration file named on teh command line
7 [ $(id -u) = 0 ] || exec sudo $0 $@
8 . $(dirname $(realpath $0))/functions $*
10 [ -r "$CONFIG" ] || die "Missing configuration $CONFIG"
11 config NAME $(basename $1 .${1##*.})
12 config LOG /tmp/oly-$NAME.log
14 if [ -z "$UNSHARED" ] ; then
17 # Create the network namespace for the subhost, then trigger
18 # detached re-run with unshared mount namespace
19 [ -r /run/netns/$NAME ] || {
21 ip netns exec $NAME ip link set lo up
23 exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 &
24 echo "Logging to $LOG" >&2
29 BASE="$(cd $(dirname $CONFIG); realpath $BASE)"
31 config LIVE "$BASE/live"
32 config UPPER "$BASE/root"
33 config WORK "$BASE/work"
36 config START "networking ssh"
37 config SUBSHELL /bin/sh
39 # Setup virtual cabling and subhost's /etc/network/interfaces
40 setup_veth_cables $NAME $CABLES
42 # Set up the mount for this subhost, including a new tmpfs on its /run
43 echo setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
44 setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
52 CMD="unshare -fp --mount-proc ip netns exec $NAME chroot $LIVE /bin/sh"
57 mount -t proc proc /proc
58 for srv in $START ; do service \$srv start ; done